James Byrne wrote:
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?
I have plans to make email-spec work with any SMTP mailer and thereby
making it more "black-box"y and allow for external processes to be
easily tested... However, that is not done yet. As it stands now you
have two options: a) have the test execution and script in the same
process or b) Use ARMailer[1] in your testing environment. ARMailer
places the messages in a database for queuing. So instead of checking
the in-memory array EmailSpec will check the queue on the database.
Since this is just for testing then you could use a lightweight sqlite3
db to store this.
-Ben
1. http://github.com/seattlerb/ar_mailer/tree/master
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users