rails 4.1 RSPECとCapybaraでテストを行っている私には、私はテストを実行するために使用する、私はbdに格納されているいくつかのデータを生成するテストを実行している、または私が必要なものは、テストを実行した後、これらのデータはそこに格納されません。RSPECとCapybaraでテストを実行して生成されたデータのみを集めたデータ
私はgem database_cleaner(RSPECとCapybaraでテストを実行して生成されたデータのみのクリーンテストデータベース)を使用しましたが、これによってテストbdのすべてのデータがクリアされます。テスト。
私はこの構成を持っており、テストはjavascrpitテストです:
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
実行するテストごとにデータベースをクリーンな状態にしたくない理由を理解するのは難しい - – David