Class: Matchi::BeAnInstanceOf
- Inherits:
-
Object
- Object
- Matchi::BeAnInstanceOf
- Defined in:
- lib/matchi/be_an_instance_of.rb
Overview
Type/class matcher.
Instance Attribute Summary collapse
-
#expected ⇒ String
readonly
The expected class name.
Instance Method Summary collapse
-
#initialize(expected) ⇒ BeAnInstanceOf
constructor
Initialize the matcher with (the name of) a class or module.
-
#inspect ⇒ Object
A string containing a human-readable representation of the matcher.
-
#matches? ⇒ Boolean
Boolean comparison between the class of the actual value and the expected class.
-
#to_s ⇒ Object
Returns a string representing the matcher.
Constructor Details
#initialize(expected) ⇒ BeAnInstanceOf
Initialize the matcher with (the name of) a class or module.
17 18 19 |
# File 'lib/matchi/be_an_instance_of.rb', line 17 def initialize(expected) @expected = String(expected) end |
Instance Attribute Details
#expected ⇒ String (readonly)
Returns The expected class name.
7 8 9 |
# File 'lib/matchi/be_an_instance_of.rb', line 7 def expected @expected end |
Instance Method Details
#inspect ⇒ Object
A string containing a human-readable representation of the matcher.
40 41 42 |
# File 'lib/matchi/be_an_instance_of.rb', line 40 def inspect "#{self.class}(#{expected})" end |
#matches? ⇒ Boolean
Boolean comparison between the class of the actual value and the expected class.
35 36 37 |
# File 'lib/matchi/be_an_instance_of.rb', line 35 def matches? self.class.const_get(expected).equal?(yield.class) end |
#to_s ⇒ Object
Returns a string representing the matcher.
45 46 47 |
# File 'lib/matchi/be_an_instance_of.rb', line 45 def to_s "be an instance of #{expected}" end |