Class: Minicrest::None
Overview
Combinator that requires none of the 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) ⇒ None
constructor
Creates a new NONE combinator.
-
#matches?(actual) ⇒ Boolean
Checks if actual matches none of the matchers.
-
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
Methods inherited from Matcher
Constructor Details
#initialize(*matchers) ⇒ None
Creates a new NONE combinator.
239 240 241 242 |
# File 'lib/minicrest/combinators.rb', line 239 def initialize(*matchers) super() @matchers = matchers.flatten end |
Instance Method Details
#description ⇒ String
Returns a description of what this matcher expects.
255 256 257 |
# File 'lib/minicrest/combinators.rb', line 255 def description "none of: #{@matchers.map(&:description).join(', ')}" end |
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
263 264 265 266 267 268 269 270 271 |
# File 'lib/minicrest/combinators.rb', line 263 def (actual) matched = @matchers.select { |m| m.matches?(actual) } <<~MSG.chomp expected #{actual.inspect} to match none of: #{@matchers.map(&:description).join("\n ")} but matched: #{matched.map(&:description).join("\n ")} MSG end |
#matches?(actual) ⇒ Boolean
Checks if actual matches none of the matchers.
248 249 250 |
# File 'lib/minicrest/combinators.rb', line 248 def matches?(actual) @matchers.none? { |m| m.matches?(actual) } end |
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
277 278 279 280 281 282 283 |
# File 'lib/minicrest/combinators.rb', line 277 def (actual) <<~MSG.chomp expected #{actual.inspect} to match at least one of: #{@matchers.map(&:description).join("\n ")} but matched none MSG end |