[rspec-users] Need help using URL helpers in controller tests

Christopher Bailey chris at cobaltedge.com
Thu Oct 9 15:24:06 EDT 2008

I have a controller test, where I want to do a GET on a page.  Our URL's are
complex, and need to be correct (duh, but we allow some slop, but that
causes a redirect which I want to avoid).  Anyway, in my controller test I
do a get to the URL that is produced by a helper method which calls a named
route URL helper.  This is not working, and I'm wondering why/what I'm
messing up.  Here's the line in the spec code that starts things off
(@widget is a real ActiveRecord object):
      get @controller.widget_path_for_seo(@widget)

The widget_path_for_seo method is defined in our ApplicationController.  It
digs some info out of the widget instance that then get passed to the named
route URL helper method, so it looks like this:

  def widget_path_for_seo(widget)
    location = seo_name_for_url widget.location.name
    building = seo_name_for_url(building_name_for_seo_url(widget.building),
true) + "-widgets"
    widget_id = seo_name_for_url(widget.name) + "-" + widget.id.to_s

    seo_widget_path(:location => location, : building => building, :id
=> widget_id)

It's the "seo_widget_path" named route helper method that is failing.  I've
checked that all values going into it are valid, but the error I get is in
ActionController::Base.url_for, where it's looking at the options hash of
values that are passed in, and doing this:


It compalins that @url is nil.  I'm wondering if this is due to being run
under the test environment or what I'm missing/not realizing, etc.  What's
strange is that some of the restful resource route url helpers work fine.
 Can anyone clue me in?

Christopher Bailey
Cobalt Edge LLC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081009/c723e17c/attachment.html>

More information about the rspec-users mailing list