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.
275 276 277 |
# File 'lib/email_spec/matchers.rb', line 275 def initialize(text) @expected_text = text end |
Instance Method Details
#description ⇒ Object
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_message ⇒ Object
298 299 300 301 302 303 304 |
# File 'lib/email_spec/matchers.rb', line 298 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
306 307 308 309 310 311 312 |
# File 'lib/email_spec/matchers.rb', line 306 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
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 |