Class: Quickie::Stub

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

Instance Method Summary collapse

Constructor Details

#initialize(object, method, options = {}) ⇒ Stub

To set up a stub with optional return value:

obj.stub(:method, :return => something)

To remove existing stub and restore original method:

obj.stub(:method, :remove)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/quickie/stub.rb', line 16

def initialize(object, method, options = {})
  options = { options => true } if options.is_a?(Symbol)
  @object, @options = object, options
  @@stash ||= []
  #
  # Create a new stub by intercepting the method or remove existing stub
  # by restoring the original method.
  #
  unless @options[:remove]
    intercept(method)
  else
    restore(method)
  end
end