【发布时间】:2011-09-12 18:27:06
【问题描述】:
我有以下 mocha mock,效果很好。
在 test.rb 文件中:
setup do
Date.stubs(:today).returns(Date.new(2011, 7, 19))
Time.stubs(:now).returns(Time.new(2011,1,1,9,0))
end
问题是测试的时间被打破了。测试运行后,日期和时间对象仍然被模拟。(!)
Finished in -21949774.01594216 seconds.
我添加了以下内容:
teardown do
Date.unstubs(:today)
Time.unstubs(:now)
end
这会为每个测试引发以下错误:WARNING: there is already a transaction in progress
这是取消存根的正确方法吗?在测试文件的末尾甚至在单元测试套件的末尾取消存根更好吗?
在 Rails 3.07 和 Mocha 0.9.12 中工作
谢谢。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 tdd mocking mocha.js