Class: Matchi::Be

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

Overview

Identity matcher.

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ Be

Initialize the matcher with an object.

Examples:

require "matchi/be"

Matchi::Be.new(:foo)

Parameters:

  • expected (#equal?)

    The expected identical object.



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

def initialize(expected)
  @expected = expected
end

Instance Method Details

#match?Boolean

Boolean comparison between the actual value and the expected value.

Examples:

require "matchi/be"

matcher = Matchi::Be.new(:foo)
matcher.match? { :foo } # => true

Yield Returns:

  • (#object_id)

    The actual value to compare to the expected one.

Returns:

  • (Boolean)

    Comparison between actual and expected values.

Raises:

  • (::ArgumentError)


30
31
32
33
34
# File 'lib/matchi/be.rb', line 30

def match?
  raise ::ArgumentError, "a block must be provided" unless block_given?

  @expected.equal?(yield)
end

#to_sString

Returns a string representing the matcher.

Returns:

  • (String)

    a human-readable description of the matcher



39
40
41
# File 'lib/matchi/be.rb', line 39

def to_s
  "be #{@expected.inspect}"
end