开发者

mocking in Ruby: mocks are sticking around between tests

开发者 https://www.devze.com 2023-01-21 01:17 出处:网络
I\'m using RR as the mocking framework for a personal project of mine.I\'ve been using it to mock the new method for some classes and when I run the tests they pass fine, but when I run ALL of the tes

I'm using RR as the mocking framework for a personal project of mine. I've been using it to mock the new method for some classes and when I run the tests they pass fine, but when I run ALL of the tests I run into a problem where it seems like the "new" methods are still returning the fake results, even when in a different test file. Is there a way to turn off th开发者_C百科e stubbing of the new method manually? What am I missing here?

Thanks for the help, Alex

I've tried putting this code into my app and it breaks the app, and.... doesn't fix the above problem.

RSpec.configure do |config|
  config.mock_with :rr
end


Mocks are replacing your old methods. Once a method is replaced by your mock it will never be normal again unless you using precautions.

Take a look at this thread. I explained there how one can undo Mocha mocks using simple alias.


RSpec's mocks are torn down automatically between tests. However, when you configure RSpec to mock with another library, you still have to use it through the RSpec mocking API.

0

精彩评论

暂无评论...
验证码 换一张
取 消