ruby on rails - rspec stub a method in an already imp -
i have method (send_to) on model want avoid called during 1 specific test. got executed.
im doing this.
subject { create(:batch_with_jobs) } #batch hasmany jobs ... 'raise if jobs not in right state' 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 the commit method continue executing original send_to method.
edit: yes, issue because stubing sent_to , should send_to.
two comments on code.
- as @fivedigit says, stub
sent_to, claim method namedsend_to. - your spec description difficult read, maybe thing "raises error when no jobs have right state" or "raises error when jobs have wrong state".
Comments
Post a Comment