Class: RSpec::Mocks::Space Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/mocks/space.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Space) initialize

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A new instance of Space

7
8
9
10
# File 'lib/rspec/mocks/space.rb', line 7
def initialize
  @proxies                 = {}
  @any_instance_recorders  = {}
end

Instance Attribute Details

- (Object) any_instance_recorders (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

5
6
7
# File 'lib/rspec/mocks/space.rb', line 5
def any_instance_recorders
  @any_instance_recorders
end

- (Object) proxies (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

5
6
7
# File 'lib/rspec/mocks/space.rb', line 5
def proxies
  @proxies
end

Instance Method Details

- (Object) any_instance_recorder_for(klass)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

43
44
45
46
47
48
# File 'lib/rspec/mocks/space.rb', line 43
def any_instance_recorder_for(klass)
  id = klass.__id__
  any_instance_recorders.fetch(id) do
    any_instance_recorders[id] = AnyInstance::Recorder.new(klass)
  end
end

- (Object) expectation_ordering

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

39
40
41
# File 'lib/rspec/mocks/space.rb', line 39
def expectation_ordering
  @expectation_ordering ||= OrderGroup.new
end

- (Object) id_for(object)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

75
76
77
78
79
80
81
82
83
84
# File 'lib/rspec/mocks/space.rb', line 75
def id_for(object)
  id = object.__id__
  return id if object.equal?(::ObjectSpace._id2ref(id))
  # this suggests that object.__id__ is proxying through to some wrapped object

  object.instance_eval do
    @__id_for_rspec_mocks_space ||= ::SecureRandom.uuid
  end
end

- (Object) proxies_of(klass)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

50
51
52
# File 'lib/rspec/mocks/space.rb', line 50
def proxies_of(klass)
  proxies.values.select { |proxy| klass === proxy.object }
end

- (Object) proxy_for(object) Also known as: ensure_registered

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rspec/mocks/space.rb', line 54
def proxy_for(object)
  id = id_for(object)
  proxies.fetch(id) do
    proxies[id] = case object
                  when NilClass   then ProxyForNil.new
                  when TestDouble then object.__build_mock_proxy
                  else
                    Proxy.new(object)
                  end
  end
end

- (Boolean) registered?(object)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)
68
69
70
# File 'lib/rspec/mocks/space.rb', line 68
def registered?(object)
  proxies.has_key?(id_for object)
end

- (Object) reset_all

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rspec/mocks/space.rb', line 22
def reset_all
  ConstantMutator.reset_all
  proxies.each_value do |object|
    object.reset
  end
  proxies.clear
  any_instance_recorders.each_value do |recorder|
    recorder.stop_all_observation!
  end
  any_instance_recorders.clear
  expectation_ordering.clear
end

- (Object) verify_all

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

12
13
14
15
16
17
18
19
20
# File 'lib/rspec/mocks/space.rb', line 12
def verify_all
  proxies.each_value do |object|
    object.verify
  end
  any_instance_recorders.each_value do |recorder|
    recorder.verify
  end
end