我在模型上有一个方法(send_to),我想避免在一个特定的测试中调用它。但它总是被执行。
我这样做。
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
commit方法继续执行原始的send_to方法。
编辑:是的,问题是因为我正在寻找SENT_TO而且它应该是SEND_TO。
答案 0 :(得分:1)
对您的代码发表两条评论。
sent_to
,但声称该方法名为send_to
。