Class: Mongoid::Matchers::Validations::ValidateLengthOfMatcher

Inherits:
HaveValidationMatcher show all
Includes:
WithMessage
Defined in:
lib/matchers/validations/length_of.rb

Instance Method Summary collapse

Methods inherited from HaveValidationMatcher

#check_on, #failure_message_for_should, #failure_message_for_should_not, #on

Constructor Details

#initialize(name) ⇒ ValidateLengthOfMatcher

Returns a new instance of ValidateLengthOfMatcher.



7
8
9
# File 'lib/matchers/validations/length_of.rb', line 7

def initialize(name)
  super(name, :length)
end

Instance Method Details

#as_exactly(value) ⇒ Object Also known as: is



29
30
31
32
# File 'lib/matchers/validations/length_of.rb', line 29

def as_exactly(value)
  @is = value
  self
end

#descriptionObject



52
53
54
55
56
57
58
59
60
# File 'lib/matchers/validations/length_of.rb', line 52

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
  options_desc << "with message '#{@expected_message}'" if @expected_message
  super << " #{options_desc.to_sentence}"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/matchers/validations/length_of.rb', line 40

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
  check_expected_message if @expected_message

  @result
end

#with_maximum(value) ⇒ Object Also known as: less_than



11
12
13
14
# File 'lib/matchers/validations/length_of.rb', line 11

def with_maximum(value)
  @maximum = value
  self
end

#with_message(message) ⇒ Object



35
36
37
38
# File 'lib/matchers/validations/length_of.rb', line 35

def with_message(message)
  @expected_message = message
  self
end

#with_minimum(value) ⇒ Object Also known as: greater_than



17
18
19
20
# File 'lib/matchers/validations/length_of.rb', line 17

def with_minimum(value)
  @minimum = value
  self
end

#within(value) ⇒ Object Also known as: in



23
24
25
26
# File 'lib/matchers/validations/length_of.rb', line 23

def within(value)
  @within = value
  self
end