spec/mailer_spec.rb in mail_safe-0.3.1 vs spec/mailer_spec.rb in mail_safe-0.3.2
- old
+ new
@@ -3,51 +3,82 @@
describe MailSafe do
TEXT_POSTSCRIPT_PHRASE = /The original recipients were:/
HTML_POSTSCRIPT_PHRASE = /<p>\s+The original recipients were:\s+<\/p>/
def deliver_message(message_name, *args)
- if ActionMailer::VERSION::MAJOR < 3
- TestMailer.send("deliver_#{message_name}", *args)
- else
- TestMailer.send(message_name, *args).deliver
- end
+ TestMailer.send(message_name, *args).deliver
end
RSpec::Matchers.define :have_addresses do |*expected|
match do |actual|
actual.to_a.sort == expected
end
end
+ describe 'Delivering a plain text email to internal addresses with empty fields' do
+ before(:each) do
+ allow(MailSafe::Config).to receive(:is_internal_address?).and_return(true)
+ @email = deliver_message(:plain_text_message,
+ :to => 'internal-to@address.com')
+ end
+
+ it 'sends the email to the original addresses and dont fail' do
+ expect(@email[:to].value).to have_addresses('internal-to@address.com')
+ end
+ end
+
describe 'Delivering a plain text email to internal addresses' do
before(:each) do
- MailSafe::Config.stub(:is_internal_address?).and_return(true)
- @email = deliver_message(:plain_text_message, :to => 'internal-to@address.com', :bcc => 'internal-bcc@address.com', :cc => 'internal-cc@address.com')
+ allow(MailSafe::Config).to receive(:is_internal_address?).and_return(true)
+ @email = deliver_message(:plain_text_message,
+ :to => 'internal-to@address.com',
+ :bcc => 'internal-bcc@address.com',
+ :cc => 'internal-cc@address.com')
end
it 'sends the email to the original addresses' do
- @email.to.should have_addresses('internal-to@address.com')
- @email.cc.should have_addresses('internal-cc@address.com')
- @email.bcc.should have_addresses('internal-bcc@address.com')
+ expect(@email.to).to have_addresses('internal-to@address.com')
+ expect(@email.cc).to have_addresses('internal-cc@address.com')
+ expect(@email.bcc).to have_addresses('internal-bcc@address.com')
end
it 'does not add a post script to the body' do
- @email.body.to_s.should_not =~ TEXT_POSTSCRIPT_PHRASE
+ expect(@email.body.to_s).not_to match(TEXT_POSTSCRIPT_PHRASE)
end
end
+ describe 'Delivering a plain text email to internal addresses with names' do
+ before(:each) do
+ allow(MailSafe::Config).to receive(:is_internal_address?).and_return(true)
+ @email = deliver_message(:plain_text_message,
+ :to => 'Internal To <internal-to@address.com>',
+ :bcc => 'Internal Bcc <internal-bcc@address.com>',
+ :cc => 'Internal Cc <internal-cc@address.com>')
+ end
+
+ it 'sends the email to the original addresses' do
+ expect(@email[:to].value).to have_addresses('Internal To <internal-to@address.com>')
+ expect(@email[:cc].value).to have_addresses('Internal Cc <internal-cc@address.com>')
+ expect(@email[:bcc].value).to have_addresses('Internal Bcc <internal-bcc@address.com>')
+ end
+
+ it 'does not add a post script to the body' do
+ expect(@email.body.to_s).not_to match(TEXT_POSTSCRIPT_PHRASE)
+ end
+ end
+
describe 'Delivering a plain text email to external addresses' do
before(:each) do
- MailSafe::Config.stub(:is_internal_address?).and_return(false)
- MailSafe::Config.stub(:get_replacement_address).and_return('replacement@example.com')
+ allow(MailSafe::Config).to receive(:is_internal_address?).and_return(false)
+ allow(MailSafe::Config).to receive(:get_replacement_address).and_return('replacement@example.com')
@email = deliver_message(:plain_text_message, :to => 'external-to@address.com', :bcc => 'external-bcc@address.com', :cc => 'external-cc@address.com')
end
it 'sends the email to the replacement address' do
- @email.to.should have_addresses('replacement@example.com')
- @email.cc.should have_addresses('replacement@example.com')
- @email.bcc.should have_addresses('replacement@example.com')
+ expect(@email.to).to have_addresses('replacement@example.com')
+ expect(@email.cc).to have_addresses('replacement@example.com')
+ expect(@email.bcc).to have_addresses('replacement@example.com')
end
end
def deliver_email_with_mix_of_internal_and_external_addresses(message_name)
MailSafe::Config.internal_address_definition = /internal/
@@ -65,27 +96,27 @@
before(:each) do
deliver_email_with_mix_of_internal_and_external_addresses(:plain_text_message)
end
it 'sends the email to the appropriate address' do
- @email.to.should have_addresses('internal1@address.com', 'internal@domain.com')
- @email.cc.should have_addresses('internal1@address.com', 'internal2@address.com')
- @email.bcc.should have_addresses('internal@domain.com', 'internal@domain.com')
+ expect(@email.to).to have_addresses('internal1@address.com', 'internal@domain.com')
+ expect(@email.cc).to have_addresses('internal1@address.com', 'internal2@address.com')
+ expect(@email.bcc).to have_addresses('internal@domain.com')
end
it 'adds a plain text post script to the body' do
- @email.body.to_s.should =~ TEXT_POSTSCRIPT_PHRASE
+ expect(@email.body.to_s).to match(TEXT_POSTSCRIPT_PHRASE)
end
end
describe 'Delivering an html email to a mix of internal and external addresses' do
before(:each) do
deliver_email_with_mix_of_internal_and_external_addresses(:html_message)
end
it 'adds an html post script to the body' do
- @email.body.to_s.should =~ HTML_POSTSCRIPT_PHRASE
+ expect(@email.body.to_s).to match(HTML_POSTSCRIPT_PHRASE)
end
end
describe 'Delivering a multipart email to a mix of internal and external addresses' do
before(:each) do
@@ -95,13 +126,13 @@
def part(type)
@email.parts.detect { |p| p.content_type =~ type }.body.to_s
end
it 'adds a text post script to the body of the text part' do
- part(/text\/plain/).should =~ TEXT_POSTSCRIPT_PHRASE
+ expect(part(/text\/plain/)).to match(TEXT_POSTSCRIPT_PHRASE)
end
it 'adds an html post script to the body of the html part' do
- part(/text\/html/).should =~ HTML_POSTSCRIPT_PHRASE
+ expect(part(/text\/html/)).to match(HTML_POSTSCRIPT_PHRASE)
end
end
end