ruby-on-rails - 如何在 Rails Capybara 测试中为几个 "scenarios"运行一次安装程序

标签 ruby-on-rails rspec capybara rspec2 poltergeist

相关问题: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

最佳答案

如您所知 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

关于ruby-on-rails - 如何在 Rails Capybara 测试中为几个 "scenarios"运行一次安装程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19798800/

相关文章:

ruby-on-rails - Capybara + Selenium-webdriver + RSpec 文件装置 + SSR 提供​​ Net::ReadTimeout

ruby-on-rails-3 - rails 3.1, 安装 capybara-webkit, 无法构建 gem native 扩展,怎么办?

ruby-on-rails - 忽略 gem,因为它的扩展未构建

ruby-on-rails - 将 json 响应与哈希数组进行比较

ruby-on-rails - rspec 的并行测试执行无限期挂起

rspec - rspec Hook 中当前示例/组的名称

ruby - 如何使用 Sinatra 配置 RSpec 以在我的测试套件运行之前动态确定哪个 Sinatra 应用程序正在运行?

javascript - 将 API key 存储到 credentials.yml.enc 的正确方法?

ruby-on-rails - ActiveRecord 范围 "default"结果

ruby-on-rails - Rails 中的 protected 和私有(private)方法