Small refactor in numericality matcher

This commit is contained in:
Elliot Winkler 2015-12-27 00:37:15 -05:00
parent 45697b5655
commit 8bc8083d77
1 changed files with 8 additions and 11 deletions

View File

@ -503,16 +503,13 @@ module Shoulda
def prepare_submatcher(submatcher)
add_submatcher(submatcher)
if submatcher.respond_to?(:diff_to_compare)
update_diff_to_compare(submatcher)
end
submatcher
end
def comparison_matcher_for(value, operator)
NumericalityMatchers::ComparisonMatcher
.new(self, value, operator)
.for(@attribute)
NumericalityMatchers::ComparisonMatcher.
new(self, value, operator).
for(@attribute)
end
def add_submatcher(submatcher)
@ -524,6 +521,10 @@ module Shoulda
@allowed_type_adjective = submatcher.allowed_type_adjective
end
if submatcher.respond_to?(:diff_to_compare)
@diff_to_compare = [@diff_to_compare, submatcher.diff_to_compare].max
end
@submatchers << submatcher
end
@ -557,10 +558,6 @@ module Shoulda
end
end
def update_diff_to_compare(matcher)
@diff_to_compare = [@diff_to_compare, matcher.diff_to_compare].max
end
def first_failing_submatcher
@_failing_submatchers ||= @submatchers.detect do |submatcher|
!submatcher.matches?(@subject)