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