Class: NotAMock::Stub
Overview
Instances returned by Object.stub_instance are NotAMock::Stub objects. These do their best to masquerade as the real thing.
Instance Method Summary collapse
-
#class ⇒ Object
Returns the class of the stubbed object.
-
#initialize(stubbed_class, methods = {}) ⇒ Stub
constructor
This is normall only called from Object.stub_instance.
-
#inspect ⇒ Object
Returns “Stub StubbedClass”.
-
#instance_of?(klass) ⇒ Boolean
Returns true if the class of the stubbed object is klass.
-
#is_a?(klass) ⇒ Boolean
(also: #kind_of?)
Returns true if the class of the stubbed object or one of its superclasses is klass.
Constructor Details
#initialize(stubbed_class, methods = {}) ⇒ Stub
This is normall only called from Object.stub_instance.
7 8 9 10 11 12 13 14 15 |
# File 'lib/not_a_mock/stub.rb', line 7 def initialize(stubbed_class, methods = {}) #:nodoc: @stubbed_class = stubbed_class methods.each do |method, result| self. do define_method(method) { result } end track_method(method) end end |
Instance Method Details
#class ⇒ Object
Returns the class of the stubbed object.
35 36 37 |
# File 'lib/not_a_mock/stub.rb', line 35 def class @stubbed_class end |
#inspect ⇒ Object
Returns “Stub StubbedClass”.
18 19 20 |
# File 'lib/not_a_mock/stub.rb', line 18 def inspect "Stub #{@stubbed_class.to_s}" end |
#instance_of?(klass) ⇒ Boolean
Returns true if the class of the stubbed object is klass.
30 31 32 |
# File 'lib/not_a_mock/stub.rb', line 30 def instance_of?(klass) @stubbed_class == klass end |
#is_a?(klass) ⇒ Boolean Also known as: kind_of?
Returns true if the class of the stubbed object or one of its superclasses is klass.
23 24 25 |
# File 'lib/not_a_mock/stub.rb', line 23 def is_a?(klass) @stubbed_class.ancestors.include?(klass) end |