diff --git a/lib/shoulda/action_mailer/matchers/have_sent_email.rb b/lib/shoulda/action_mailer/matchers/have_sent_email.rb index 1151d814..baa08a68 100644 --- a/lib/shoulda/action_mailer/matchers/have_sent_email.rb +++ b/lib/shoulda/action_mailer/matchers/have_sent_email.rb @@ -98,7 +98,7 @@ module Shoulda # :nodoc: 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 diff --git a/test/matchers/action_mailer/have_sent_email_test.rb b/test/matchers/action_mailer/have_sent_email_test.rb index 0cb42014..8234d957 100644 --- a/test/matchers/action_mailer/have_sent_email_test.rb +++ b/test/matchers/action_mailer/have_sent_email_test.rb @@ -37,12 +37,18 @@ class HaveSentEmailTest < ActiveSupport::TestCase # :nodoc: :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,