Sha256: b0adecb24801a489c4c9f5b0985dc2350db505f82752bd682c52a840460d1960

Contents?: true

Size: 876 Bytes

Versions: 1

Compression:

Stored size: 876 Bytes

Contents

module PostcodeAnywhere
  module Matchers
    RSpec::Matchers.define :validate_email_with_postcode_anywhere do
      chain :on_attribute do |attribute|
        @attribute = attribute
      end

      match do |model|
        model_validators = model.class.validators_on(attribute)
        model_validators.any? { |validator| validator.instance_of?(PostcodeAnywhere::EmailValidation::Validator) }
      end

      def attribute
        @attribute || :email
      end

      failure_message_for_should do |model|
        failure_message(model, 'should')
      end

      failure_message_for_should_not do |model|
        failure_message(model, 'snould not')
      end

      def failure_message(model, should_or_should_not)
        "#{model.class} #{should_or_should_not} have 'PostcodeAnywhere::EmailValidation::Validator' on attribute #{attribute}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
postcode_anywhere-email_validation-0.0.4 lib/postcode_anywhere/matchers/email_validator.rb