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

8
9
10
11
12
# File 'lib/rspec/mocks/space.rb', line 8
def initialize
  @proxies                 = {}
  @any_instance_recorders  = {}
  self.outside_example     = true
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) outside_example

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.

6
7
8
# File 'lib/rspec/mocks/space.rb', line 6
def outside_example
  @outside_example
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.

45
46
47
48
49
50
51
# File 'lib/rspec/mocks/space.rb', line 45
def any_instance_recorder_for(klass)
  print_out_of_example_deprecation if outside_example
  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.

41
42
43
# File 'lib/rspec/mocks/space.rb', line 41
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.

83
84
85
86
87
88
89
90
91
92
# File 'lib/rspec/mocks/space.rb', line 83
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

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.

76
77
78
# File 'lib/rspec/mocks/space.rb', line 76
def print_out_of_example_deprecation
  RSpec.deprecate("Using rspec-mocks doubles or partial doubles outside the per-test lifecycle (such as in a `before(:all)` hook)")
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.

53
54
55
# File 'lib/rspec/mocks/space.rb', line 53
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.

57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rspec/mocks/space.rb', line 57
def proxy_for(object)
  print_out_of_example_deprecation if outside_example
  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)
72
73
74
# File 'lib/rspec/mocks/space.rb', line 72
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.

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rspec/mocks/space.rb', line 24
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.

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