Class: RSpec::ValidatesTimeliness::Matchers::ValidationMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-validates_timeliness/matchers/validation_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr_name) ⇒ ValidationMatcher

Returns a new instance of ValidationMatcher.



14
15
16
17
18
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 14

def initialize(attr_name)
  @attr_name = attr_name
  @options = {}
  @description = MessageBuilder.new(base_description)
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



12
13
14
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 12

def description
  @description
end

Instance Method Details

#after(value = nil, &block) ⇒ Object



25
26
27
28
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 25

def after(value = nil, &block)
  options[__method__] = block_given? ? block : value
  self
end

#before(value = nil, &block) ⇒ Object



35
36
37
38
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 35

def before(value = nil, &block)
  options[__method__] = block_given? ? block : value
  self
end

#between(value) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 45

def between(value)
  case value
  when Array, Range
    options[:on_or_after] = value.first
    options[value.is_a?(Range) && value.exclude_end? ? :before : :on_or_before] = value.last
  end

  self
end

#failure_messageObject



61
62
63
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 61

def failure_message
  "Expected #{description}"
end

#failure_message_when_negatedObject



65
66
67
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 65

def failure_message_when_negated
  "Did not expect #{description}"
end

#is_at(value = nil, &block) ⇒ Object



20
21
22
23
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 20

def is_at(value = nil, &block)
  options[__method__] = block_given? ? block : value
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 55

def matches?(subject)
  @subject = subject

  attribute_exist? && all_options_correct?
end

#on_or_after(value = nil, &block) ⇒ Object



30
31
32
33
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 30

def on_or_after(value = nil, &block)
  options[__method__] = block_given? ? block : value
  self
end

#on_or_before(value = nil, &block) ⇒ Object



40
41
42
43
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 40

def on_or_before(value = nil, &block)
  options[__method__] = block_given? ? block : value
  self
end