Created
May 18, 2013 19:46
-
-
Save 7maples/5605558 to your computer and use it in GitHub Desktop.
Examples of specs for emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe UserMailer do | |
describe "signup_confirmation" do | |
let!(:user) {User.create(:username => 'jen', :email => '7maples@example.com')} | |
let(:mail) { UserMailer.signup_confirmation } | |
before { ActionMailer::Base.deliveries = [] } | |
it "confirms delivery" do | |
UserMailer.signup_confirmation(user).deliver | |
ActionMailer::Base.deliveries.should_not be_empty | |
end | |
end | |
end | |
#Using FactoryGirl - from Raph | |
describe Mailer do | |
it 'sends a welcome email' do | |
user = FactoryGirl.create(:user, email: 'phyzikz@gmail.com') | |
email = Mailer.welcome_email(user).deliver | |
expect(ActionMailer::Base.deliveries).to_not be_empty | |
end | |
it 'sends an order confirmation email' do | |
user = FactoryGirl.create(:user, email: 'phyzikz@gmail.com') | |
order = FactoryGirl.create(:order, user: user) | |
email = Mailer.order_confirmation(user, order).deliver | |
expect(ActionMailer::Base.deliveries).to_not be_empty | |
end | |
end | |
#Attachments | |
it "sends an email to the customer with images attached" do | |
post :create, valid_params | |
expect(ActionMailer::Base.deliveries.first.attachments.first.filename).to eq "001.jpg" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment