Class: Shoulda::Lotus::Matchers::AllowValueMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/lotus/matchers/allow_value_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ AllowValueMatcher



9
10
11
# File 'lib/shoulda/lotus/matchers/allow_value_matcher.rb', line 9

def initialize(value)
  @value = value
end

Instance Method Details

#descriptionObject



18
19
20
# File 'lib/shoulda/lotus/matchers/allow_value_matcher.rb', line 18

def description
  "allow '#{@value}' to be set to '#{@attribute}'"
end

#failure_messageObject



22
23
24
# File 'lib/shoulda/lotus/matchers/allow_value_matcher.rb', line 22

def failure_message
  "'#{@value}' is an invalid format for '#{@attribute}'"
end

#failure_message_when_negatedObject



26
27
28
# File 'lib/shoulda/lotus/matchers/allow_value_matcher.rb', line 26

def failure_message_when_negated
  "'#{@value}' is a valid format for '#{@attribute}'"
end

#for(attribute) ⇒ Object



30
31
32
33
# File 'lib/shoulda/lotus/matchers/allow_value_matcher.rb', line 30

def for(attribute)
  @attribute = attribute
  self
end

#matches?(target) ⇒ Boolean



13
14
15
16
# File 'lib/shoulda/lotus/matchers/allow_value_matcher.rb', line 13

def matches?(target)
  target.send("#{@attribute}=", @value)
  !Matcher.new(target, @attribute, :format).matches?
end