Class: EmailSpec::Matchers::DeliverTo
- Inherits:
-
EmailMatcher
- Object
- EmailMatcher
- EmailSpec::Matchers::DeliverTo
- Defined in:
- lib/email_spec/matchers.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object (also: #negative_failure_message)
-
#initialize(expected_email_addresses_or_objects_that_respond_to_email) ⇒ DeliverTo
constructor
A new instance of DeliverTo.
- #matches?(email) ⇒ Boolean
Methods inherited from EmailMatcher
Constructor Details
#initialize(expected_email_addresses_or_objects_that_respond_to_email) ⇒ DeliverTo
Returns a new instance of DeliverTo.
48 49 50 51 52 53 54 |
# File 'lib/email_spec/matchers.rb', line 48 def initialize(expected_email_addresses_or_objects_that_respond_to_email) emails = expected_email_addresses_or_objects_that_respond_to_email.map do |email_or_object| email_or_object.kind_of?(String) ? email_or_object : email_or_object.email end @expected_recipients = Mail::ToField.new(emails).addrs.map(&:to_s).sort end |
Instance Method Details
#description ⇒ Object
56 57 58 |
# File 'lib/email_spec/matchers.rb', line 56 def description "be delivered to #{@expected_recipients.inspect}" end |
#failure_message ⇒ Object
67 68 69 |
# File 'lib/email_spec/matchers.rb', line 67 def "expected #{@email.inspect} to deliver to #{@expected_recipients.inspect}, but it delivered to #{@actual_recipients.inspect}" end |
#failure_message_when_negated ⇒ Object Also known as: negative_failure_message
71 72 73 |
# File 'lib/email_spec/matchers.rb', line 71 def "expected #{@email.inspect} not to deliver to #{@expected_recipients.inspect}, but it did" end |
#matches?(email) ⇒ Boolean
60 61 62 63 64 65 |
# File 'lib/email_spec/matchers.rb', line 60 def matches?(email) @email = email recipients = email.header[:to] || email.header[:bcc] @actual_recipients = address_array{ recipients && recipients.addrs }.map(&:to_s).sort @actual_recipients == @expected_recipients end |