Class: EmailSpec::Matchers::HaveHeader
- Inherits:
-
Object
- Object
- EmailSpec::Matchers::HaveHeader
- 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(name, value) ⇒ HaveHeader
constructor
A new instance of HaveHeader.
- #mail_headers_hash(email_headers) ⇒ Object
- #matches?(email) ⇒ Boolean
Constructor Details
#initialize(name, value) ⇒ HaveHeader
Returns a new instance of HaveHeader.
321 322 323 |
# File 'lib/email_spec/matchers.rb', line 321 def initialize(name, value) @expected_name, @expected_value = name, value end |
Instance Method Details
#description ⇒ Object
325 326 327 328 329 330 331 |
# File 'lib/email_spec/matchers.rb', line 325 def description if @expected_value.is_a?(String) "have header #{@expected_name}: #{@expected_value}" else "have header #{@expected_name} with value matching #{@expected_value.inspect}" end end |
#failure_message ⇒ Object
342 343 344 345 346 347 348 |
# File 'lib/email_spec/matchers.rb', line 342 def if @expected_value.is_a?(String) "expected the headers to include '#{@expected_name}: #{@expected_value}' but they were #{mail_headers_hash(@given_header).inspect}" else "expected the headers to include '#{@expected_name}' with a value matching #{@expected_value.inspect} but they were #{mail_headers_hash(@given_header).inspect}" end end |
#failure_message_when_negated ⇒ Object Also known as: negative_failure_message
350 351 352 353 354 355 356 |
# File 'lib/email_spec/matchers.rb', line 350 def if @expected_value.is_a?(String) "expected the headers not to include '#{@expected_name}: #{@expected_value}' but they were #{mail_headers_hash(@given_header).inspect}" else "expected the headers not to include '#{@expected_name}' with a value matching #{@expected_value.inspect} but they were #{mail_headers_hash(@given_header).inspect}" end end |
#mail_headers_hash(email_headers) ⇒ Object
359 360 361 |
# File 'lib/email_spec/matchers.rb', line 359 def mail_headers_hash(email_headers) email_headers.fields.inject({}) { |hash, field| hash[field.field.class::FIELD_NAME] = field.to_s; hash } end |
#matches?(email) ⇒ Boolean
333 334 335 336 337 338 339 340 |
# File 'lib/email_spec/matchers.rb', line 333 def matches?(email) @given_header = email.header if @expected_value.is_a?(String) @given_header[@expected_name].to_s == @expected_value else @given_header[@expected_name].to_s =~ @expected_value end end |