I have an application in rails 4.1 to which I am doing the test with RSPEC and Capybara, for her I have a test database with data that I use to perform the tests, I am running a test that generates some data that are stored in the bd, or what I need is that after running the tests these data are not stored in it.
I have used the gem database_cleaner (clean test database, only of the data generated running tests with RSPEC and Capybara), but this clears all the data of the test bd and I only want to erase the data that are generated by the tests.
I have this configuration, and the test is a javascrpit test:
config.use_transactional_fixtures = false
config.before(:suite) do
if config.use_transactional_fixtures?
raise(<<-MSG)
Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
(or set it to false) to prevent uncommitted transactions being used in
JavaScript-dependent specs.
During testing, the app-under-test that the browser driver connects to
uses a different database connection to the database connection used by
the spec. The app's database connection would not be able to access
uncommitted transaction data setup over the spec's database connection.
MSG
end
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, type: :feature) do
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
if !driver_shares_db_connection_with_specs
DatabaseCleaner.strategy = :truncation
end
end