class EmailSpec::Matchers::HaveHeader

Public Class Methods

new(name, value) click to toggle source
# File lib/email_spec/matchers.rb, line 322
def initialize(name, value)
  @expected_name, @expected_value = name, value
end

Public Instance Methods

description() click to toggle source
# File lib/email_spec/matchers.rb, line 326
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() click to toggle source
# File lib/email_spec/matchers.rb, line 343
def failure_message
  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() click to toggle source
# File lib/email_spec/matchers.rb, line 351
def failure_message_when_negated
  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
Also aliased as: negative_failure_message
mail_headers_hash(email_headers) click to toggle source
# File lib/email_spec/matchers.rb, line 360
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) click to toggle source
# File lib/email_spec/matchers.rb, line 334
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
negative_failure_message()