Class: Matchi::Satisfy

Inherits:
Object
  • Object
show all
Defined in:
lib/matchi/satisfy.rb

Overview

Satisfy matcher.

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Satisfy

Initialize the matcher with a block.

Examples:

require "matchi/satisfy"

Matchi::Satisfy.new { |value| value == 42 }

Parameters:

  • block (Proc)

    A block of code.



14
15
16
# File 'lib/matchi/satisfy.rb', line 14

def initialize(&block)
  @expected = block
end

Instance Method Details

#inspectObject

A string containing a human-readable representation of the matcher.



35
36
37
# File 'lib/matchi/satisfy.rb', line 35

def inspect
  "#{self.class}(&block)"
end

#matches?Boolean

Boolean comparison between the actual value and the expected value.

Examples:

require "matchi/satisfy"

matcher = Matchi::Satisfy.new { |value| value == 42 }
matcher.matches? { 42 } # => true

Yield Returns:

  • (#object_id)

    The actual value to compare to the expected one.

Returns:

  • (Boolean)

    Comparison between actual and expected values.



30
31
32
# File 'lib/matchi/satisfy.rb', line 30

def matches?(*, **)
  @expected.call(yield)
end

#to_sObject

Returns a string representing the matcher.



40
41
42
# File 'lib/matchi/satisfy.rb', line 40

def to_s
  "satisfy &block"
end