Class: RSpec::Mocks::ConstantMutator::ConstantHider

Inherits:
BaseMutator show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb

Overview

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

#idempotently_reset, #initialize

Methods included from Support::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

#mutateObject



170
171
172
173
174
175
176
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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

#resetObject



188
189
190
191
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/mutate_const.rb', line 188

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

#to_constantObject



178
179
180
181
182
183
184
185
186
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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