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

creating a double in before :all #202

Closed
capoferro opened this issue Oct 26, 2010 · 12 comments
Closed

creating a double in before :all #202

capoferro opened this issue Oct 26, 2010 · 12 comments

Comments

@capoferro
Copy link

Creating a double in a before :all block triggers this error:

undefined method `double' for #RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x00000001996b90

If I remove the :all, (or change to :each), the block evaluates without incident.

Rspec 2.0.1, Rails 3.

@rsutphin
Copy link

rsutphin commented Nov 4, 2010

I noticed this too in a non-rails project.

@dchelimsky
Copy link
Contributor

Test doubles, mocks, stubs all get rolled back after each example, so before(:all) would not work even if it were made available.

I'll leave this open while I figure out where/how to best document this fact.

@agmcleod
Copy link

I have this problem as well. https://github.com/agmcleod/Copy-Process/blob/experimental/spec/copyprocess/processor_spec.rb

Line 226. However, if i take out the i method call, following it, it works fine. line 230 is for the original poster's workaround.

@agmcleod
Copy link

Sorry, that's the it method call. Comment that out and the block passing to it, tests pass, no failures.

@dchelimsky
Copy link
Contributor

@h3h
Copy link

h3h commented Jun 14, 2011

It would be nice if RSpec could raise a developer-friendly error message instead of just NoMethodError.

@dchelimsky
Copy link
Contributor

@h3h - my only concern w/ doing that is that ppl who use non-rspec frameworks would not get the same friendly messages. Seems like we'd be opening a can o' worms.

@capoferro
Copy link
Author

I don't know enough to say whether it'd be a can of worms to add this, but I agree that an error such as "You cannot create a double in a before :all block" error would be much more helpful, as if you expect a double to work and get no method, you're more likely to think that you've spelled something wrong or missed a require than that you're just not able to make a double in that context.

@felixyz
Copy link

felixyz commented May 7, 2013

+1 There should be a better error message.

@victormartins
Copy link

I just hit this problem...
+1 There should be a better error message.

@myronmarston
Copy link
Member

This has been resolved in RSpec 3 -- if you upgrade you'll get it.

@victormartins
Copy link

Ah, thanks 👍

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

8 participants