Class: Minicrest::Some
Overview
Combinator that requires at least one matcher to succeed.
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(*matchers) ⇒ Some
constructor
Creates a new SOME 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(*matchers) ⇒ Some
Creates a new SOME combinator.
295 296 297 298 |
# File 'lib/minicrest/combinators.rb', line 295 def initialize(*matchers) super() @matchers = matchers.flatten end |
Instance Method Details
#description ⇒ String
Returns a description of what this matcher expects.
311 312 313 |
# File 'lib/minicrest/combinators.rb', line 311 def description "some of: #{@matchers.map(&:description).join(', ')}" end |
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
319 320 321 322 323 324 325 326 |
# File 'lib/minicrest/combinators.rb', line 319 def (actual) <<~MSG.chomp expected #{actual.inspect} to match at least one of: #{@matchers.map(&:description).join("\n ")} but matched none: #{@matchers.map { |m| m.(actual) }.join("\n ")} MSG end |
#matches?(actual) ⇒ Boolean
Checks if actual matches at least one matcher.
304 305 306 |
# File 'lib/minicrest/combinators.rb', line 304 def matches?(actual) @matchers.any? { |m| m.matches?(actual) } end |
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
332 333 334 335 336 337 338 |
# File 'lib/minicrest/combinators.rb', line 332 def (actual) matched = @matchers.select { |m| m.matches?(actual) } <<~MSG.chomp expected #{actual.inspect} to match none of the conditions, but matched: #{matched.map(&:description).join("\n ")} MSG end |