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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With