class NoBrainer::Matchers::Validations::ValidateLengthOfMatcher
Public Class Methods
new(name)
click to toggle source
Calls superclass method
NoBrainer::Matchers::Validations::HaveValidationMatcher::new
# File lib/matchers/validations/length_of.rb, line 7 def initialize(name) super(name, :length) end
Public Instance Methods
as_exactly(value)
click to toggle source
# File lib/matchers/validations/length_of.rb, line 29 def as_exactly(value) @is = value self end
Also aliased as: is
description()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 46 def description options_desc = [] options_desc << "with minimum of #{@minimum}" if @minimum options_desc << "with maximum of #{@maximum}" if @maximum options_desc << "within the range of #{@within}" if @within options_desc << "as exactly #{@is}" if @is "#{super} #{options_desc.to_sentence}" end
matches?(actual)
click to toggle source
Calls superclass method
NoBrainer::Matchers::Validations::HaveValidationMatcher#matches?
# File lib/matchers/validations/length_of.rb, line 35 def matches?(actual) return false unless @result = super(actual) check_maximum if @maximum check_minimum if @minimum check_range if @within check_exact if @is @result end
with_maximum(value)
click to toggle source
# File lib/matchers/validations/length_of.rb, line 11 def with_maximum(value) @maximum = value self end
Also aliased as: less_than
with_minimum(value)
click to toggle source
# File lib/matchers/validations/length_of.rb, line 17 def with_minimum(value) @minimum = value self end
Also aliased as: greater_than
within(value)
click to toggle source
# File lib/matchers/validations/length_of.rb, line 23 def within(value) @within = value self end
Also aliased as: in
Private Instance Methods
actual_is()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 109 def actual_is actual_is = @validator.options[:is] end
actual_max()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 117 def actual_max @validator.options[:maximum] || (@validator.options[:in] || @validator.options[:within]).try(&:max) end
actual_min()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 113 def actual_min @validator.options[:minimum] || (@validator.options[:in] || @validator.options[:within]).try(&:min) end
check_exact()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 100 def check_exact if actual_is == @is @positive_result_message += " as exactly #{@is}" else @negative_result_message += " as exactly #{actual_is}" @result = false end end
check_maximum()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 57 def check_maximum if actual_max.nil? @negative_result_message += ' with no maximum' @result = false elsif actual_max == @maximum @positive_result_message += " with maximum of #{@maximum}" else @negative_result_message += " with maximum of #{actual_max}" @result = false end end
check_minimum()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 69 def check_minimum if actual_min.nil? @negative_result_message += ' with no minimum' @result = false elsif actual_min == @minimum @positive_result_message += " with minimum of #{@minimum}" else @negative_result_message += " with minimum of #{actual_min}" @result = false end end
check_range()
click to toggle source
# File lib/matchers/validations/length_of.rb, line 81 def check_range min, max = @within.minmax if !actual_min.nil? && actual_max.nil? @negative_result_message += " with no minimum but with maximum of #{actual_max}" @result = false elsif actual_min.nil? && !actual_max.nil? @negative_result_message += " with minimum_of #{actual_min} but no maximum" @result = false elsif actual_min.nil? && actual_max.nil? @negative_result_message += ' with no minimum and maximum' @result = false elsif actual_min == min && actual_max == max @positive_result_message += " within the range of #{@within.inspect}" else @negative_result_message += " within the range of #{(actual_min..actual_max).inspect}" @result = false end end