Class: Matchi::Matcher::BeInstanceOf

Inherits:
Base
  • Object
show all
Defined in:
lib/matchi/matcher/be_instance_of.rb

Overview

Type/class matcher.

Direct Known Subclasses

BeAnInstanceOf

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ BeInstanceOf

Initialize the matcher with an object.

Examples:

A string matcher

Matchi::Matcher::BeInstanceOf.new(String)

Parameters:

  • expected (#object_id)

    An expected class.



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

def initialize(expected)
  @expected = expected
end

Instance Method Details

#matches?Boolean

TODO:

For security reasons, instead of comparing actual with expected, we should compare expected with actual. Using something such as: ‘expected.class_of?(actual)`.

Returns Comparison between actual and expected values.

Examples:

Is it an instance of string?

be_instance_of = Matchi::Matcher::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.



33
34
35
# File 'lib/matchi/matcher/be_instance_of.rb', line 33

def matches?
  yield.instance_of?(expected)
end