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 == ‘[email protected]’}.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 => ‘[email protected]’)
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 == ‘[email protected]’}.should be_blank
end
end