하나의 특정 테스트 중에 피하고 싶지 않은 모델에 메소드 (send_to)가 있습니다. 하지만 항상 처형당했습니다.rspec 스텁 이미 imp에서 메소드
이 작업을 수행하고 있습니다.
subject { create(:batch_with_jobs) } #Batch hasMany Jobs
...
it 'raise if all jobs are not in right state' do
Job.stub(:sent_to){true} #first attempt, doesnt work
Job.any_instance.stub(:sent_to).and_return(true) #second attempt, doesnt work
subject.jobs.first.update_attribute :state, :error_submitting
expect{subject.commit}.to raise_error
end
커밋 메소드는 원래의 send_to 메소드를 계속 실행합니다.
편집 : 예, 문제는 내가 작성한 내용이므로 SEND_TO이며 SEND_TO입니다.
귀하의 질문에이 메서드는'send_to'라고하지만, 코드는'sent_to'를 스텁합니다. 그것이 문제일까요? – fivedigit
그와 같은 구문에는 아무런 문제가 없습니다. 개인적으로 컨텍스트를 추가하고 블록 전후에 스텁/언 스텁을 수행합니다. JOb 관련 코드를 보지 않고 말하기 힘든 것 외 –