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?
attention to the specs themselves, I just want to give you a "real
puts “Challenges count: #{Challenge.count}”
end
Challenge.featured.should be_empty
Challenges count: 0
Challenges count: 1
Challenges count: 0
.Before Each:
Featured Challenges size: 1
Challenges count: 1
.Before Each:
Featured Challenges size: 1
Challenges count: 2
FBefore Each:
Featured Challenges size: 2
Challenges count: 3
What’s in your Gemfile and spec/spec_helper.rb?
ps - please post in-line or at the bottom so we can follow the thread.
attention to the specs themselves, I just want to give you a "real
puts “Challenges count: #{Challenge.count}”
end
Challenge.featured.should be_empty
Challenges count: 0
Challenges count: 1
Challenges count: 0
What’s in your Gemfile and spec/spec_helper.rb?
ps - please post in-line or at the bottom so we can follow the thread.
I am not sure if this will help or not but I was also getting data not
cleared properly when run specs through rake but when ran using
script/spec
it was cleaning up the data
script/spec would be rails 2 / rspec 1 - my problem occurs with rails
3 / rspec 2 (and script/spec doesn’t exist because of that).
Hard to break the top posting habit I moved your comments to the
bottom.
@Timo - I’m sorry I missed this the first time through, but it’s because
the spec_helper config is missing this line:
config.use_transactional_fixtures = true
The post-install hook when you install rspec-rails instructs you to
re-run ‘script/rails generate rspec:install’, and if you do so you’ll
see this line in the generated spec_helper.
Let me know if that solves it. I’m pretty sure it will.