rspec 中的事务装置会阻止调用 after_commit,但即使我使用以下命令禁用它们
RSpec.configure do |config|
config.use_transactional_fixtures = false
end
The after_commit callback
不运行。
这是一个带有最新 rspec/rails 的 Rails 应用程序,我已经在其中生成了问题:git://github.com/sheabarton/after_commit_demo.git https://github.com/sheabarton/after_commit_demo
解决这个问题的一种方法是触发commit
手动回调。例子:
describe SomeModel do
subject { ... }
context 'after_commit' do
after { subject.run_callbacks(:commit) }
it 'does something' do
subject.should_receive(:some_message)
end
end
end
有点晚了,但希望这对其他人有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)