Class: EmailSpec::Matchers::HaveBodyText

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

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ HaveBodyText

Returns a new instance of HaveBodyText.



275
276
277
# File 'lib/email_spec/matchers.rb', line 275

def initialize(text)
  @expected_text = text
end

Instance Method Details

#descriptionObject



279
280
281
282
283
284
285
# 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_messageObject



298
299
300
301
302
303
304
# 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_negatedObject Also known as: negative_failure_message



306
307
308
309
310
311
312
# 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

#matches?(email) ⇒ Boolean

Returns:

  • (Boolean)


287
288
289
290
291
292
293
294
295
296
# 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