Class: ActiveSupport::Testing::SimpleStubs

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/testing/time_helpers.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Stub

Instance Method Summary collapse

Constructor Details

#initializeSimpleStubs

Returns a new instance of SimpleStubs.



8
9
10
# File 'lib/active_support/testing/time_helpers.rb', line 8

def initialize
  @stubs = {}
end

Instance Method Details

#stub_object(object, method_name, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/active_support/testing/time_helpers.rb', line 12

def stub_object(object, method_name, &block)
  key = [object.object_id, method_name]

  if stub = @stubs[key]
    unstub_object(stub)
  end

  new_name = "__simple_stub__#{method_name}"

  @stubs[key] = Stub.new(object, method_name, new_name)

  object.singleton_class.send :alias_method, new_name, method_name
  object.define_singleton_method(method_name, &block)
end

#unstub_all!Object



27
28
29
30
31
32
# File 'lib/active_support/testing/time_helpers.rb', line 27

def unstub_all!
  @stubs.each_value do |stub|
    unstub_object(stub)
  end
  @stubs = {}
end