Sha256: 7e39e4096ea00226a3970a06d280317f57dc5d8af6227669f804ff50cbc21d6a

Contents?: true

Size: 597 Bytes

Versions: 2

Compression:

Stored size: 597 Bytes

Contents

module SimpleShipping
  module CustomMatchers
    class ValidatePresenceOfMatcher < BasicMatcher
      def initialize(attribute)
        @attribute = attribute.to_sym
      end
      
      def matches?(model)
        model.send("#{@attribute}=", nil)
        model.valid?
        model.errors.messages[@attribute] and
        model.errors.messages[@attribute].include? "can't be blank"
      end

      def description
        "validate presence of #{@attribute.inspect}"
      end
    end

    def validate_presence_of(attr_name)
      ValidatePresenceOfMatcher.new(attr_name)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_shipping-0.4.7 spec/support/custom_matchers/validate_presence_of_matcher.rb
simple_shipping-0.4.6 spec/support/custom_matchers/validate_presence_of_matcher.rb