【发布时间】:2013-11-05 20:55:46
【问题描述】:
相关问题:how to run capybara commands once, then run some tests
如何设置 Capybara 测试以仅在部分后台运行一次,并在其中保存测试场景的数据库记录。
注意,我在测试之间使用了 database_cleaner。是的,我有一些 seed_tables,但我想要一个不是全局的范围,而只是一个集成测试文件。
feature "some feature" do
background do
# set up some records that don't change between scenarios
# set up some records that do change between scenarios
end
scenario "scenario 1" do
# run tests
end
scenario "scenario 2" do
# run tests
end
end
这是我对 database_cleaner.rb 的设置:
RSpec.configure do |config|
config.add_setting(:seed_tables)
config.seed_tables = %w(global_options shoot_types)
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation, except: config.seed_tables)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation, {except: config.seed_tables}
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
【问题讨论】:
标签: ruby-on-rails rspec capybara rspec2 poltergeist