Controller:
@organization.topics.find(params[:id])
How can I stub this in my controller_spec with Rspec? (@organization IS being set in my spec helper)
I’ve tried:
controller.stub_chain(:topics, :find).with("37") { mock_topic }
Topic.stub(:find).with("37") { mock_topic }
Neither of the above seem to work. Any ideas? Thanks!
If you have access to the
@organizationvariable (you indicate that you do) then you should be able to:I don’t believe (unless they’ve changed the API to stub_chain, but I don’t see anything of that nature in the docs) you can specify a .with(’37’) when using stub_chain. If it is absolutely necessary that you specify what variable is passed to the find method (and it rarely is), you’ll have to take the long route: