[rspec-users] Routes helpers work differently from helper examples compared to page rendering

Ed Ruder ed.ruder at gmail.com
Sat Jul 4 17:40:52 EDT 2009

I have a helper that calls a Rails route _url method. In the context
of a helper spec file, the route helper method ends up calling url_for
in rails/actionpack/lib/action_controller/base.rb. In the context of
rendering a page, the route helper method calls url_for in rails/
actionpack/lib/action_view/helpers/url_helper.rb. Though very similar,
they can return different results, as I found out.

Specifically, ActionController::Base#url_for doesn't do html escaping--
ActionView::Helpers::UrlHelper#url_for does, and has an additional
parameter, :escape => true|false, to controller whether or not the
escaping is done.

This took some frustrating time to track down.

Since the code path executed by helper examples is not the same as
production, tests can produce invalid results. Also, some behavior
cannot be tested, since the code generating the results is not being

Is this a bug in RSpec, or is there a "correct" way to test helpers
that I'm missing?

More information about the rspec-users mailing list