Class: Matchi::Matchers::BeInstanceOf::Matcher

Inherits:
Object
  • Object
show all
Includes:
MatchersBase
Defined in:
lib/matchi/rspec/be_instance_of.rb

Overview

The matcher.

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ Matcher

Initialize the matcher with an object.

Examples:

A string matcher

Matchi::BeInstanceOf.new(String)

Parameters:

  • expected (#object_id)

    An expected class.



19
20
21
# File 'lib/matchi/rspec/be_instance_of.rb', line 19

def initialize(expected)
  @expected = expected
end

Instance Method Details

#matches?Boolean

Returns Comparison between actual and expected values.

Examples:

Is it an instance of string?

be_instance_of = Matchi::BeInstanceOf.new(String)
be_instance_of.matches? { 'foo' } # => true

Yield Returns:

  • (#instance_of?)

    the actual value to compare to the expected one.

Returns:

  • (Boolean)

    Comparison between actual and expected values.



31
32
33
# File 'lib/matchi/rspec/be_instance_of.rb', line 31

def matches?
  yield.instance_of?(@expected)
end