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 => ''fred at
mail.com'')
@user2 = mock_model(UserAccount, :email => ''bill at
mail.com'')
@user3 = mock_model(UserAccount, :email => ''jane at
mail.com'')
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
=>
''admin at fiveacross.com'', :subject => ''testing
email''}
@emails.size.should == 3
email_to_fred = @emails[0]
email_to_fred.to.should == [''fred at mail.com'']
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 == [''bill at mail.com'']
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 == [''jane at mail.com'']
email_to_jane.subject.should == ''testing email''
email_to_jane.body.should match(/my message/)
end
HTH
Shane