Class: Matchi::Matcher::BeAnInstanceOf

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

Overview

Type/class matcher.

Instance Attribute Summary

Attributes inherited from Base

#expected

Instance Method Summary collapse

Methods inherited from Base

#inspect, #to_s, to_sym

Constructor Details

#initialize(expected) ⇒ BeAnInstanceOf

Initialize the matcher with an object.

Examples:

A string matcher

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

Parameters:

  • expected (Class)

    An expected class.



15
16
17
18
# File 'lib/matchi/matcher/be_an_instance_of.rb', line 15

def initialize(expected)
  super()
  @expected = expected
end

Instance Method Details

#matches?Boolean

Boolean comparison between the class of the actual value and the expected class.

Examples:

Is it an instance of string?

be_an_instance_of = Matchi::Matcher::BeInstanceOf.new(String)
be_an_instance_of.matches? { "foo" } # => true

Yield Returns:

  • (#class)

    the actual value to compare to the expected one.

Returns:

  • (Boolean)

    Comparison between actual and expected values.



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

def matches?(*, **)
  expected.equal?(yield.class)
end