问题
I am using Rspec for testing a rails application. I have 2 tables I imported data into (both the test and development database)
The entire application is dependent on the tables data, meaning the entire functionality is matching, calculating and measuring data from this table and putting it into other tables.
so, when testing, there's no point in deleting these table's data but Rspec is still deleting the data from them.
my question is: how can I force Rspec not to delete data from these tables (never, ever)?
my spec helper file
require 'rubygems'
require 'spork'
Spork.prefork do
end
Spork.each_run do
end
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
end
回答1:
The solution is in the spec_helper.rb file I should change this
config.use_transactional_fixtures = true
to this
config.use_transactional_fixtures = false
In the tests where I do need the database to be cleaned, I clean it manually with delete_all or with database_cleaner (whatever convenient for you)
That solved my problem and made the database persistent through the testing.
来源:https://stackoverflow.com/questions/5289956/rspec-dont-delete-2-specific-tables