Skip to content

Commit

Permalink
Fixed exceptions when matching arrays of emails against regexps; fixes
Browse files Browse the repository at this point in the history
…thoughtbotgh-125 (based on a patch from github.com/phene)
  • Loading branch information
jferris committed Aug 17, 2010
1 parent b0692c3 commit 02520e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/shoulda/action_mailer/matchers/have_sent_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def regexp_or_string_match(a_string, a_regexp_or_string)
def regexp_or_string_match_in_array(an_array, a_regexp_or_string)
case a_regexp_or_string
when Regexp
an_array.detect{|e| e =~ a_regexp_or_string}.any?
an_array.any? { |string| string =~ a_regexp_or_string }
when String
an_array.include?(a_regexp_or_string)
end
Expand Down
8 changes: 7 additions & 1 deletion test/matchers/action_mailer/have_sent_email_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ def the_email
:message => /Expected sent email with subject/
end

should "accept based on the sender" do
should "accept based on a string sender" do
assert_accepts have_sent_email.from('do-not-reply@example.com'), nil
assert_rejects have_sent_email.from('you@example.com'), nil,
:message => /Expected sent email from/
end

should "accept based on a regexp sender" do
assert_accepts have_sent_email.from(/@example\.com/), nil
assert_rejects have_sent_email.from(/you@/), nil,
:message => /Expected sent email from/
end

should "accept based on the body" do
assert_accepts have_sent_email.with_body(/is spam\./), nil
assert_rejects have_sent_email.with_body(/totally safe/), nil,
Expand Down

0 comments on commit 02520e4

Please sign in to comment.