Class: Matchi::Eq

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

Overview

Equivalence matcher.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ Eq

Initialize the matcher with an object.

Examples:

require "matchi/eq"

Matchi::Eq.new("foo")

Parameters:

  • expected (#eql?)

    An expected equivalent object.



17
18
19
# File 'lib/matchi/eq.rb', line 17

def initialize(expected)
  @expected = expected
end

Instance Attribute Details

#expected#eql? (readonly)

Returns An expected equivalent object.

Returns:

  • (#eql?)

    An expected equivalent object.



7
8
9
# File 'lib/matchi/eq.rb', line 7

def expected
  @expected
end

Instance Method Details

#inspectObject

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



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

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

#matches?Boolean

Boolean comparison between the actual value and the expected value.

Examples:

require "matchi/eq"

matcher = Matchi::Eq.new("foo")

matcher.expected           # => "foo"
matcher.matches? { "foo" } # => true

Yield Returns:

  • (#object_id)

    The actual value to compare to the expected one.

Returns:

  • (Boolean)

    Comparison between actual and expected values.



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

def matches?
  expected.eql?(yield)
end

#to_sObject

Returns a string representing the matcher.



45
46
47
# File 'lib/matchi/eq.rb', line 45

def to_s
  "eq #{expected.inspect}"
end