[rspec-users] rspec 2 not cleaning up after examples run?

Timo Rößner dark.red.and.yellow at googlemail.com
Mon Jun 28 11:00:01 EDT 2010


Hey guys,

I let the code speak for itself:

Below are my currently failing specs, please don't pay too much
attention to the specs themselves, I just want to give you a "real
life example" of what's happening - the only interesting thing about
the specs is that there is a call to Factory(:challenge) in each of
them and a before-each-call putting out what's currently in the
database:

  describe 'featuring' do

    before(:each) do
      puts "Before Each:"
      puts "Featured Challenges size: #{Challenge.featured.size}"
      puts "Challenges count: #{Challenge.count}"
    end

    it 'should tell if a challenge is featured' do
      challenge = Factory(:challenge, :feature_position => 1)
      challenge.should be_featured
    end

    it 'should tell if a challenge is not featured' do
      challenge = Factory(:challenge, :feature_position => 0)
      challenge.should_not be_featured
    end

    it 'should feature a challenge' do
      challenge = Factory(:challenge)
      challenge.feature!
      Challenge.featured.should == [challenge]
    end

    it 'should unfeature a challenge' do
      challenge = Factory(:challenge, :feature_position => 1)
      challenge.unfeature!
      Challenge.featured.should be_empty
    end
  end

Now to the interesting part:

A spec run using rails 2.3.5 and rspec 1:

bundle exec spec spec/models/challenge_spec.rb
Before Each:
Featured Challenges size: 0
Challenges count: 0
.Before Each:
Featured Challenges size: 0
Challenges count: 0
.Before Each:
Featured Challenges size: 0
Challenges count: 0
.Before Each:
Featured Challenges size: 0
Challenges count: 0
..............................

-> Looks good.

Here's the exact same spec run with rspec-2.0.0.beta.13 and
rails-3.0.0.beta4:

Before Each:
Featured Challenges size: 0
Challenges count: 0
Before Each:
Featured Challenges size: 1
Challenges count: 1
.Before Each:
Featured Challenges size: 1
Challenges count: 2
Before Each:
Featured Challenges size: 2
Challenges count: 3

So apparently the latest rspec doesn't clean up after examples at all?

Is this a bug or a feature?


More information about the rspec-users mailing list