mock 개체에 should_receive expectations를 설정할 수있는 방법이 있지만 조금 이상하게 보입니다. 나에게더 읽기 쉽고 이해하기 쉬운 방법으로 게시물 앞에 should_receive expect를 정의하십시오.
def mock_fax_event(stubs={})
@mock_fax_event ||= mock_model(FaxEvent, stubs)
end
it "should notify facility/admin of failed faxes" do
FaxEvent.should_receive(:find_by_fax_id).with(@fax_event.fax_id).and_return(mock_fax_event(:notify_failure => true))
mock_fax_event.should_receive(:notify_failure)
post :create, :TransactionID => @fax_event.fax_id
end
, 나는 다음과 같은 일을하고 싶지만, 그것은 작동하지 않습니다
it "should notify facility/admin of failed faxes" do
post :create, :TransactionID => @fax_event.fax_id
assigns(:fax_event).should_receive(:notify_failure)
end
을 나는 위가 작동하지 않는 이유를 이해 생각하지만, 나는 생각 내가 지금하고있는 방식이 불분명하다. find_by_fax_id 부분이 아니라 notify_failure가 실제로 호출되었는지 테스트하고 싶습니다.
내가하려는 일을하는 더 좋은 방법이 있습니까?
감사합니다. 저는 Mocha를 확인합니다. 나는 테스팅 프레임 워크에 압도 당하고있다. TransactionID까지는 컨트롤러가 제어 할 수없는 외부 서비스를 통해 컨트롤러에 게시됩니다. 따라서 그것에 대해 할 수있는 일이 많지 않습니다 :) 답변을 수여하기 전에 다른 사람이 말할만한 내용이 있는지 주위를 기다릴 것입니다. 귀하의 의견. –