123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Mocks::ConstantMutator::ConstantHider 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

Hides a defined 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 170

def mutate
  return unless (@defined = recursive_const_defined?(full_constant_name))
  @context = recursive_const_get(@context_parts.join('::'))
  @original_value = get_const_defined_on(@context, @const_name)

  @context.__send__(:remove_const, @const_name)
end

#reset

[ GitHub ]

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

def reset
  return unless @defined
  @context.const_set(@const_name, @original_value)
end

#to_constant

[ GitHub ]

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

def to_constant
  return Constant.unmutated(full_constant_name) unless @defined

  const = super
  const.hidden = true
  const.previously_defined = true

  const
end