ruby on rails - how to correctly use stub for testing in rspec -
so, have method in class follow:
def installation_backlog api::dashboards::installationsbacklog.new(operational_district_id, officer_id).backlog_tasks end
and want spec it. so, wrote rspec test test follow:
it "should call new instance of installationsbacklog backlog_tasks method" expect_any_instance_of(api::dashboards::installationsbacklog).to receive(:backlog_tasks) @installation_officer.installation_backlog # @installation_officer new instance of container class. end
and working.
however, began wonder if correct way of doing it. like: sure if stub wrong ( inexistent ) method, , test it, pass or fail?
i tried it, passed
so, if later, method name gets changed, there no way test detect that.
so, here question: how can sure rspec stubbed method existent in code?
here's how i'd set up. might help..
let(:backlog) { double('backlog', backlog_tasks: []) } before allow(api::dashboards::installationsbacklog).to receive(:new). and_return(backlog) end 'instantiates installationbacklog' expect(api::dashboards::installationbacklog).to receive(:new). with(operational_district_id, officer_id) @installation_officer.installation_backlog end 'calls backlog_tasks on instance of installationbacklog' expect(backlog).to receive(:backlog_tasks) @installation_officer.installation_backlog end
Comments
Post a Comment