この質問に関連:カスタム トランザクションは、rspec の database_cleaner では機能しません
requires_new で TX を開始したくない場所はありますか? (ネストされたTXを行います)
ModelObject.transaction(requires_new: true)
もしそうなら、これがデフォルトだったはずです。
ところで、これが、デフォルトのトランザクション戦略を使用している場合、コードの通常の実行パスが成功したときに、ロールバックを伴う rspec テストが失敗する理由です。
これが私の DatabaseCleaner セットアップです。Rails 4 の実行。
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