8

I know that we generally don't want to stub a method in acceptance/feature tests, but this is something I ABSOLUTELY need to stub for all of my acceptance/feature tests.

When I put the stub call in Before block in env.rb or in a Background step, I get the following error.

The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported. (RSpec::Mocks::OutsideOfExampleError)

Where should I put the stub call so that it will work in all scenarios?

1 Answer 1

5

I thought this might work:

  RSpec::Mocks.with_temporary_scope do
    allow_any_instance_of ....
  end

Documented here:

https://relishapp.com/rspec/rspec-mocks/docs/basics/scope

but actually does not work as I expect - better solution is:

require 'cucumber/rspec/doubles'

thanks to Sanjay! @sanjsanj

Documented here:

https://github.com/cucumber/cucumber/wiki/Mocking-and-Stubbing-with-Cucumber

1
  • It looks like documentation for this is falling out of date? This doesn't work for me :( BUT adding the with_temporary_scope bit did the trick!!! Thanks!
    – Ninjaxor
    Dec 16, 2015 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.