rspec-core: doubles and around hook failure

Hi,

The following raises Failure/Error: double('test').as_null_object The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported.

context "test" do
  around(:each) do |example|
    double('test').as_null_object
    example.run
  end

  it "foo" do
  end
end

Works with a before hook though.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

OK, then you can define an extra rspec-mock scope for your around hook:

around do |example|
  RSpec::Mocks.with_temporary_scope do
    Container.stub(:foo, double('bar'), &example)
  end
end

Or use something besides double as replacement for the foo here.