class Matchi::BeAnInstanceOf
Type/class matcher.
Attributes
expected[R]
@return [String] The expected class name.
Public Class Methods
new(expected)
click to toggle source
Initialize the matcher with (the name of) a class or module.
@example
require "matchi/be_an_instance_of" Matchi::BeAnInstanceOf.new(String)
@param expected [Class, to_s
] The expected class name.
# File lib/matchi/be_an_instance_of.rb, line 17 def initialize(expected) @expected = String(expected) end
Public Instance Methods
inspect()
click to toggle source
A string containing a human-readable representation of the matcher.
# File lib/matchi/be_an_instance_of.rb, line 40 def inspect "#{self.class}(#{expected})" end
matches?() { || ... }
click to toggle source
Boolean comparison between the class of the actual value and the expected class.
@example
require "matchi/be_an_instance_of" matcher = Matchi::BeAnInstanceOf.new(String) matcher.expected # => "String" matcher.matches? { "foo" } # => true
@yieldreturn [#class] the actual value to compare to the expected one.
@return [Boolean] Comparison between actual and expected values.
# File lib/matchi/be_an_instance_of.rb, line 35 def matches? self.class.const_get(expected).equal?(yield.class) end
to_s()
click to toggle source
Returns a string representing the matcher.
# File lib/matchi/be_an_instance_of.rb, line 45 def to_s "be an instance of #{expected}" end