【发布时间】:2013-12-25 06:37:17
【问题描述】:
我们是否需要像after_destroy一样在ActiveRecord中测试回调?
【问题讨论】:
标签: ruby-on-rails unit-testing tdd
我们是否需要像after_destroy一样在ActiveRecord中测试回调?
【问题讨论】:
标签: ruby-on-rails unit-testing tdd
鉴于这样的事情:
after_destroy :clean_up_some_stuff
我认为您不需要测试 after_destroy 是否有效,但您确实需要全面测试 clean_up_some_stuff 方法是否正常工作。
【讨论】:
你可以在这里测试两件事。
你的方法在销毁clean_up_some_stuff之后调用的目的是什么
test "should do the clean up stuff" do
assert Model.new.clean_up_some_stuff
# more asserts to verify the job is done
end
销毁对象并验证回调是否成功
test "should destroy" do
object = Model.create
assert object.destroy
# more asserts to verify the job is done
end
assertions-cheat-sheet 应该会有所帮助。
【讨论】: