views:

53

answers:

1

Hi.

I am using Cucumber as the BDD framework with rspec/mocha mocking. Ideally we would not mock/stub behavior in cucumber specs; however the scenario is exceptional here. To give you the brief idea of problem here; I have two features product feature and cart feature.

Cart feature is currently mocking some of the product fetch from 3 party system. And in cucumber run cart feature runs before product feature. Product feature uses real call for some scenarios. Ideally we would expect that Class level stubs like Product.stub(:find) would be cleared once the scenarios are completed; however that is not the case. Class level stubs linger on to the next cucumber scenario run and interfere with the call.

I interchangeably used mocha and rspec to induce the stubs; but no avail; in either case the stub remains and prevents my product feature to run after cart feature. Both of them run fine in isolation.

Has anyone faced similar issue of stubs not being reset in cucumber? Is there a way, I can restore the original class behavior?

Any help will be appreciated.

Cheers

+2  A: 

For mocha integration, you should add the following to a file in your features/support folder (like mocha.rb)

require "mocha"

World(Mocha::Standalone)

Before do
  mocha_setup
end

After do
  begin
    mocha_verify
  ensure
    mocha_teardown
  end
end

The after block should release all mocks.

Source: http://gist.github.com/80554

Geoff Lanotte
awesome. Just what I needed to dump rspec mocking/stubbing and go with mocha! :)
Priyank