如何测试以下示例?
- class Post < ActiveRecord::Base
- belongs_to :discussion,touch: true
- end
解决方法
你可以设置一个
message expectation:
- it "should touch the discussion" do
- post = Factory.build(:post)
- post.discussion.should_receive(:touch)
- post.save!
- end
此示例使用Factory Girl,但您也可以使用灯具或模拟器.