Class: EmailSpec::Matchers::DeliverTo
- Inherits:
-
Object
- Object
- EmailSpec::Matchers::DeliverTo
- Defined in:
- lib/email_spec/matchers.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expected_email_addresses_or_objects_that_respond_to_email) ⇒ DeliverTo
constructor
A new instance of DeliverTo.
- #matches?(email) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(expected_email_addresses_or_objects_that_respond_to_email) ⇒ DeliverTo
Returns a new instance of DeliverTo.
35 36 37 38 39 40 41 |
# File 'lib/email_spec/matchers.rb', line 35 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
43 44 45 |
# File 'lib/email_spec/matchers.rb', line 43 def description "be delivered to #{@expected_recipients.inspect}" end |
#failure_message ⇒ Object
53 54 55 |
# File 'lib/email_spec/matchers.rb', line 53 def "expected #{@email.inspect} to deliver to #{@expected_recipients.inspect}, but it delivered to #{@actual_recipients.inspect}" end |
#matches?(email) ⇒ Boolean
47 48 49 50 51 |
# File 'lib/email_spec/matchers.rb', line 47 def matches?(email) @email = email @actual_recipients = (email.header[:to].addrs || []).map(&:to_s).sort @actual_recipients == @expected_recipients end |
#negative_failure_message ⇒ Object
57 58 59 |
# File 'lib/email_spec/matchers.rb', line 57 def "expected #{@email.inspect} not to deliver to #{@expected_recipients.inspect}, but it did" end |