@sponge = Factory(:user)
let(:event_type) { EventType.where( name: 'visit_site').first ONE:运行测试时 => false
subject{ Event.new user: @sponge, event_type: event_type, points_earned: event_type.points_value, description: {}}
context 'call #update_user_points when create a event' do
it{should_receive(:update_user_points)}
end2:运行测试时的 => true
it 'should call update_user_points after creation' do
event = Event.new user: @sponge, event_type: event_type, points_earned:event_type.points_value, description: {}
event.should_receive(:update_user_points)
event.save
end请给我一些建议。
发布于 2012-03-14 15:01:12
第二个示例与第一个示例不一样:它们都为Event#update_user_points设置了消息期望,但第二个示例之后调用了save;第一个示例没有。
我认为您不能像在第一个示例中所做的那样,在隐式主题中使用should_receive。rspec似乎没有抱怨,但我不认为它能做你想要的事情。因此,它这样做:
update_user_points方法。它失败了,因为从未收到该消息。
https://stackoverflow.com/questions/9696597
复制相似问题