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

Slightly confusing expectation behaviour when stubbing after expectation #171

Closed
lazyatom opened this issue Dec 12, 2013 · 4 comments
Closed

Comments

@lazyatom
Copy link
Contributor

It looks like calling stubs causes a previous expects to fail. Running the following (somewhat contrived) example will fail:

Object.expects(:method_one).returns(Object.new)
Object.stubs(:method_one).returns(Object.new)
Object.method_one

Here's the slightly confusing message you get:

not all expectations were satisfied
unsatisfied expectations:
- expected exactly once, not yet invoked: Object.method_one(any_parameters)
satisfied expectations:
- allowed any number of times, invoked once: Object.method_one(any_parameters)

I can imagine why this might be the case, but I wondered if it was a gotcha that was documented anywhere?

@floehopper
Copy link
Member

This aspect of Mocha was modelled on the method dispatch behaviour of jMock v1 [1]. I thought I had written it up somewhere in the documentation, but I can't find it. The best I can do is point you at this acceptance test which describes the current behaviour. It's worth noting that in some cases, it may be possible to use Mocha's states functionality to achieve what you want.

In the long term I'd like to change this aspect of Mocha's behaviour to be more like that of jMock v2 [2], but this would require a major version release and I just haven't managed to find the time to do it.

[1] http://www.jmock.org/jmock1-dispatch.html
[2] http://www.jmock.org/dispatch.html

@lazyatom
Copy link
Contributor Author

Ah, that's really interesting.

I wonder if there's a sensible place in the documentation or the README to start collecting gotchas like this?

— James

On Fri, Dec 13, 2013 at 6:14 AM, James Mead [email protected]
wrote:

This aspect of Mocha was modelled on the method dispatch behaviour of jMock v1 [1]. I thought I had written it up somewhere in the documentation, but I can't find it. The best I can do is point you at this acceptance test which describes the current behaviour. It's worth noting that in some cases, it may be possible to use Mocha's states functionality to achieve what you want.
In the long term I'd like to change this aspect of Mocha's behaviour to be more like that of jMock v2 [2], but this would require a major version release and I just haven't managed to find the time to do it.
[1] http://www.jmock.org/jmock1-dispatch.html

[2] http://www.jmock.org/dispatch.html

Reply to this email directly or view it on GitHub:
#171 (comment)

@floehopper
Copy link
Member

I've added 2 separate issues: #172 & #173 to capture my plans to deal with this issue. Closing this one.

@floehopper
Copy link
Member

@lazyatom I've added documentation for this in my fix for #172. See these two links:

I hope that helps.

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

2 participants