Class: Minicrest::Or
Overview
Combinator that requires at least one matcher to succeed (logical OR).
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) ⇒ Or
constructor
Creates a new OR combinator.
-
#matches?(actual) ⇒ Boolean
Checks if actual matches at least one matcher.
-
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
Methods inherited from Matcher
Constructor Details
#initialize(left, right) ⇒ Or
Creates a new OR combinator.
123 124 125 126 127 |
# File 'lib/minicrest/combinators.rb', line 123 def initialize(left, right) super() @left = left @right = right end |
Instance Method Details
#description ⇒ String
Returns a description of what this matcher expects.
140 141 142 |
# File 'lib/minicrest/combinators.rb', line 140 def description "(#{@left.description} or #{@right.description})" end |
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/minicrest/combinators.rb', line 148 def (actual) <<~MSG.chomp expected #{actual.inspect} to match at least one of: #{@left.description} #{@right.description} but it matched neither: #{@left.(actual)} #{@right.(actual)} MSG end |
#matches?(actual) ⇒ Boolean
Checks if actual matches at least one matcher.
133 134 135 |
# File 'lib/minicrest/combinators.rb', line 133 def matches?(actual) @left.matches?(actual) || @right.matches?(actual) end |
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/minicrest/combinators.rb', line 163 def (actual) matched = [] matched << @left.description if @left.matches?(actual) matched << @right.description if @right.matches?(actual) <<~MSG.chomp expected #{actual.inspect} not to match either condition, but it matched: #{matched.join("\n ")} MSG end |