Class: Minicrest::And
Overview
Combinator that requires both matchers to succeed (logical AND).
Instance Method Summary collapse
-
#description ⇒ String
Returns a description of what this matcher expects.
-
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
-
#initialize(left, right) ⇒ And
constructor
Creates a new AND combinator.
-
#matches?(actual) ⇒ Boolean
Checks if actual matches both matchers.
-
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
Methods inherited from Matcher
Constructor Details
#initialize(left, right) ⇒ And
Creates a new AND combinator.
67 68 69 70 71 |
# File 'lib/minicrest/combinators.rb', line 67 def initialize(left, right) super() @left = left @right = right end |
Instance Method Details
#description ⇒ String
Returns a description of what this matcher expects.
84 85 86 |
# File 'lib/minicrest/combinators.rb', line 84 def description "(#{@left.description} and #{@right.description})" end |
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
92 93 94 95 96 97 |
# File 'lib/minicrest/combinators.rb', line 92 def (actual) = [] << @left.(actual) unless @left.matches?(actual) << @right.(actual) unless @right.matches?(actual) .join("\n AND\n") end |
#matches?(actual) ⇒ Boolean
Checks if actual matches both matchers.
77 78 79 |
# File 'lib/minicrest/combinators.rb', line 77 def matches?(actual) @left.matches?(actual) && @right.matches?(actual) end |
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
103 104 105 106 107 108 109 110 |
# File 'lib/minicrest/combinators.rb', line 103 def (actual) <<~MSG.chomp expected #{actual.inspect} not to match both conditions: #{@left.description} #{@right.description} but it matched both MSG end |