class EmailSpec::Matchers::HaveBodyText

Public Class Methods

new(text) click to toggle source
# File lib/email_spec/matchers.rb, line 275
def initialize(text)
  @expected_text = text
end

Public Instance Methods

description() click to toggle source
# File lib/email_spec/matchers.rb, line 279
def description
  if @expected_text.is_a?(String)
    "have body including #{@expected_text.inspect}"
  else
    "have body matching #{@expected_text.inspect}"
  end
end
failure_message() click to toggle source
# File lib/email_spec/matchers.rb, line 298
def failure_message
  if @expected_text.is_a?(String)
    "expected the body to contain #{@expected_text.inspect} but was #{@given_text.inspect}"
  else
    "expected the body to match #{@expected_text.inspect}, but did not.  Actual body was: #{@given_text.inspect}"
  end
end
failure_message_when_negated() click to toggle source
# File lib/email_spec/matchers.rb, line 306
def failure_message_when_negated
  if @expected_text.is_a?(String)
    "expected the body not to contain #{@expected_text.inspect} but was #{@given_text.inspect}"
  else
    "expected the body not to match #{@expected_text.inspect} but #{@given_text.inspect} does match it."
  end
end
Also aliased as: negative_failure_message
matches?(email) click to toggle source
# File lib/email_spec/matchers.rb, line 287
def matches?(email)
  if @expected_text.is_a?(String)
    @given_text = email.default_part_body.to_s.gsub(/\s+/, " ")
    @expected_text = @expected_text.gsub(/\s+/, " ")
    @given_text.include?(@expected_text)
  else
    @given_text = email.default_part_body.to_s
    !!(@given_text =~ @expected_text)
  end
end
negative_failure_message()