[rspec-devel] [ rspec-Bugs-11091 ] mock setup fails in before(:all), but succeeds in before(:each)

noreply at rubyforge.org noreply at rubyforge.org
Thu May 24 07:41:24 EDT 2007


Bugs item #11091, was opened at 2007-05-24 11:26
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=11091&group_id=797

Category: mock module
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 3
Submitted By: Jon Egil Strand (jonegil)
>Assigned to: David Chelimsky (dchelimsky)
Summary: mock setup fails in before(:all), but succeeds in before(:each)

Initial Comment:


The attached spec shows how setting up a mock fails inconsistently.

When setting it up within before(:all), it fails.
When setting it up within before(:each), it is ok.
When setting it up within before(:each), then within before(:all), both are ok.


Parsing data
- before(:all) (ERROR - 1)

Parsing data
- should include 10 persons (ERROR - 2)

Parsing data
- should include 10 persons (ERROR - 3)

1)
NoMethodError in 'Parsing data before(:all)'
undefined method `add' for nil:NilClass
./test\spec_bug.rb:5:

2)
Spec::Mocks::MockExpectationError in 'Parsing data should include 10 persons'
Mock 'gui' expected :increment with (any args) once, but received it 0 times
./test\spec_bug.rb:18:

3)
Spec::Mocks::MockExpectationError in 'Parsing data should include 10 persons'
Mock 'gui' expected :increment with (any args) once, but received it 0 times
./test\spec_bug.rb:31:

Finished in 0.06 seconds

3 examples, 3 failures

----------------------------------------------------------------------

>Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-24 11:41

Message:
This is by design. before(:all) is not executed in the same binding as the examples are. 

Using before(:all) for mocks is a mock-no-no. Doing so would bind your examples together and produce unexpected results.

What we need is better documentation about before(:each) and before(:all). I'll work on that for the next release.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=11091&group_id=797


More information about the rspec-devel mailing list