Skip to content

Commit

Permalink
Add test coverage for single-part emails and fix multipart failure case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Morrison committed Jun 3, 2011
1 parent 1d9c303 commit 267ea99
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/shoulda/matchers/action_mailer/have_sent_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def expectation
end if @parts && @parts_failed
expectation << " from #{@sender.inspect}" if @sender_failed
expectation << " to #{@recipient.inspect}" if @recipient_failed
expectation << " #{!@multipart && 'not '}being multipart" if @multipart_failed
expectation << " #{'not ' if !@multipart}being multipart" if @multipart_failed
expectation << "\nDeliveries:\n#{inspect_deliveries}"
end

Expand Down
34 changes: 33 additions & 1 deletion spec/shoulda/action_mailer/have_sent_email_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,39 @@ def add_mail_to_deliveries
::ActionMailer::Base.deliveries << Mailer.the_email
end

context "an email" do
context "an email without multiple parts" do
before do

This comment has been minimized.

Copy link
@vjt

vjt Jun 5, 2011

Contributor

hi, sorry for being picky, but this line is too much indented :-)

This comment has been minimized.

Copy link
@jasonm

jasonm Jun 5, 2011

Contributor

Thanks, good catch - committed in 85d3e5e

define_mailer :mailer, [:the_email] do
def the_email
mail :from => "do-not-reply@example.com",
:to => "myself@me.com",
:body => "Every email is spam",
:subject => "This is spam"
end
end
add_mail_to_deliveries
end

after { ::ActionMailer::Base.deliveries.clear }

it "accepts sent-email when it is not multipart" do
should_not have_sent_email.multipart
matcher = have_sent_email.multipart(true)
matcher.matches?(Mailer.the_email)
matcher.failure_message.should =~ /Expected sent email being multipart/
end

it "matches the body with a regexp" do
should have_sent_email.with_body(/email is spam/)
end

it "matches the body with a string" do
should have_sent_email.with_body("Every email is spam")
should_not have_sent_email.with_body("emails is")
end
end

context "an email with both a text/plain and text/html part" do
before do
define_mailer :mailer, [:the_email] do
def the_email
Expand Down

0 comments on commit 267ea99

Please sign in to comment.