Alex Kovshovik
Alex Kovshovik

Reputation: 4215

What is the scope of the mocks created by mocha when used in rspec?

In my rspec test suite I use mocha library to create mocks/stubs and test doubles. Examples in my rspec suite run in random order, as recommended. For some reason a few examples now fail randomly. I already ruled out shared database state and global variables (I confess: there are global variables in my Rails app).

Another logical suspect (maybe) is the mocking library. According to rspec documentation here rspec would clean out all mocks after each example, even those created in before(:all). This should work with any mocking library, right? Maybe...

For historic reasons my test suite doesn't use built-in rspec mocks, we use mocha library.

Question: would rspec clean out all mocks/stubs created by mocha after each example?

Upvotes: 0

Views: 156

Answers (1)

sjaime
sjaime

Reputation: 1500

One possible point of failure is not telling Rspec that you want to use mocha for mocks:

# Where you do your Rspec config stuff
RSpec.configure do |config|
  config.mock_framework = :mocha
end

AFAIK, for the cleaning up you mention to happen, you need to do that.

Source

Upvotes: 0

Related Questions