123456789_123456789_123456789_123456789_123456789_

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

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, BaseMutator
Instance Chain:
Inherits: RSpec::Mocks::ConstantMutator::BaseMutator
Defined in: rspec-mocks/lib/rspec/mocks/mutate_const.rb

Overview

Sets an undefined constant for the duration of an example.

Class Method Summary

BaseMutator - Inherited

Instance Attribute Summary

Instance Method Summary

BaseMutator - Inherited

::RSpec::Support::RecursiveConstMethods - Included

#const_defined_on?

See additional method definition at line 31.

#constants_defined_on

See additional method definition at line 41.

#get_const_defined_on

See additional method definition at line 35.

#normalize_const_name, #recursive_const_defined?, #recursive_const_get

Instance Method Details

#mutate

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/mutate_const.rb', line 279

def mutate
  @parent = @context_parts.inject(Object) do |klass, name|
    if const_defined_on?(klass, name)
      get_const_defined_on(klass, name)
    else
      ConstantMutator.stub(name_for(klass, name), Module.new)
    end
  end

  @parent.const_set(@const_name, @mutated_value)
end

#name_for(parent, name) (private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/mutate_const.rb', line 305

def name_for(parent, name)
  root = if parent == Object
           ''
         else
           parent.name
         end
  root + '::' + name
end

#reset

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/mutate_const.rb', line 299

def reset
  @parent.__send__(:remove_const, @const_name)
end

#to_constant

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/mutate_const.rb', line 291

def to_constant
  const = super
  const.stubbed = true
  const.previously_defined = false

  const
end