Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mock fails in before(:all) #255

Closed
lsegal opened this issue Dec 17, 2010 · 1 comment
Closed

mock fails in before(:all) #255

lsegal opened this issue Dec 17, 2010 · 1 comment

Comments

@lsegal
Copy link

lsegal commented Dec 17, 2010

The following fails in rspec-2.3.0:

describe do
  before(:all) do
    @mock = mock(:foo)
    @mock.stub!(:foo).and_return(1)
  end

  it "should work" do
    @mock.foo.should == 1
  end
end

with:

undefined method `mock' for #<RSpec::Core::ExampleGroup::Nested_1:0x00000101c7ed48>

Changing the before(:all) to before(:each) is a potential workaround. Is this intentional?

@dchelimsky
Copy link
Contributor

Yes, this is intentional. Mocks are cleared out after every example, so setting them in before(:all) would mean that the 2nd example that runs can not access that mock any longer.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants