相关问题: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
最佳答案
如您所知 background
是 before
的别名用于功能测试(请参阅 this )。因此,您可以使用:
background(:all) do
# set up some records that don't change between scenarios
end
background(:each) do # or background
# set up some records that do change between scenarios
end
关于ruby-on-rails - 如何在 Rails Capybara 测试中为几个 "scenarios"运行一次安装程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19798800/