Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock callbacks #200

Open
elazar opened this issue Sep 30, 2015 · 1 comment
Open

Mock callbacks #200

elazar opened this issue Sep 30, 2015 · 1 comment

Comments

@elazar
Copy link
Contributor

elazar commented Sep 30, 2015

I may be unique in this notion, but I sometimes find myself needing mock callbacks. I generally use these in tests in place of actual callbacks I'd pass to methods. I do two things with these:

  1. Have code under test invoke them, where I may provide a function body that performs assertions against the callback parameters.
  2. Assert that they were invoked, so I know that any desired interaction and/or parameter assertions actually happened.

The latter is the main annoying point, as I've tended to have to keep a separate flag that the function body modifies to indicate that it's been called.

Interoperability with Phake's API to verify calls (e.g. any, none, a specific quantity, etc.) and perform parameter assertions against callbacks, as we're currently able to do with mock object methods, would be a lot nicer than code I've tended to write to accomplish the same thing.

@mlively
Copy link
Collaborator

mlively commented Sep 30, 2015

This was actually very much on my radar as something I wanted to do. I will
get it ready for the next release.

On Wed, Sep 30, 2015 at 12:14 PM, Matthew Turland notifications@github.com
wrote:

I may be unique in this notion, but I sometimes find myself needing mock
callbacks. I generally use these in tests in place of actual callbacks I'd
pass to methods. I do two things with these:

  1. Have code under test invoke them, where I may provide a function
    body that performs assertions against the callback parameters.
  2. Assert that they were invoked, so I know that any desired
    interaction and/or parameter assertions actually happened.

The latter is the main annoying point, as I've tended to have to keep a
separate flag that the function body modifies to indicate that it's been
called.

Interoperability with Phake's API to verify calls (e.g. any, none, a
specific quantity, etc.) and perform parameter assertions would be a lot
nicer than code I've tended to write to accomplish the same thing.


Reply to this email directly or view it on GitHub
#200.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants