我使用 rspec+capybara 创建了几个测试。测试代码
当我用 rspec 运行它们时,它们都通过了
git:(master) ✗ rspec
Rack::File headers parameter replaces cache_control after Rack 1.5.
WARNING: there is already a transaction in progress
NOTICE: there is no transaction in progress
.WARNING: there is already a transaction in progress
NOTICE: there is no transaction in progress
.WARNING: there is already a transaction in progress
NOTICE: there is no transaction in progress
.WARNING: there is already a transaction in progress
NOTICE: there is no transaction in progress
.WARNING: there is already a transaction in progress
NOTICE: there is no transaction in progress
.WARNING: there is already a transaction in progress
NOTICE: there is no transaction in progress
.WARNING: there is already a transaction in progress
NOTICE: there is no transaction in progress
.WARNING: there is already a transaction in progress
NOTICE: there is no transaction in progress
.
Finished in 32.54 seconds
8 examples, 0 failures
但是如果我使用防护,一些往往会失败(某些测试可能会失败,并且可能不会不时)
防护输出
如何解释这种行为?以及如何解决?
更新 1
我已经在使用gem 'database_cleaner'
这个配置:
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:transaction)
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = :transaction
config.use_transactional_examples = true
更新 2
更改了几个文件https://github.com/Asmmund/notes/commit/a5e0a43d6247bb8f937fb7e9dcc8d8cfa7bfc4ea