【问题标题】:How to run setup once for several "scenarios" in Rails Capybara test如何在 Rails Capybara 测试中为多个“场景”运行一次设置
【发布时间】: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


    【解决方案1】:

    您可能知道backgroundbefore 的别名,用于功能测试(请参阅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
    

    【讨论】:

      猜你喜欢
      • 2012-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多