7

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?

yangtheman
  • 509
  • 4
  • 21

1 Answers1

4

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

Sam Joseph
  • 4,584
  • 4
  • 31
  • 47
  • 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 '15 at 19:41