# Testing emails with RSpec 1.0.8

**URL:** <https://www.ruby-forum.com/t/testing-emails-with-rspec-1-0-8/115763>\
**Category:** RSpec\
**Created:** [September 28, 2007, 11:02am UTC](https://www.ruby-forum.com/t/testing-emails-with-rspec-1-0-8/115763 "2007-09-28T11:02:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fukas78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/85f322/32.png) [@fukas78](https://www.ruby-forum.com/u/fukas78)\
**Post date:** [September 28, 2007, 11:02am UTC](https://www.ruby-forum.com/t/testing-emails-with-rspec-1-0-8/115763/1 "2007-09-28T11:02:45Z")

</div>

Anyone is doing email testing with RSpec?  
Can you post some examples?

Thank you, Laco M.

---

<div class="post-metadata">

**Author:** ![fukas78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/85f322/32.png) [@fukas78](https://www.ruby-forum.com/u/fukas78)\
**Post date:** [September 28, 2007, 11:08am UTC](https://www.ruby-forum.com/t/testing-emails-with-rspec-1-0-8/115763/2 "2007-09-28T11:08:37Z")

</div>

On 28/09/2007, at 9:01 PM, Ladislav Martincik wrote:

> Anyone is doing email testing with RSpec?  
> Can you post some examples?

Like this?

before(:each) do  
@user1 = mock\_model(UserAccount, :email =\> ‘removed\_email\_address@domain.invalid’)  
@user2 = mock\_model(UserAccount, :email =\> ‘removed\_email\_address@domain.invalid’)  
@user3 = mock\_model(UserAccount, :email =\> ‘removed\_email\_address@domain.invalid’)  
UserAccount.should\_receive(:find).with(:all).and\_return([@user1,  
@user2, @user3])  
@controller.stub!(:authorize).and\_return(true)  
@emails = ActionMailer::Base.deliveries  
@emails.clear  
end

it “should send three separate emails” do  
post :email, :email =\>{:body =\> ‘my message’, :from =\>  
‘removed\_email\_address@domain.invalid’, :subject =\> ‘testing email’}  
@emails.size.should == 3

```
 email_to_fred = @emails[0]
 email_to_fred.to.should == ['removed_email_address@domain.invalid']
 email_to_fred.subject.should == 'testing email'
 email_to_fred.body.should match(/my message/)

 email_to_bill = @emails[1]
 email_to_bill.to.should == ['removed_email_address@domain.invalid']
 email_to_bill.subject.should == 'testing email'
 email_to_bill.body.should match(/my message/)

 email_to_jane = @emails[2]
 email_to_jane.to.should == ['removed_email_address@domain.invalid']
 email_to_jane.subject.should == 'testing email'
 email_to_jane.body.should match(/my message/)

```

end

HTH  
Shane
