Class: Shoulda::Matchers::ActiveModel::ValidationMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveModel::ValidationMatcher
show all
- Includes:
- Qualifiers::IgnoringInterferenceByWriter
- Defined in:
- lib/shoulda/matchers/active_model/validation_matcher.rb,
lib/shoulda/matchers/active_model/validation_matcher/build_description.rb
Direct Known Subclasses
ComparisonMatcher, NumericalityMatchers::RangeMatcher, ValidateAbsenceOfMatcher, ValidateAcceptanceOfMatcher, ValidateComparisonOfMatcher, ValidateConfirmationOfMatcher, ValidateExclusionOfMatcher, ValidateInclusionOfMatcher, ValidateLengthOfMatcher, ValidateNumericalityOfMatcher, ValidatePresenceOfMatcher, Shoulda::Matchers::ActiveRecord::ValidateUniquenessOfMatcher
Defined Under Namespace
Classes: BuildDescription
Instance Attribute Summary
#ignore_interference_by_writer
Instance Method Summary
collapse
#ignoring_interference_by_writer
Constructor Details
Returns a new instance of ValidationMatcher.
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 8
def initialize(attribute)
super
@attribute = attribute
@options = {}
@expects_strict = false
@subject = nil
@last_submatcher_run = nil
@expected_message = nil
@expects_custom_validation_message = false
end
|
Instance Method Details
#allow_blank ⇒ Object
28
29
30
31
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 28
def allow_blank
options[:allow_blank] = true
self
end
|
#does_not_match?(subject) ⇒ Boolean
60
61
62
63
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 60
def does_not_match?(subject)
@subject = subject
true
end
|
#expects_custom_validation_message? ⇒ Boolean
51
52
53
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 51
def expects_custom_validation_message?
@expects_custom_validation_message
end
|
#expects_strict? ⇒ Boolean
38
39
40
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 38
def expects_strict?
@expects_strict
end
|
#failure_message ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 65
def failure_message
overall_failure_message.dup.tap do |message|
if failure_reason.present?
message << "\n"
message << Shoulda::Matchers.word_wrap(
failure_reason,
indent: 2,
)
end
end
end
|
#failure_message_when_negated ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 77
def failure_message_when_negated
overall_failure_message_when_negated.dup.tap do |message|
if failure_reason.present?
message << "\n"
message << Shoulda::Matchers.word_wrap(
failure_reason,
indent: 2,
)
end
end
end
|
#failure_reason ⇒ Object
89
90
91
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 89
def failure_reason
last_submatcher_run.try(:failure_message)
end
|
#matches?(subject) ⇒ Boolean
55
56
57
58
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 55
def matches?(subject)
@subject = subject
false
end
|
#on(context) ⇒ Object
23
24
25
26
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 23
def on(context)
@context = context
self
end
|
#strict ⇒ Object
33
34
35
36
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 33
def strict
@expects_strict = true
self
end
|
#with_message(expected_message) ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 42
def with_message(expected_message)
if expected_message
@expects_custom_validation_message = true
@expected_message = expected_message
end
self
end
|