Class: EmailSpec::Matchers::DeliverFrom

Inherits:
EmailMatcher show all
Defined in:
lib/email_spec/matchers.rb

Instance Method Summary collapse

Methods inherited from EmailMatcher

#address_array

Constructor Details

#initialize(email) ⇒ DeliverFrom

Returns a new instance of DeliverFrom.



85
86
87
# File 'lib/email_spec/matchers.rb', line 85

def initialize(email)
  @expected_sender = Mail::FromField.new(email).addrs.first
end

Instance Method Details

#descriptionObject



89
90
91
# File 'lib/email_spec/matchers.rb', line 89

def description
  "be delivered from #{@expected_sender}"
end

#failure_messageObject



101
102
103
# File 'lib/email_spec/matchers.rb', line 101

def failure_message
  %(expected #{@email.inspect} to deliver from "#{@expected_sender.to_s}", but it delivered from "#{@actual_sender.to_s}")
end

#failure_message_when_negatedObject Also known as: negative_failure_message



105
106
107
# File 'lib/email_spec/matchers.rb', line 105

def failure_message_when_negated
  %(expected #{@email.inspect} not to deliver from "#{@expected_sender.to_s}", but it did)
end

#matches?(email) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
96
97
98
99
# File 'lib/email_spec/matchers.rb', line 93

def matches?(email)
  @email = email
  @actual_sender = address_array{ email.header[:from].addrs }.first

  !@actual_sender.nil? &&
    @actual_sender.to_s == @expected_sender.to_s
end