我有几个包含参数和其他东西的表,它永远不会改变!
但是我不能告诉 database_cleaner 保留这些数据,每次测试后它都会截断我的所有数据库。
宝石
gem "cucumber-rails", "~> 1.3.0", require: false
gem 'factory_girl_rails'
gem 'database_cleaner'
配置/黄瓜.yml
enter code here
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
功能/支持/环境
require 'cucumber/rails'
require 'database_cleaner'
require 'database_cleaner/cucumber'
require 'factory_girl_rails'
Capybara.default_selector = :css
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner.logger = Rails.logger
DatabaseCleaner.clean_with(:truncation, :except => %w[regions departements villes positions levels footballtypes genders publicies types])
DatabaseCleaner.strategy = :truncation, {:except => %w[regions departements villes positions levels footballtypes genders publicies types]}
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
Cucumber::Rails::World.use_transactional_fixtures = false
Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
DatabaseCleaner.clean_with(:truncation, :except => %w[regions departements villes positions levels footballtypes genders publicies types])
DatabaseCleaner.strategy = :truncation, {:except => %w[regions departements villes positions levels footballtypes genders publicies types]}
end
Before do
DatabaseCleaner.strategy = :truncation, {:except => %w[regions departements villes positions levels footballtypes genders publicies types]}
DatabaseCleaner.clean_with(:truncation, :except => %w[regions departements villes positions levels footballtypes genders publicies types])
DatabaseCleaner.start
end
After do |scenario|
DatabaseCleaner.clean_with(:truncation, :except => %w[regions departements villes positions levels footballtypes genders publicies types])
DatabaseCleaner.strategy = :truncation, {:except => %w[regions departements villes positions levels footballtypes genders publicies types]}
DatabaseCleaner.clean
end
你有一些线索吗?谢谢,尼尔森