[rspec-users] Database clearing

David Chelimsky dchelimsky at gmail.com
Fri Sep 19 09:26:13 EDT 2008


On Fri, Sep 19, 2008 at 8:22 AM, Todd Tyree <todd at snappl.co.uk> wrote:
> I'm seeing something strange and was just wondering if someone can confirm
> my assumptions for me:
>
> I have  user model with a number of specs: some of them use fixtures and
> some of them don't.  Today, while talking someone through some specs that
> needed developming, I noticed that the fixtures always seemed to be
> loading.  When I investigated, I discovered that it was not the fixtures
> always loading, but the db not clearing between runs.  So, given a very
> simple spec (with the standard fixtures):
>
> # -*- coding: mule-utf-8 -*-
> require File.dirname(__FILE__) + '/../spec_helper'
>
> describe User do
>   fixtures :users
>
>   it "should have some users" do
>      User.all.should_not be_blank
>   end
> end
>
> describe User, "description" do
>   it "should not show emails" do
>      User.all.should be_blank
>      # Or, to be a bit more concise:
>     User.all.select{|u| u.email == 'bob at example.com'}.should be_blank
>   end
> end
>
>
> The second describe is failing because the db is populated with the users
> from fixtures (still).  I am correct in assuming, with transactions fixtures
> switched to true (as it is), this should not be the case, right?
>
> Reenforcing my feeling that this is wrong is the fact that if I include a
> before(:each) do block in the first set of statements that creates a
> non-fixture user, this user does get removed from the db before the second
> describe runs:
>
> describe User do
>   fixtures :users
>
>   before(:each) do
>     user = User.new(:email => 'bob at example.com')
>     user.save(false)
>   end
>
>   it "should have some users" do
>      User.all.should_not be_blank
>   end
> end
>
> # This passes
> describe User, "description" do
>   it "should description" do
>     User.all.select{|u| u.email == 'bob at example.com'}.should be_blank
>   end
> end

Does your spec_helper file have this:

Spec::Runner.configure do |config|
  config.use_transactional_fixtures = true
end

Also, what versions of rspec and rails are you using?


More information about the rspec-users mailing list