Problems testing helpers - link_to and url_for don't work

So I’ve used the helper test plugin, and also tried some things from
Rails Recipes, and basically neither seems to work for cases where a
helper does anything related to link_to/url_for, and this includes
calling named_routes. This is obviously an issue, as a common use for
helpers is to refactoring something like this:

<%= link_to “text that changes slightly”, :id => id %>

to this

<%= article_link “text”, id, other_options %>

using a helper. That example is a over simplified, but you get the
idea. Just moving duplicated links to a helper to keep things dry.

The issue seems to be that the controller is always nil by the time
url_for gets call in ActionController::Base - so something weird is
going on with trying to use StubController having to do with scope.
There are also issues I’ve had in getting the controller set up to
match what happens in a real request, with filters being run and what

So I think a better solution would include:

  • FooHelperTest uses FooController as its controller with its filters
    run to simulate a request, otherwise the test state differs from
    production. A helper depends intimately upon its controller for
    things to work right, even with proper controller/view separation, so
    just doing a StubController doesn’t cut it.
  • figure out why the UrlHelper doesn’t see the @controller when doing
  • roll these changes into Geoffrey’s plugin or a new one…

any thoughts?