description()
click to toggle source
def description
"only allow #{allowed_types} values for #{@attribute}"
end
even()
click to toggle source
def even
even_number_matcher = OddEvenNumberMatcher.new(@attribute, :even => true)
add_submatcher(even_number_matcher)
self
end
failure_message_for_should()
click to toggle source
def failure_message_for_should
submatcher_failure_messages_for_should.last
end
failure_message_for_should_not()
click to toggle source
def failure_message_for_should_not
submatcher_failure_messages_for_should_not.last
end
is_equal_to(value)
click to toggle source
def is_equal_to(value)
add_submatcher(ComparisonMatcher.new(value, :==).for(@attribute))
self
end
is_greater_than(value)
click to toggle source
def is_greater_than(value)
add_submatcher(ComparisonMatcher.new(value, :>).for(@attribute))
self
end
is_greater_than_or_equal_to(value)
click to toggle source
def is_greater_than_or_equal_to(value)
add_submatcher(ComparisonMatcher.new(value, :>=).for(@attribute))
self
end
is_less_than(value)
click to toggle source
def is_less_than(value)
add_submatcher(ComparisonMatcher.new(value, :<).for(@attribute))
self
end
is_less_than_or_equal_to(value)
click to toggle source
def is_less_than_or_equal_to(value)
add_submatcher(ComparisonMatcher.new(value, :<=).for(@attribute))
self
end
matches?(subject)
click to toggle source
def matches?(subject)
@subject = subject
submatchers_match?
end
odd()
click to toggle source
def odd
odd_number_matcher = OddEvenNumberMatcher.new(@attribute, :odd => true)
add_submatcher(odd_number_matcher)
self
end
only_integer()
click to toggle source
def only_integer
add_submatcher(OnlyIntegerMatcher.new(@attribute))
self
end
with_message(message)
click to toggle source
def with_message(message)
@submatchers.each { |matcher| matcher.with_message(message) }
self
end
add_disallow_value_matcher()
click to toggle source
def add_disallow_value_matcher
disallow_value_matcher = DisallowValueMatcher.new(NON_NUMERIC_VALUE).
for(@attribute).
with_message(:not_a_number)
add_submatcher(disallow_value_matcher)
end
add_submatcher(submatcher)
click to toggle source
def add_submatcher(submatcher)
@submatchers << submatcher
end
allowed_types()
click to toggle source
def allowed_types
allowed = ['numeric'] + submatcher_allowed_types
allowed.join(', ')
end
failing_submatchers()
click to toggle source
def failing_submatchers
@failing_submatchers ||= @submatchers.select { |matcher| !matcher.matches?(@subject) }
end
submatcher_allowed_types()
click to toggle source
def submatcher_allowed_types
@submatchers.map(&:allowed_types).reject(&:empty?)
end
submatcher_failure_messages_for_should()
click to toggle source
def submatcher_failure_messages_for_should
failing_submatchers.map(&:failure_message_for_should)
end
submatcher_failure_messages_for_should_not()
click to toggle source
def submatcher_failure_messages_for_should_not
failing_submatchers.map(&:failure_message_for_should_not)
end
submatchers_match?()
click to toggle source
def submatchers_match?
failing_submatchers.empty?
end