class Shoulda::Lotus::Matchers::ValidateInclusionOfMatcher

Public Class Methods

new(attribute) click to toggle source
# File lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb, line 9
def initialize(attribute)
  @attribute = attribute
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb, line 25
def description
  "inclusion only '#{@values.inspect}' values on '#{@attribute}'"
end
failure_message() click to toggle source
# File lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb, line 29
def failure_message
  "'#{@attribute}' is include only '#{@values.inspect}'"
end
failure_message_when_negated() click to toggle source
# File lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb, line 33
def failure_message_when_negated
  "'#{@attribute}' is not include only '#{@values.inspect}'"
end
in_array(values) click to toggle source
# File lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb, line 37
def in_array(values)
  @values = values
  self
end
matches?(target) click to toggle source
# File lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb, line 13
def matches?(target)
  value = nil

  loop do
    value = SecureRandom.hex
    break unless @values.include? value
  end

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