Class: Minicrest::All
Overview
Combinator that requires all matchers 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) ⇒ All
constructor
Creates a new ALL combinator.
-
#matches?(actual) ⇒ Boolean
Checks if actual matches all matchers.
-
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
Methods inherited from Matcher
Constructor Details
#initialize(*matchers) ⇒ All
Creates a new ALL combinator.
184 185 186 187 |
# File 'lib/minicrest/combinators.rb', line 184 def initialize(*matchers) super() @matchers = matchers.flatten end |
Instance Method Details
#description ⇒ String
Returns a description of what this matcher expects.
200 201 202 |
# File 'lib/minicrest/combinators.rb', line 200 def description "all of: #{@matchers.map(&:description).join(', ')}" end |
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
208 209 210 211 212 213 214 215 216 |
# File 'lib/minicrest/combinators.rb', line 208 def (actual) failed = @matchers.reject { |m| m.matches?(actual) } <<~MSG.chomp expected #{actual.inspect} to match all of: #{@matchers.map(&:description).join("\n ")} but failed: #{failed.map { |m| m.(actual) }.join("\n ")} MSG end |
#matches?(actual) ⇒ Boolean
Checks if actual matches all matchers.
193 194 195 |
# File 'lib/minicrest/combinators.rb', line 193 def matches?(actual) @matchers.all? { |m| m.matches?(actual) } end |
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
222 223 224 225 226 227 |
# File 'lib/minicrest/combinators.rb', line 222 def (actual) <<~MSG.chomp expected #{actual.inspect} not to match all conditions, but it matched all: #{@matchers.map(&:description).join("\n ")} MSG end |