Class: RSpec::Mocks::Space

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

Direct Known Subclasses

NestedSpace

Defined Under Namespace

Modules: FakeMutex

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Space) initialize



50
51
52
53
54
55
56
57
# File 'lib/rspec/mocks/space.rb', line 50

def initialize
  @proxies                 = {}
  @any_instance_recorders  = {}
  @constant_mutators       = []
  @expectation_ordering    = OrderGroup.new
  @proxy_mutex             = new_mutex
  @any_instance_mutex      = new_mutex
end

Instance Attribute Details

- (Object) any_instance_mutex (readonly)

Returns the value of attribute any_instance_mutex



48
49
50
# File 'lib/rspec/mocks/space.rb', line 48

def any_instance_mutex
  @any_instance_mutex
end

- (Object) any_instance_recorders (readonly)

Returns the value of attribute any_instance_recorders



48
49
50
# File 'lib/rspec/mocks/space.rb', line 48

def any_instance_recorders
  @any_instance_recorders
end

- (Object) proxies (readonly)

Returns the value of attribute proxies



48
49
50
# File 'lib/rspec/mocks/space.rb', line 48

def proxies
  @proxies
end

- (Object) proxy_mutex (readonly)

Returns the value of attribute proxy_mutex



48
49
50
# File 'lib/rspec/mocks/space.rb', line 48

def proxy_mutex
  @proxy_mutex
end

Instance Method Details

- (Object) any_instance_proxy_for(klass)



92
93
94
# File 'lib/rspec/mocks/space.rb', line 92

def any_instance_proxy_for(klass)
  AnyInstance::Proxy.new(any_instance_recorder_for(klass), proxies_of(klass))
end

- (Object) any_instance_recorder_for(klass)



83
84
85
86
87
88
89
90
# File 'lib/rspec/mocks/space.rb', line 83

def any_instance_recorder_for(klass)
  any_instance_mutex.synchronize do
    id = klass.__id__
    any_instance_recorders.fetch(id) do
      any_instance_recorder_not_found_for(id, klass)
    end
  end
end

- (Object) constant_mutator_for(name)



79
80
81
# File 'lib/rspec/mocks/space.rb', line 79

def constant_mutator_for(name)
  @constant_mutators.find { |m| m.full_constant_name == name }
end

- (Object) new_scope



59
60
61
# File 'lib/rspec/mocks/space.rb', line 59

def new_scope
  NestedSpace.new(self)
end

- (Object) proxies_of(klass)



96
97
98
# File 'lib/rspec/mocks/space.rb', line 96

def proxies_of(klass)
  proxies.values.select { |proxy| klass === proxy.object }
end

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



100
101
102
103
104
105
# File 'lib/rspec/mocks/space.rb', line 100

def proxy_for(object)
  proxy_mutex.synchronize do
    id = id_for(object)
    proxies.fetch(id) { proxy_not_found_for(id, object) }
  end
end

- (Object) register_constant_mutator(mutator)



75
76
77
# File 'lib/rspec/mocks/space.rb', line 75

def register_constant_mutator(mutator)
  @constant_mutators << mutator
end

- (Boolean) registered?(object)



109
110
111
# File 'lib/rspec/mocks/space.rb', line 109

def registered?(object)
  proxies.has_key?(id_for object)
end

- (Object) reset_all



68
69
70
71
72
73
# File 'lib/rspec/mocks/space.rb', line 68

def reset_all
  proxies.each_value { |proxy| proxy.reset }
  @constant_mutators.reverse.each { |mut| mut.idempotently_reset }
  any_instance_recorders.each_value { |recorder| recorder.stop_all_observation! }
  any_instance_recorders.clear
end

- (Object) verify_all



63
64
65
66
# File 'lib/rspec/mocks/space.rb', line 63

def verify_all
  proxies.each_value { |proxy| proxy.verify }
  any_instance_recorders.each_value { |recorder| recorder.verify }
end