Sha256: ebf3936813ccb6d8e5eaf40cecbc962d43b1f40e084f4fc67175e329a8e8b697

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

# Copyright (c) 2008-13 Peter H. Boling of RailsBling.com
# Released under the MIT license
module SanitizeEmail
  module TestHelpers
    class UnexpectedMailType < StandardError; end

    def string_matching_attribute(matcher, part, mail_or_part)
      string_matching(matcher, part, mail_or_part.send(part))
    end

    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

    # Normalize arrays to strings
    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

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

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sanitize_email-1.1.6 lib/sanitize_email/test_helpers.rb
sanitize_email-1.1.5 lib/sanitize_email/test_helpers.rb
sanitize_email-1.1.4 lib/sanitize_email/test_helpers.rb
sanitize_email-1.1.3 lib/sanitize_email/test_helpers.rb
sanitize_email-1.1.2 lib/sanitize_email/test_helpers.rb
sanitize_email-1.1.1 lib/sanitize_email/test_helpers.rb