Module: SanitizeEmail::TestHelpers
- Included in:
- RspecMatchers
- Defined in:
- lib/sanitize_email/test_helpers.rb
Overview
Helpers for test-unit
Defined Under Namespace
Classes: UnexpectedMailType
Instance Method Summary collapse
-
#array_matching(matcher, part, mail_or_part) ⇒ Object
Normalize arrays to strings.
- #email_matching(matcher, part, mail_or_part) ⇒ Object
- #string_matching(matcher, part, mail_or_part) ⇒ Object
- #string_matching_attribute(matcher, part, mail_or_part) ⇒ Object
Instance Method Details
#array_matching(matcher, part, mail_or_part) ⇒ Object
Normalize arrays to strings
28 29 30 31 |
# File 'lib/sanitize_email/test_helpers.rb', line 28 def array_matching(matcher, part, mail_or_part) mail_or_part = mail_or_part.join(', ') if mail_or_part.respond_to?(:join) string_matching(matcher, part, mail_or_part) end |
#email_matching(matcher, part, mail_or_part) ⇒ Object
33 34 35 |
# File 'lib/sanitize_email/test_helpers.rb', line 33 def email_matching(matcher, part, mail_or_part) array_matching(matcher, part, mail_or_part.send(part)) end |
#string_matching(matcher, part, mail_or_part) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sanitize_email/test_helpers.rb', line 15 def string_matching(matcher, part, mail_or_part) if mail_or_part.respond_to?(:=~) # Can we match a regex against it? if matcher.is_a?(Regexp) mail_or_part =~ matcher else mail_or_part =~ Regexp.new(Regexp.escape(matcher)) end else raise UnexpectedMailType, "Cannot match #{matcher} for #{part}" end end |
#string_matching_attribute(matcher, part, mail_or_part) ⇒ Object
11 12 13 |
# File 'lib/sanitize_email/test_helpers.rb', line 11 def string_matching_attribute(matcher, part, mail_or_part) string_matching(matcher, part, mail_or_part.send(part)) end |