Class: Shoulda::Lotus::Matchers::ValidateInclusionOfMatcher
- Inherits:
-
Object
- Object
- Shoulda::Lotus::Matchers::ValidateInclusionOfMatcher
- Defined in:
- lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #in_array(values) ⇒ Object
-
#initialize(attribute) ⇒ ValidateInclusionOfMatcher
constructor
A new instance of ValidateInclusionOfMatcher.
- #matches?(target) ⇒ Boolean
Constructor Details
#initialize(attribute) ⇒ ValidateInclusionOfMatcher
9 10 11 |
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 9 def initialize(attribute) @attribute = attribute end |
Instance Method Details
#description ⇒ Object
25 26 27 |
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 25 def description "inclusion only '#{@values.inspect}' values on '#{@attribute}'" end |
#failure_message ⇒ Object
29 30 31 |
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 29 def "'#{@attribute}' is include only '#{@values.inspect}'" end |
#failure_message_when_negated ⇒ Object
33 34 35 |
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 33 def "'#{@attribute}' is not include only '#{@values.inspect}'" end |
#in_array(values) ⇒ Object
37 38 39 40 |
# File 'lib/shoulda/lotus/matchers/validate_inclusion_of_matcher.rb', line 37 def in_array(values) @values = values self end |
#matches?(target) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 |
# 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 |