Class: NotAMock::Stub

Inherits:
Object show all
Defined in:
lib/not_a_mock/stub.rb

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

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.meta_eval do
      define_method(method) { result }
    end
    track_method(method)
  end
end

Instance Method Details

#classObject

Returns the class of the stubbed object.



35
36
37
# File 'lib/not_a_mock/stub.rb', line 35

def class
  @stubbed_class
end

#inspectObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


23
24
25
# File 'lib/not_a_mock/stub.rb', line 23

def is_a?(klass)
  @stubbed_class.ancestors.include?(klass)
end