floehopper/mocha — Issue #54: Class method stub being lost during testing
Author: samdalton
Created: 2012-01-12 01:53:43+00:00
State: open

I have an expectation defined on a class in an RSpec before(:all) block, like so
before :all do
Item.expects(:find).returns([])
end

If I call the find method, Item.find, directly after this, I get the correct response. If I let the tests run, which are capybara-webkit integration tests, the expectation never gets triggered.

The method is definitely getting called, as various debug statements I entered have shown, but the mocha expectation always fails.

The method lives in the index action, and is being called in a before(:each) block
before :each do
@user = Factory(:user)
visit '/users/sign_in'
fill_in "user_email", :with => @user.email
fill_in "user_password", :with => @user.password
click_button 'Sign in'
visit '/admin/items'
end

I've tried setting the expectation it various points in the test, such as in :all, :each, :suite hooks, and even just before visiting the url. In each case, I can also successfully call Item.find after setting the expectation and observe the correct response.

More information will probably be required for this, so please let me know what info would help.