# ActionMailer intermittent test failure

**URL:** <https://www.ruby-forum.com/t/actionmailer-intermittent-test-failure/181166>\
**Category:** Rails\
**Created:** [January 6, 2010, 6:35pm UTC](https://www.ruby-forum.com/t/actionmailer-intermittent-test-failure/181166 "2010-01-06T18:35:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Curtis\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea5d25/32.png) [@Curtis\_C](https://www.ruby-forum.com/u/Curtis_C)\
**Post date:** [January 6, 2010, 6:35pm UTC](https://www.ruby-forum.com/t/actionmailer-intermittent-test-failure/181166/1 "2010-01-06T18:35:02Z")

</div>

I’ve written a test for a controller that sends email using  
ActionMailer. The problem is the test fails sporadically. It almost  
seems like ActionMailer::Base.deliveries isn’t being updated by the  
time the assert checks, but I don’t think ActionMailer sends emails  
asynchronously, at least nothing in the guide indicates that is the  
case.

I tried adding a sleep before the assert to see if it was a threading  
thing, but I still get the failure at about the same interval.

Here is my test code:

test “should remind players” do  
session.clear  
get :reminder  
assert\_emails 2  
assert\_equal %w[removed\_email\_address@domain.invalid], ActionMailer::Base.deliveries[0].to  
assert\_equal “Game Reminder”,  
ActionMailer::Base.deliveries[0].subject  
assert\_equal users(:two).email,  
ActionMailer::Base.deliveries[0].from[0]  
end

Any known issues with intermittent ActionMailer or  
ActionMailer::TestCase failures?

# – Curtis C. removed\_email\_address@domain.invalid home:[http://curtiscooley.com](http://curtiscooley.com) blog:[http://ponderingobjectorienteddesign.blogspot.com](http://ponderingobjectorienteddesign.blogspot.com)

Leadership is a potent combination of strategy and character. But if  
you must be without one, be without the strategy.  
– H. Norman Schwarzkopf

---

<div class="post-metadata">

**Author:** ![Curtis\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea5d25/32.png) [@Curtis\_C](https://www.ruby-forum.com/u/Curtis_C)\
**Post date:** [January 6, 2010, 6:53pm UTC](https://www.ruby-forum.com/t/actionmailer-intermittent-test-failure/181166/2 "2010-01-06T18:53:10Z")

</div>

Ignore. I found the problem and it had nothing to do with ActionMailer  
or ActionMailer::Test. It was a boundary condition error in my test  
fixture. Sometimes the test took just long enough to run that a date  
check failed and no emails were actually sent.

On Wed, Jan 6, 2010 at 9:33 AM, Curtis C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Here is my test code:  
> Any known issues with intermittent ActionMailer or  
> – H. Norman Schwarzkopf

# – Curtis C. removed\_email\_address@domain.invalid home:[http://curtiscooley.com](http://curtiscooley.com) blog:[http://ponderingobjectorienteddesign.blogspot.com](http://ponderingobjectorienteddesign.blogspot.com)

Leadership is a potent combination of strategy and character. But if  
you must be without one, be without the strategy.  
– H. Norman Schwarzkopf
