0
@sponge = Factory(:user)
let(:event_type) { EventType.where(name: 'visit_site').first
ONE: =>假,當運行測試rspec,2種方式是一樣的嗎?
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
二: =>真當運行測試
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
給我一些建議,請:d
我明白rspec中的一個小例子,爲什麼我們必須在「event.save」之前放置「should_receive」。我認爲它在創建事件後運行update_user_points,它應該在那之後放置?而我雖然第一種方式必須運行良好? 你能帶我學些關於RSpec的東西給初學者嗎? 謝謝:D – 2012-03-15 01:47:54