Class: Remarkable::ActiveRecord::Matchers::ValidateLengthOfMatcher

Inherits:
Matcher::Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb

Instance Method Summary collapse

Methods included from Helpers

#allow_blank, #allow_nil

Methods included from Default::Helpers

#assert_contains, #assert_does_not_contain

Methods inherited from Matcher::Base

#negative, #spec

Methods included from Matcher::DSL

included, #matches?

Instance Method Details

#descriptionObject



39
40
41
# File 'lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb', line 39

def description
  "ensure #{expectation}"
end

#failure_messageObject



43
44
45
# File 'lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb', line 43

def failure_message
  "Expected #{expectation} (#{@missing})"
end

#is(value) ⇒ Object



33
34
35
36
37
# File 'lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb', line 33

def is(value)
  @options[:minimum] = value
  @options[:maximum] = value
  self
end

#message(message) ⇒ Object

If message is supplied, reassign it properly to :short_message and :long_message. This is ActiveRecord default behavior when the validation is :maximum, :minimum or :is.



17
18
19
20
21
22
23
# File 'lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb', line 17

def message(message)
  if [:is, :minimum, :maximum].include? @behavior
    short_message(message)
    long_message(message)
  end
  self
end

#negative_failure_messageObject



47
48
49
# File 'lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb', line 47

def negative_failure_message
  "Did not expect #{expectation}"
end

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



25
26
27
28
29
30
# File 'lib/remarkable/active_record/macros/validations/validate_length_of_matcher.rb', line 25

def within(range)
  @behavior = :within
  @options[:minimum] = range.first
  @options[:maximum] = range.last
  self
end