[rspec-users] Cucumber - Testing ActionMailer

James Byrne lists at ruby-forum.com
Wed Apr 29 10:08:59 EDT 2009

James Byrne wrote:
> I have reached this point in testing using email-spec:
> The email To: header value and the current_email_address are the same 
> insofar as I can tell.  But the email_spec matcher is not finding that 
> address in the deliveries array.  Any ideas as to what I am missing?

I have determined what the problem is. I just do not know how to fix it.

What is happening is that I am testing a standalone (outside of a Rails 
instance) Ruby script that requires ActionMailer.  I call this script 
from inside the step definition using the %x alias for Kernel#`. When 
this runs it picks up the test environment and directs email output into 
ActionMailer::Base.deliveries.  However, this array only exists during 
the script's existence and naturally disappears when he script 
terminates. In consequence, the results are not available for testing.

I have, up to now, simply accepted the magic of injecting test methods 
into classes and using the results.  Now I need to have explained how I 
get this to magic work with stand alone scripts.  How do I get 
ActionMailer::Base.deliveries created by ActionMailer in the script to 
remain available to cucumber/email-spec?
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list