Setting up params for path helpers in view specs

I am writing a view spec for a view (surprise, surprise) that has call to a path helper in the form of…

edit_company_url(:format => 'json')

When rendered in the browser (on an html rendering of the same company#edit action), this works fine since the params contain the appropriate :id, and rails magic is able to discern the correct url. However, when trying to write a view spec for this template, I get an routing error due to the lack of a company ID. It still fails even when I setup params within the spec. If I rewrite the helper call to…

edit_company_url(@company, :format => 'json')

then the test works fine. I’ll probably end up leaving it like that, as it’s more explicit/readable anyway. But Im curious if there’s an appropriate way to setup params, etc, in the view spec to make this helper work as originally written.

@jsgarvin… What’s the full spec?

Also, you might want to check out the “View Specs | assigns” section of the Rspec documentation and see if that helps.

It seems like the path helper is taking params from the controller’s request path_parameters. If no argument is provided it will use the implicit :id parameter, which you can set on the stub controller provided by rspec:

controller.request.path_parameters[:id] =

Sorry for bumping an old thread, but I spent a while searching for this too and this thread was one of the only useful results that showed up.