Class: ActiveSupport::Testing::SimpleStubs

Inherits:
Object
  • Object
show all
Defined in:
activesupport/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.



6
7
8
# File 'activesupport/lib/active_support/testing/time_helpers.rb', line 6

def initialize
  @stubs = {}
end

Instance Method Details

#stub_object(object, method_name, return_value) ⇒ Object



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

def stub_object(object, method_name, return_value)
  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) { return_value }
end

#unstub_all!Object



25
26
27
28
29
30
# File 'activesupport/lib/active_support/testing/time_helpers.rb', line 25

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