Is there any way you can extract a couple of tests that exhibit this problem so I can reproduce it locally?
Can you try running the specs with the Mocha debug option switched on?
MOCHA_OPTIONS=debug rake
This should output some debug statements as Mocha is loaded before the specs are run. Can you post the output here?
Is the problem always an unexpected invocation?
Thanks, James.
> --
> You received this message because you are subscribed to the Google Groups "mocha-developer" group.
> To post to this group, send email to mocha-d...@googlegroups.com.
> To unsubscribe from this group, send email to mocha-develop...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mocha-developer?hl=en.
>
Thanks, James.
On 10 Feb 2012, at 09:30, Noppanit wrote:
I upgraded Mocha to 0.10.4 already and I'm using ruby 1.8.7, RSpec
2.8.0. And the problem still persists.
I export MOCHA_OPTIONS=debug
already but it's not showing anything on the screen, just the error
unexpected invocation.
I put
gem 'mocha', :require => false into my Gemfile already
and I also put require 'mocha' at the end of my spec_helper.rb
> But if I put these two statements at after(:each) method it runs fine.
>
> Mocha::Mockery.instance.teardown
> Mocha::Mockery.reset_instance
This confirms that the problem is that Mocha's teardown code is not being called by Rspec. But I wouldn't want you to have to keep that in your after(:each).
Can you confirm that you have configured Rspec to use Mocha?
RSpec.configure do |config|
config.mock_framework = :mocha
end
Also can you tell us what else is in your bundle? Perhaps some other library is interfering…?
Cheers, James.
I hadn't seen James' message (above) about configuring RSpec, so if
that solved it for you, great, but if not ...
This is a complete longshot (since I can't reproduce the issue
myself), but rspec aliases mocha's setup, verify, and teardown methods
using alias (not alias_method) instead of delegating to them. The
`alias` method creates a new pointer to the same method body, so if
the aliased method is replaced by a new implementation (perhaps
because a file is reloaded), the alias is still pointing to the old
one.
1.9.3-p0 :001 > def foo; "foo"; end
=> nil
1.9.3-p0 :002 > alias bar foo
=> nil
1.9.3-p0 :003 > bar
=> "foo"
1.9.3-p0 :004 > def foo; "FOO"; end
=> nil
1.9.3-p0 :005 > foo
=> "FOO"
1.9.3-p0 :006 > bar
=> "foo"
I just posted a commit to a mocha-integration-issue branch in
rspec-core that defines methods that delegate to mocha instead of
aliasing mocha's methods. Please point your Gemfile at rspec-core on
github like this:
gem "rspec-core", :git => "git://github.com/rspec/rspec-core/",
:branch => "mocha-integration-issue"
If that solves the problem I'll merge this into master and release it
in the 2.9 release.
Cheers,
David
The convention is to put that in 'spec/spec_helper.rb', and then
require that file from every spec file.
> To post to this group, send email to mocha-developer@googlegroups.com.
> To unsubscribe from this group, send email to mocha-developer+unsubscribe@googlegroups.com.