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

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



224
225
226
227
228
229
# File 'lib/rspec/mocks/mutate_const.rb', line 224

def mutate
  @context = recursive_const_get(@context_parts.join('::'))
  @original_value = get_const_defined_on(@context, @const_name)

  @context.__send__(:remove_const, @const_name)
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.



239
240
241
# File 'lib/rspec/mocks/mutate_const.rb', line 239

def rspec_reset
  @context.const_set(@const_name, @original_value)
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.



231
232
233
234
235
236
237
# File 'lib/rspec/mocks/mutate_const.rb', line 231

def to_constant
  const = super
  const.hidden = true
  const.previously_defined = true

  const
end