Class: MiniTest::Matchers::ActiveModel::ValidationMatcher
- Inherits:
-
Object
- Object
- MiniTest::Matchers::ActiveModel::ValidationMatcher
- Includes:
- Helpers
- Defined in:
- lib/matchers/validation_matcher.rb
Overview
:nodoc:
Direct Known Subclasses
ValidateAcceptanceMatcher, ValidateAssociated, ValidateExclusionMatcher, ValidateFormatMatcher, ValidateInclusionMatcher, ValidateLengthMatcher, ValidateUniquenessMatcher
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(attr, type) ⇒ ValidationMatcher
constructor
A new instance of ValidationMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
-
#on(*contexts) ⇒ Object
TODO: Add documentation.
-
#with_message(expected_message) ⇒ Object
TODO: Add documentation.
Methods included from Helpers
Constructor Details
#initialize(attr, type) ⇒ ValidationMatcher
Returns a new instance of ValidationMatcher.
7 8 9 10 11 |
# File 'lib/matchers/validation_matcher.rb', line 7 def initialize attr, type @attr = attr @type = type @expected_on = @expected_message = nil end |
Instance Method Details
#description ⇒ Object
45 46 47 |
# File 'lib/matchers/validation_matcher.rb', line 45 def description "validate #{@type} of #{@attr}" end |
#failure_message ⇒ Object
37 38 39 |
# File 'lib/matchers/validation_matcher.rb', line 37 def "Expected #{@klass} to #{description}; instead got #{@negative_message}" end |
#matches?(subject) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/matchers/validation_matcher.rb', line 25 def matches? subject @klass = subject.is_a?(Class) ? subject : subject.class @validator = @klass.validators_on(@attr).find { |v| v.kind == @type } @result = true check_validator check_on if @expected_on if @expected_message @result end |
#negative_failure_message ⇒ Object
41 42 43 |
# File 'lib/matchers/validation_matcher.rb', line 41 def "Expected #{@klass} to not #{description}; instead got #{@positive_message}" end |
#on(*contexts) ⇒ Object
TODO: Add documentation.
14 15 16 17 |
# File 'lib/matchers/validation_matcher.rb', line 14 def on *contexts @expected_on = clean_contexts contexts self end |
#with_message(expected_message) ⇒ Object
TODO: Add documentation.
20 21 22 23 |
# File 'lib/matchers/validation_matcher.rb', line 20 def @expected_message = self end |