@sponge = Factory(:user)
let(:event_type) { EventType.where( name: 'visit_site').first
ONE: => false when run test
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)}
end
TWO: => true when run test
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
Give me some advises please :D
Your second example is not the same as your first: they both set up a message expectation for Event#update_user_points
, but the second calls save
after that; the first doesn't.
I don't think you can use should_receive
with an implicit subject, as you try to do in the first example. rspec doesn't seem to complain, but I don't think it does what you're wanting it to. In order, it does this:
update_user_points
method.It fails because the message was never received.