[rspec-users] Route generation inside mailer specs

Wincent Colaiuta win at wincent.com
Mon Feb 25 06:09:31 EST 2008

Rails mailers live under "app/models" even though they have some  
controller-like responsibilities, and I stick the corresponding specs  
under "spec/models"

In one of my mailers I use the kind of dynamic route generation  
methods that Rails provides, things like foo_bar_path and foo_bar_url.

What would I need to do to get access to those methods from within my  
mailer specs? I basically want to confirm the presence of a url in the  
generated body, something like:

   url = foo_bar_url(@foo, @bar)
   @mail.body.should match(url)

Evidently I need to include some module or something, but as it's all  
dynamically generated I have no idea where to begin looking.

Oddly enough, the foo_bar_url _is_ defined within the context of the  
example (ie. I don't get an "undefined method foo_bar_url in  
exception), but what I _do_ get is:

   You have a nil object when you didn't expect it!
   The error occurred while evaluating nil.foo_bar_url

So the message is being sent to nil... not what I would have expected.


More information about the rspec-users mailing list