4

Related to question: how to run capybara commands once, then run some tests

How do I set up a Capybara test to run part of the background just once and have the database records there for the scenarios in the test.

Note, I'm using database_cleaner between tests. Yes, I have some seed_tables, but I'd like to have a scope that is not global but just one file of integration tests.

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

Here's my setup for 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
4

1 回答 1

4

如您所知,它是功能测试background的别名(请参阅this)。因此,您可以使用:before

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
于 2013-11-05T21:13:19.397 回答