Ease Bus
2010-Mar-07 06:14 UTC
Mocha expectation is affecting (bleeding) from one test to another
Mocha expectation is affecting (bleeding) from one test to another: In one test, I have: Friendship.expects(:is_friend?).with(users[1], users[3]).returns(true) Then, in another test, which actually is listed before the test, I am getting this error: unexpected invocation: Friendship(id: integer, user_id: integer, friend_id: integer, status: string, requested_at: datetime, accepted_at: datetime, created_at: datetime, updated_at: datetime).is_friend?(#<User:0xb6b2bf04>, #<User:0xb6bc7648>) satisfied expectations: - expected exactly once, already invoked once: Friendship(id: integer, user_id: integer, friend_id: integer, status: string, requested_at: datetime, accepted_at: datetime, created_at: datetime, updated_at: datetime).is_friend?(#<User:0xb6eeb220>, #<User:0xb6c3a224>) What''s going on? I am not using test-unit gem, or shoulda. I removed ''require ''mocha'' from the top of the test file but the problem remains the same. Interestingly, it doesn''t happen on my Mac machine. It only happens on my staging server which is Ubuntu. I am on rails 2.3.5. Thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ritchie
2010-Mar-07 12:34 UTC
Re: Mocha expectation is affecting (bleeding) from one test to another
I realise this probably won''t help you directly because you state that you''re not using shoulda but I had a similar problem with mocha stubs bleeding from one Shoulda test to another. I found that reversing the order of the config.gem lines in environment.rb, thus: config.gem "thoughtbot-shoulda", :lib => "shoulda" #- shoulda must be loaded before mocha config.gem "mocha" #--or any_instance bleeds between tests resolved the problem. I didn''t investigate why. Also, this problem didn''t seem to occur when I ran under autotest. It only popped up when running the tests with rake. I expect because autotest runs the tests as separate processes. Good luck Ritchie -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
James Mead
2010-Mar-07 17:32 UTC
Re: Re: Mocha expectation is affecting (bleeding) from one test to another
Are you sure no expectations are being set for the failing test e.g. in a setup method? What version of Ruby are you using? What version of Mocha are you using. How and where are you requiring Mocha? Can you send the test code and the code under test to the Mocha mailing list [1] so we can try and reproduce the problem. Thanks, James. [1] http://groups.google.com/group/mocha-developer -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.