Class: Tape::EmailSpec::Matchers::DeliverTo

Inherits:
Object
  • Object
show all
Defined in:
lib/tape/email_spec/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_email_addresses_or_objects_that_respond_to_email) ⇒ DeliverTo

Returns a new instance of DeliverTo.



36
37
38
39
40
41
42
# File 'lib/tape/email_spec/matchers.rb', line 36

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

#descriptionObject



44
45
46
# File 'lib/tape/email_spec/matchers.rb', line 44

def description
  "be delivered to #{@expected_recipients.inspect}"
end

#failure_messageObject



54
55
56
# File 'lib/tape/email_spec/matchers.rb', line 54

def failure_message
  "expected #{@email.inspect} to deliver to #{@expected_recipients.inspect}, but it delivered to #{@actual_recipients.inspect}"
end

#matches?(email) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/tape/email_spec/matchers.rb', line 48

def matches?(email)
  @email = email
  @actual_recipients = (email.header[:to].addrs || []).map(&:to_s).sort
  @actual_recipients == @expected_recipients
end

#negative_failure_messageObject



58
59
60
# File 'lib/tape/email_spec/matchers.rb', line 58

def negative_failure_message
  "expected #{@email.inspect} not to deliver to #{@expected_recipients.inspect}, but it did"
end