Class: RSpec::Mocks::Space

Inherits:
Object show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb

Direct Known Subclasses

NestedSpace

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpace

Returns a new instance of Space.



60
61
62
63
64
65
66
67
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 60

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

#any_instance_mutexObject (readonly)

Returns the value of attribute any_instance_mutex.



58
59
60
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 58

def any_instance_mutex
  @any_instance_mutex
end

#any_instance_recordersObject (readonly)

Returns the value of attribute any_instance_recorders.



58
59
60
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 58

def any_instance_recorders
  @any_instance_recorders
end

#proxiesObject (readonly)

Returns the value of attribute proxies.



58
59
60
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 58

def proxies
  @proxies
end

#proxy_mutexObject (readonly)

Returns the value of attribute proxy_mutex.



58
59
60
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 58

def proxy_mutex
  @proxy_mutex
end

Instance Method Details

#any_instance_proxy_for(klass) ⇒ Object



103
104
105
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 103

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

#any_instance_recorder_for(klass, only_return_existing = false) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 93

def any_instance_recorder_for(klass, only_return_existing=false)
  any_instance_mutex.synchronize do
    id = klass.__id__
    any_instance_recorders.fetch(id) do
      return nil if only_return_existing
      any_instance_recorder_not_found_for(id, klass)
    end
  end
end

#any_instance_recorders_from_ancestry_of(object) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 131

def any_instance_recorders_from_ancestry_of(object)
  # Optimization: `any_instance` is a feature we generally
  # recommend not using, so we can often early exit here
  # without doing an O(N) linear search over the number of
  # ancestors in the object's class hierarchy.
  return [] if any_instance_recorders.empty?

  # We access the ancestors through the singleton class, to avoid calling
  # `class` in case `class` has been stubbed.
  (class << object; ancestors; end).map do |klass|
    any_instance_recorders[klass.__id__]
  end.compact
end

#constant_mutator_for(name) ⇒ Object



89
90
91
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 89

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

#new_scopeObject



69
70
71
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 69

def new_scope
  NestedSpace.new(self)
end

#proxies_of(klass) ⇒ Object



107
108
109
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 107

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

#proxy_for(object) ⇒ Object Also known as: ensure_registered



111
112
113
114
115
116
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 111

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

#register_constant_mutator(mutator) ⇒ Object



85
86
87
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 85

def register_constant_mutator(mutator)
  @constant_mutators << mutator
end

#registered?(object) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 127

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

#reset_allObject



78
79
80
81
82
83
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 78

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

#superclass_proxy_for(klass) ⇒ Object



118
119
120
121
122
123
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 118

def superclass_proxy_for(klass)
  proxy_mutex.synchronize do
    id = id_for(klass)
    proxies.fetch(id) { superclass_proxy_not_found_for(id, klass) }
  end
end

#verify_allObject



73
74
75
76
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/space.rb', line 73

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