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.



6
7
8
9
10
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 6

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.



4
5
6
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 4

def description
  @description
end

Instance Method Details

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



17
18
19
20
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 17

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

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



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

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

#between(value) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 37

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



53
54
55
# File 'lib/rspec-validates_timeliness/matchers/validation_matcher.rb', line 53

def failure_message
  "Expected #{description}"
end

#failure_message_when_negatedObject



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

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

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



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

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(subject)
  @subject = subject

  attribute_exist? && all_options_correct?
end

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



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

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

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



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

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