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.



257
258
259
# File 'lib/email_spec/matchers.rb', line 257

def initialize(text)
  @expected_text = text
end

Instance Method Details

#descriptionObject



261
262
263
264
265
266
267
# File 'lib/email_spec/matchers.rb', line 261

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



280
281
282
283
284
285
286
# File 'lib/email_spec/matchers.rb', line 280

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

#matches?(email) ⇒ Boolean

Returns:

  • (Boolean)


269
270
271
272
273
274
275
276
277
278
# File 'lib/email_spec/matchers.rb', line 269

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_messageObject



288
289
290
291
292
293
294
# File 'lib/email_spec/matchers.rb', line 288

def negative_failure_message
  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