Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber/Capybara - The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported

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?

like image 639
yangtheman Avatar asked Feb 12 '15 19:02

yangtheman


1 Answers

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

like image 100
Sam Joseph Avatar answered Oct 04 '22 03:10

Sam Joseph