Module: SanitizeEmail::TestHelpers

Defined in:
lib/sanitize_email/test_helpers.rb

Overview

Helpers for test-unit

Defined Under Namespace

Classes: UnexpectedMailType

Instance Method Summary collapse

Instance Method Details

#array_matching(matcher, part, attribute) ⇒ Object

Normalize arrays to strings


29
30
31
32
# File 'lib/sanitize_email/test_helpers.rb', line 29

def array_matching(matcher, part, attribute)
  attribute = attribute.join(', ') if attribute.respond_to?(:join)
  string_matching(matcher, part, attribute)
end

#email_attribute_matching(matcher, part, attribute) ⇒ Object


38
39
40
# File 'lib/sanitize_email/test_helpers.rb', line 38

def email_attribute_matching(matcher, part, attribute)
  array_matching(matcher, part, attribute)
end

#email_matching(matcher, part, mail_or_part) ⇒ Object


34
35
36
# File 'lib/sanitize_email/test_helpers.rb', line 34

def email_matching(matcher, part, mail_or_part)
  email_attribute_matching(matcher, part, mail_or_part.send(part))
end

#string_matching(matcher, part, attribute) ⇒ Object

Raises:


18
19
20
21
22
23
24
25
26
# File 'lib/sanitize_email/test_helpers.rb', line 18

def string_matching(matcher, part, attribute)
  # Can we match a regex against it?
  raise UnexpectedMailType, "Cannot match #{matcher} for #{part}" unless attribute.respond_to?(:=~)
  attribute =~ if matcher.is_a?(Regexp)
                 matcher
               else
                 Regexp.new(Regexp.escape(matcher))
               end
end

#string_matching_attribute(matcher, part, attribute) ⇒ Object


14
15
16
# File 'lib/sanitize_email/test_helpers.rb', line 14

def string_matching_attribute(matcher, part, attribute)
  string_matching(matcher, part, attribute)
end