lib/matchers/validations/format.rb in mongoid-minitest-0.1.1 vs lib/matchers/validations/format.rb in mongoid-minitest-0.1.2
- old
+ new
@@ -1,24 +1,24 @@
module Mongoid
module Matchers
module Validations
class ValidateFormatMatcher < HaveValidationMatcher
- def initialize(field)
- super(field, :format)
+ def initialize field
+ super field, :format
end
- def to_allow(valid_value)
+ def to_allow valid_value
@valid = valid_value
self
end
- def to_not_allow(invalid_value)
+ def to_not_allow invalid_value
@invalid = invalid_value
self
end
- def matches?(subject)
+ def matches? subject
return false unless @result = super(subject)
check_valid_value if @valid
check_invalid_value if @invalid
@@ -33,20 +33,20 @@
end
private
def check_valid_value
- if format =~ @valid
+ if format == @valid || format =~ @valid
@positive_message << " with #{@valid.inspect} as a valid value"
else
@negative_message << " with #{@valid.inspect} as an invalid value"
@result = false
end
end
def check_invalid_value
- if !(format =~ @invalid)
+ if format !~ @invalid
@positive_message << " with #{@invalid.inspect} as a invalid value"
else
@negative_message << " with #{@invalid.inspect} as a valid value"
@result = false
end
@@ -55,11 +55,11 @@
def format
@validator.options[:with]
end
end
- def validate_format_of(field)
- ValidateFormatMatcher.new(field)
+ def validate_format_of field
+ ValidateFormatMatcher.new field
end
end
end
end