Class: EmailSpec::Matchers::DeliverFrom

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

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ DeliverFrom

Returns a new instance of DeliverFrom.



70
71
72
# File 'lib/email_spec/matchers.rb', line 70

def initialize(email)
  @expected_sender = TMail::Address.parse(email)
end

Instance Method Details

#descriptionObject



74
75
76
# File 'lib/email_spec/matchers.rb', line 74

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

#failure_messageObject



87
88
89
# File 'lib/email_spec/matchers.rb', line 87

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

#matches?(email) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
# File 'lib/email_spec/matchers.rb', line 78

def matches?(email)
  @email = email
  @actual_sender = (email.from_addrs || []).first

  !@actual_sender.nil? &&
    @actual_sender.address == @expected_sender.address &&
    @actual_sender.name == @expected_sender.name
end

#negative_failure_messageObject



91
92
93
# File 'lib/email_spec/matchers.rb', line 91

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