레일 4.1에 RSPEC 및 Capybara로 테스트를 수행하는 애플리케이션이 있습니다. 데이터가있는 테스트 데이터베이스가 있습니다. 나는 테스트를 수행하는 데 사용하고, 나는 bd에 저장된 일부 데이터를 생성하는 테스트를 실행하고 있거나 필요한 것은 테스트를 실행 한 후 이들 데이터가 저장되어 있지 않다는 것이다.RSPEC 및 Capybara를 사용하여 테스트를 실행하여 생성 된 데이터의 깨끗한 테스트 데이터베이스
필자는 보석 DB_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