Rspec 2 not cleaning up after examples run?

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?

On Jun 28, 2010, at 10:00 AM, Timo Rößner wrote:

 challenge.should be_featured
 Challenge.featured.should == [challenge]

Featured Challenges size: 0

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?

Bug, but please check if it’s still true of beta.14.1.

Thx

Hey David,

I just tried it out using the latest rspec and rspec-rails:

Gemfile:

gem ‘rspec’, ‘2.0.0.beta.14’
gem ‘rspec-rails’, '2.0.0.beta.14.1

$ bundle show rspec
~/.bundle/ruby/1.8/gems/rspec-2.0.0.beta.14

$bundle show rspec-rails
~/.bundle/ruby/1.8/gems/rspec-rails-2.0.0.beta.14.1

Unfortunately, the bug still exists when using this configuration:

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
FBefore Each:
Featured Challenges size: 2
Challenges count: 3

Hi David,

Gemfile and spec/spec_helper (not sure what you mean with “in-line
posting”? I hope it’s ok like that, if not, let me know):

456941’s gists · GitHub

On Jun 28, 2010, at 10:30 AM, Timo Rößner wrote:

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.

El 29/06/2010, a las 09:50, Timo Rößner
escribió:

Hi David,

Gemfile and spec/spec_helper (not sure what you mean with “in-line
posting”? I hope it’s ok like that, if not, let me know):

He means, don’t top-post.

http://idallen.com/topposting.html

Cheers,
Wincent

On Jun 29, 2010, at 2:50 AM, Timo Rößner wrote:

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.

Hi David,

456941’s gists · GitHub

I forked and made a couple of changes: gist:457034 · GitHub

  • Added :development to the group declaration on line 31
  • Changed rspec-rails to beta.14.2
  • Removed the rspec declaration (it’s a dependency of rspec-rails, so
    unnecessary)
  • Changed what is now line 44 to what gets generated now

Not sure if this will fix anything, but let’s see.

On Jun 29, 12:14 pm, David C. [email protected] wrote:

.Before Each:
Featured Challenges size: 0

Gemfile:
Unfortunately, the bug still exists when using this configuration:
FBefore Each:
I forked and made a couple of changes:gist:457034 · GitHub

  • Added :development to the group declaration on line 31
  • Changed rspec-rails to beta.14.2
  • Removed the rspec declaration (it’s a dependency of rspec-rails, so unnecessary)
  • Changed what is now line 44 to what gets generated now

Not sure if this will fix anything, but let’s see.


rspec-users mailing list
[email protected]://rubyforge.org/mailman/listinfo/rspec-users

Hey,

@Wincent alright, thanks.

@David

I changed my Gemfile and my spec_helper as you suggested (right now
they are exactly the same as in your gist) and ran “bundle install”.

Unfortunately this setup seems to cause another problem:

( $ ) bundle exec spec spec/models/challenge_spec.rb
/usr/lib/ruby/gems/1.8/gems/bundler-0.9.26/lib/bundler/
shared_helpers.rb:153:in `bin_path’: can’t find executable spec
(Gem::Exception)
from ~/.bundle/ruby/1.8/bin/spec:19

( $ ) bundle show rspec
~.bundle/ruby/1.8/gems/rspec-2.0.0.beta.15

On Jun 30, 2010, at 11:55 AM, Timo Rößner wrote:

Hey guys,
describe ‘featuring’ do
end
end
A spec run using rails 2.3.5 and rspec 1:
Challenges count: 0
Before Each:
Challenges count: 3

Challenges count: 2

[email protected]://rubyforge.org/mailman/listinfo/rspec-users
Unfortunately this setup seems to cause another problem:

( $ ) bundle exec spec spec/models/challenge_spec.rb
/usr/lib/ruby/gems/1.8/gems/bundler-0.9.26/lib/bundler/
shared_helpers.rb:153:in `bin_path’: can’t find executable spec
(Gem::Exception)
from ~/.bundle/ruby/1.8/bin/spec:19

( $ ) bundle show rspec
~.bundle/ruby/1.8/gems/rspec-2.0.0.beta.15

The command is rspec in rspec 2. Try:

bundle exec rspec spec/models/challenge_spec.rb

Cheers,
David

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

Amir

On Jun 30, 2010 10:56 PM, “David C.” [email protected]
wrote:

On Jun 30, 2010, at 11:55 AM, Timo Rößner wrote:

On Jun 29, 12:14 pm, David C. <dchelim…
The command is rspec in rspec 2. Try:

bundle exec rspec spec/models/challenge_spec.rb

Cheers,
David

@David,

alright, I tried:

bundle exec rspec spec/models/challenge_spec.rb

-> Same results, same log output as above.

@Amiruddin

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).

On Jul 1, 2010, at 3:22 AM, Timo Rößner wrote:

-> Same results, same log output as above.

@Amiruddin

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 :slight_smile: 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.

Cheers,
David

Hey David,

sorry for the late reply, you nailed it, that was the problem
indeed…:slight_smile:

Thanks a lot for the assist.

Cheers