Class: EmailSpec::Matchers::HaveBodyText
- Inherits:
-
Object
- Object
- EmailSpec::Matchers::HaveBodyText
- 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(text) ⇒ HaveBodyText
constructor
A new instance of HaveBodyText.
- #matches?(email) ⇒ Boolean
Constructor Details
#initialize(text) ⇒ HaveBodyText
Returns a new instance of HaveBodyText.
274 275 276 |
# File 'lib/email_spec/matchers.rb', line 274 def initialize(text) @expected_text = text end |
Instance Method Details
#description ⇒ Object
278 279 280 281 282 283 284 |
# File 'lib/email_spec/matchers.rb', line 278 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 ⇒ Object
297 298 299 300 301 302 303 |
# File 'lib/email_spec/matchers.rb', line 297 def 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 ⇒ Object Also known as: negative_failure_message
305 306 307 308 309 310 311 |
# File 'lib/email_spec/matchers.rb', line 305 def 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
286 287 288 289 290 291 292 293 294 295 |
# File 'lib/email_spec/matchers.rb', line 286 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 |