1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
# encoding: utf-8
# frozen_string_literal: true
require 'spec_helper'
describe "Mail::TestMailer" do
before(:each) do
# Reset all defaults back to original state
Mail.defaults do
delivery_method :smtp, { :address => "localhost",
:port => 25,
:domain => 'localhost.localdomain',
:user_name => nil,
:password => nil,
:authentication => nil,
:enable_starttls_auto => true }
Mail::TestMailer.deliveries.clear
end
end
it "should have no deliveries when first initiated" do
Mail.defaults do
delivery_method :test
end
expect(Mail::TestMailer.deliveries).to be_empty
end
it "should deliver an email to the Mail::TestMailer.deliveries array" do
Mail.defaults do
delivery_method :test
end
mail = Mail.new do
to 'mikel@me.com'
from 'you@you.com'
subject 'testing'
body 'hello'
end
mail.deliver
expect(Mail::TestMailer.deliveries.length).to eq 1
expect(Mail::TestMailer.deliveries.first).to eq mail
end
it "should clear the deliveries when told to" do
Mail.defaults do
delivery_method :test
end
mail = Mail.new do
to 'mikel@me.com'
from 'you@you.com'
subject 'testing'
body 'hello'
end
mail.deliver
expect(Mail::TestMailer.deliveries.length).to eq 1
Mail::TestMailer.deliveries.clear
expect(Mail::TestMailer.deliveries).to be_empty
end
it "should not raise errors if no sender is defined" do
Mail.defaults do
delivery_method :test
end
mail = Mail.new do
to "to@somemail.com"
subject "Email with no sender"
body "body"
end
expect(mail.smtp_envelope_from).to be_nil
expect do
mail.deliver
end.to raise_error('SMTP From address may not be blank: nil')
end
it "should raise an error if no recipient if defined" do
Mail.defaults do
delivery_method :test
end
mail = Mail.new do
from "from@somemail.com"
subject "Email with no recipient"
body "body"
end
expect(mail.smtp_envelope_to).to eq([])
expect do
mail.deliver
end.to raise_error('SMTP To address may not be blank: []')
end
it "should save settings passed to initialize" do
expect(Mail::TestMailer.new(:setting => true).settings).to include(:setting => true)
end
end
|