[rspec-users] Spec'ing ActionMailer

s.ross cwdinfo at gmail.com
Mon Feb 5 13:52:04 EST 2007


I still don't have this working (see my previous email with the  
pastie attached), but now have another ActionMailer/rSpec question.  
I'm spec'ing a different mailer model directly (instead of through  
the controller). It's meant to be invoked through script/runner, so I  
won't have a response object.

I can see in the plugin source that there is assert_select_email  
support, but I'm pretty sure there is no expectation that starts with  
"assert." How would one spec something like:

setup do
   ActionMailer::Base.delivery_method = :test
   ActionMailer::Base.perform_deliveries = true
   ActionMailer::Base.deliveries = []
   MyMailer.trigger_emails   # invokes model method to send 4 emails

specify "d'oh! should have a non-empty recipient list" do
   ActionMailer::Base.deliveries.size.should be(4)
   ActionMailer::Base.deliveries.each do |email|
     email.recipients.should_not be_empty

specify "first email should have a list item with the name of the  
first guy" do
   ActionMailer::Base.deliveries[0].should select_tag('li', members 

The above code is truly bogus and doesn't work. I'm trying to figure  
out where to get the messages and how to specify the expectations on  



On Feb 4, 2007, at 1:35 PM, David Chelimsky wrote:

> Steve - are you using the RSpec trunk?
> If you are, AND your email is html email, you can use this right now:
> response.should send_email {
>   with_tag("div", "joe at shmoe.com")
>   with_tag("div", projects(:trace).name)
>   with_tag("div", member/show)
> }
> There is no specific support yet for email headers, nor raw text,
> though I can see now there is a need for that and will raise the
> appropriate RFE.
> David

More information about the rspec-users mailing list