Test Database not refreshing after running initial tests
I am going thru Railstutorial.org and having this issue:
Test Database seem to not be emptying after running tests.
In section 6.10 I create the line below in the user_spec.rb file and it passes the first time then fails every time afterwards.
it "should create a new instance given valid attributes" do
User.create!(@attr)
end
When i look at the test.sqlite3 database it shows 1 user in the database. If I remove the user the test passes once, then fails again saying it cannot create the user because email is not unique. I look in the Database and there the record is again.
It seems like that code above creates it, but it doesnt ever get destroyed.
Here is my GemFile
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', '1.3.2', :require => 'sqlite3'
gem 'gravatar_image_tag', '0.1.0'
group :development do
gem 'rspec-rails', '2.3.0'
gem 'annotate-models', '1.0.4'
end
group :test do
gem 'rspec', '2.3.0'
gem 'w开发者_开发问答ebrat', '0.7.1'
gem 'spork', '0.8.4'
end
Check in ./spec/spec_helper.rb
and make sure the following line is there:
config.use_transactional_fixtures = true
Have a look at the database_cleaner gem and see if that solves your problem.
精彩评论