Class: Minicrest::Not
Overview
Combinator that negates a matcher’s result.
Wraps another matcher and inverts its matching logic. When the wrapped matcher succeeds, Not fails, and vice versa.
Instance Method Summary collapse
-
#description ⇒ String
Returns a description of what this matcher expects.
-
#failure_message(actual) ⇒ String
Returns the failure message when the negated match fails.
-
#initialize(matcher) ⇒ Not
constructor
Creates a new negating matcher.
-
#matches?(actual) ⇒ Boolean
Checks if actual does NOT match the wrapped matcher.
-
#negated_failure_message(actual) ⇒ String
Returns the failure message when a double-negated match fails.
Methods inherited from Matcher
Constructor Details
#initialize(matcher) ⇒ Not
Creates a new negating matcher.
16 17 18 19 |
# File 'lib/minicrest/combinators.rb', line 16 def initialize(matcher) super() @matcher = matcher end |
Instance Method Details
#description ⇒ String
Returns a description of what this matcher expects.
32 33 34 |
# File 'lib/minicrest/combinators.rb', line 32 def description "not #{@matcher.description}" end |
#failure_message(actual) ⇒ String
Returns the failure message when the negated match fails.
This happens when the wrapped matcher succeeds (but we wanted it to fail).
42 43 44 |
# File 'lib/minicrest/combinators.rb', line 42 def (actual) @matcher.(actual) end |
#matches?(actual) ⇒ Boolean
Checks if actual does NOT match the wrapped matcher.
25 26 27 |
# File 'lib/minicrest/combinators.rb', line 25 def matches?(actual) !@matcher.matches?(actual) end |
#negated_failure_message(actual) ⇒ String
Returns the failure message when a double-negated match fails.
This happens when not(not(matcher)) is used and the inner matcher fails.
52 53 54 |
# File 'lib/minicrest/combinators.rb', line 52 def (actual) @matcher.(actual) end |