Sha256: 0e91343fe6ed37b0f5180d2f681f7350ad90f07fa566a6fd4e580034be6126e2
Contents?: true
Size: 1.21 KB
Versions: 1
Compression:
Stored size: 1.21 KB
Contents
module DataMapper module Matchers def validate_format_of(property) ValidateFormatOf.new(property) end class ValidateFormatOf < ValidationMatcher set_validation_subject "format" def with(format) @format = format self end def matches?(model) model_class = model.is_a?(Class) ? model : model.class validators = model_class.validators.contexts[:default] format_of = validators.find do |validator| validator.is_a? DataMapper::Validations::FormatValidator and validator.field_name == @property end return false unless format_of return false unless format_of.options[:with] == @format return false if @msg and @msg != format_of.options[:message] true end def failure_message msg = "expected to validate #{@validation_subject} of #{@property} with #{@format.inspect}" msg = %Q'#{msg} and message "#{@msg}"' if @msg msg end def failure_message_when_negated msg = "expected to not validate #{@validation_subject} of #{@property} with #{@format.inspect}" msg = %Q'#{msg} and message "#{@msg}"' if @msg msg end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dm-rspec-0.3.0 | lib/dm/matchers/validate_format_of.rb |