Testing UrlHelper in ActionMailer

Hi All,

So I found a helpful web page that explained how I could use things like
url_for in my mails:


However, I can’t test them properly. The problem is that when I create a
controller in my unit tests and pass it into the ActionMailer, it’s not
a real controller, set up as a controller is when it is instantiated via
an http request, so variables inside the controller like @url are not
set, meaning the test based version of the mail fails.

What I’m trying to do in the mail is something like this:

<%= url_for :controller => ‘discussions’, :action => ‘tree’, :id =>
@discussion %>

so I don’t really need the defaults in the controller @url anyhow.

Any ideas how I can test this thing properly? Create a mock controller
Some method to set the controllers @url variable …?

I was trying this:

class MockController < ActionController::Base
@url =

but I keep getting “MissingSourceFile: No such file to load –
url_rewriter” errors - I can’t work out how to pull in the UrlRewriter
class …

Many thanks in advance.


I found a way round this by patching actioncontroller::base



This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs