Class: Minicrest::Anything

Inherits:
Matcher
  • Object
show all
Defined in:
lib/minicrest/anything.rb

Overview

Matcher that matches any value (placeholder matcher).

Use this when you want to assert the structure of data but don’t care about specific values, or when testing that something exists without caring what it is.

Examples:

Basic usage

anything.matches?(42)      # => true
anything.matches?(nil)     # => true
anything.matches?("hello") # => true

With complex structures (partial matching)

# When combined with other matchers for partial assertions
assert_that(result).matches(anything)

Instance Method Summary collapse

Methods inherited from Matcher

#&, #|

Instance Method Details

#descriptionString

Returns a description of what this matcher expects.

Returns:

  • (String)

    description



30
31
32
# File 'lib/minicrest/anything.rb', line 30

def description
  'anything'
end

#failure_message(actual) ⇒ String

Returns the failure message when the match fails.

Note: This method should never be called since anything always matches.

Parameters:

  • actual (Object)

    the value that was checked

Returns:

  • (String)

    failure message



40
41
42
43
44
# File 'lib/minicrest/anything.rb', line 40

def failure_message(actual)
  <<~MSG.chomp
    expected #{actual.inspect} to be anything (this should never fail)
  MSG
end

#matches?(_actual) ⇒ Boolean

Matches any value.

Parameters:

  • _actual (Object)

    the value to check (ignored)

Returns:

  • (Boolean)

    always true



23
24
25
# File 'lib/minicrest/anything.rb', line 23

def matches?(_actual)
  true
end

#negated_failure_message(actual) ⇒ String

Returns the failure message when a negated match fails.

This is called when does_not(anything) fails because anything matched.

Parameters:

  • actual (Object)

    the value that was checked

Returns:

  • (String)

    message indicating unexpected match



52
53
54
55
56
# File 'lib/minicrest/anything.rb', line 52

def negated_failure_message(actual)
  <<~MSG.chomp
    expected #{actual.inspect} not to be anything, but everything is something
  MSG
end