Class: RSpec::Mocks::ConstantStubber::UndefinedConstantSetter Private
- Inherits:
-
BaseStubber
- Object
- BaseStubber
- RSpec::Mocks::ConstantStubber::UndefinedConstantSetter
- Defined in:
- lib/rspec/mocks/stub_const.rb
Overview
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.
Sets an undefined constant for the duration of an example.
Instance Attribute Summary
Attributes inherited from BaseStubber
#full_constant_name, #original_value
Instance Method Summary collapse
- #previously_defined? ⇒ Boolean private
- #rspec_reset ⇒ Object private
- #stub ⇒ Object private
Methods inherited from BaseStubber
Methods included from RecursiveConstMethods
#recursive_const_defined?, #recursive_const_get
Constructor Details
This class inherits a constructor from RSpec::Mocks::ConstantStubber::BaseStubber
Instance Method Details
#previously_defined? ⇒ Boolean
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.
218 219 220 |
# File 'lib/rspec/mocks/stub_const.rb', line 218 def previously_defined? false end |
#rspec_reset ⇒ 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.
222 223 224 |
# File 'lib/rspec/mocks/stub_const.rb', line 222 def rspec_reset @deepest_defined_const.send(:remove_const, @const_to_remove) end |
#stub ⇒ 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.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/rspec/mocks/stub_const.rb', line 202 def stub remaining_parts = @context_parts.dup @deepest_defined_const = @context_parts.inject(Object) do |klass, name| break klass unless klass.const_defined?(name) remaining_parts.shift klass.const_get(name) end context = remaining_parts.inject(@deepest_defined_const) do |klass, name| klass.const_set(name, Module.new) end @const_to_remove = remaining_parts.first || @const_name context.const_set(@const_name, @stubbed_value) end |