Class: RSpec::Mocks::ConstantMutator::UndefinedConstantSetter Private

Inherits:
BaseMutator
  • Object
show all
Defined in:
lib/rspec/mocks/mutate_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 BaseMutator

#full_constant_name, #original_value

Instance Method Summary (collapse)

Methods inherited from BaseMutator

#initialize

Methods included from RecursiveConstMethods

#const_defined_on?, #constants_defined_on, #get_const_defined_on, #normalize_const_name, #recursive_const_defined?, #recursive_const_get

Constructor Details

This class inherits a constructor from RSpec::Mocks::ConstantMutator::BaseMutator

Instance Method Details

- (Object) mutate

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.

320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/rspec/mocks/mutate_const.rb', line 320
def mutate
  remaining_parts = @context_parts.dup
  @deepest_defined_const = @context_parts.inject(Object) do |klass, name|
    break klass unless const_defined_on?(klass, name)
    remaining_parts.shift
    get_const_defined_on(klass, 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, @mutated_value)
end

- (Object) rspec_reset

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.

344
345
346
# File 'lib/rspec/mocks/mutate_const.rb', line 344
def rspec_reset
  @deepest_defined_const.__send__(:remove_const, @const_to_remove)
end

- (Object) to_constant

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.

336
337
338
339
340
341
342
# File 'lib/rspec/mocks/mutate_const.rb', line 336
def to_constant
  const = super
  const.stubbed = true
  const.previously_defined = false
  const
end