Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/osaris/shoulda-matchers

  • Loading branch information...
commit abad4a892d957f5ec26bb33ce96bf79ac8ef024d 2 parents bf937c9 + cabe44c
@mike-burns mike-burns authored
View
17 lib/shoulda/matchers/action_mailer/have_sent_email.rb
@@ -11,6 +11,7 @@ module ActionMailer # :nodoc:
# it { should have_sent_email.with_part('text/html', /HTML spam/) }
# it { should have_sent_email.with_subject(/spam/).
# from('do-not-reply@example.com').
+ # reply_to('reply-to-me@example.com').
# with_body(/spam/).
# to('myself@me.com') }
#
@@ -43,6 +44,12 @@ def from(sender = nil, &block)
self
end
+ def reply_to(reply_to = nil, &block)
+ @reply_to = reply_to
+ @reply_to_block = block
+ self
+ end
+
def with_body(body = nil, &block)
@body = body
@body_block = block
@@ -99,6 +106,7 @@ def matches?(subject)
@parts_failed = !parts_match(mail, @parts) if @parts
@body_failed = !body_match(mail, @body) if @body
@sender_failed = !regexp_or_string_match_in_array(mail.from, @sender) if @sender
+ @reply_to_failed = !regexp_or_string_match_in_array(mail.reply_to, @reply_to) if @reply_to
@recipient_failed = !regexp_or_string_match_in_array(mail.to, @recipient) if @recipient
@cc_failed = !regexp_or_string_match_in_array(mail.cc, @cc) if @cc
@cc_recipients_failed = !match_array_in_array(mail.cc, @cc_recipients) if @cc_recipients
@@ -127,6 +135,7 @@ def description
description << " having a #{content_type} part containing #{body.inspect}"
end if @parts
description << " from #{@sender.inspect}" if @sender
+ description << " reply to #{@reply_to.inspect}" if @reply_to
description << " to #{@recipient.inspect}" if @recipient
description << " cc #{@cc.inspect}" if @cc
description << " with cc #{@cc_recipients.inspect}" if @cc_recipients
@@ -145,6 +154,7 @@ def expectation
expectation << " with a #{content_type} part containing #{body}"
end if @parts && @parts_failed
expectation << " from #{@sender.inspect}" if @sender_failed
+ expectation << " reply to #{@reply_to.inspect}" if @reply_to_failed
expectation << " to #{@recipient.inspect}" if @recipient_failed
expectation << " cc #{@cc.inspect}" if @cc_failed
expectation << " with cc #{@cc_recipients.inspect}" if @cc_recipients_failed
@@ -161,14 +171,15 @@ def inspect_deliveries
end
def anything_failed?
- @subject_failed || @body_failed || @sender_failed || @recipient_failed ||
- @cc_failed || @cc_recipients_failed || @bcc_failed || @bcc_recipients_failed ||
- @parts_failed || @multipart_failed
+ @subject_failed || @body_failed || @sender_failed || @reply_to_failed ||
+ @recipient_failed || @cc_failed || @cc_recipients_failed || @bcc_failed ||
+ @bcc_recipients_failed || @parts_failed || @multipart_failed
end
def normalize_blocks
@email_subject = @context.instance_eval(&@email_subject_block) if @email_subject_block
@sender = @context.instance_eval(&@sender_block) if @sender_block
+ @reply_to = @context.instance_eval(&@reply_to_block) if @reply_to_block
@body = @context.instance_eval(&@body_block) if @body_block
@recipient = @context.instance_eval(&@recipient_block) if @recipient_block
@cc = @context.instance_eval(&@cc_block) if @cc_block
View
7 spec/shoulda/action_mailer/have_sent_email_spec.rb
@@ -11,6 +11,7 @@ def add_mail_to_deliveries(params = nil)
before do
@info = {
:from => "do-not-reply@example.com",
+ :reply_to => "reply-to-me@example.com",
:to => "myself@me.com",
:cc => ["you@you.com", "joe@bob.com", "hello@goodbye.com"],
:bcc => ["test@example.com", "sam@bob.com", "goodbye@hello.com"],
@@ -39,6 +40,10 @@ def the_email(params)
should have_sent_email.from{ @info[:from] }
end
+ it "should send an e-email based on reply_to" do
+ should have_sent_email.reply_to { @info[:reply_to] }
+ end
+
it "should send an e-mail based on cc" do
should have_sent_email.cc{ @info[:cc][0] }
end
@@ -276,5 +281,7 @@ def the_email(params)
matcher.description.should == 'send an email with a subject of "Welcome!" containing "Welcome, human!" having a text/plain part containing "plain" having a text/html part containing "html" from "alien@example.com"'
matcher = matcher.to("human@example.com")
matcher.description.should == 'send an email with a subject of "Welcome!" containing "Welcome, human!" having a text/plain part containing "plain" having a text/html part containing "html" from "alien@example.com" to "human@example.com"'
+ matcher = matcher.reply_to("reply-to-me@example.com")
+ matcher.description.should == 'send an email with a subject of "Welcome!" containing "Welcome, human!" having a text/plain part containing "plain" having a text/html part containing "html" from "alien@example.com" reply to "reply-to-me@example.com" to "human@example.com"'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.