class RSpec::Mocks::ConstantMutator::BaseMutator
Contains common functionality used by all of the constant mutators.
@private
Constants
- CONST_SETTER_SOURCE
Attributes
Public Class Methods
Source
# File lib/rspec/mocks/mutate_const.rb, line 147 def initialize(full_constant_name, mutated_value, transfer_nested_constants) @full_constant_name = normalize_const_name(full_constant_name) @mutated_value = mutated_value @transfer_nested_constants = transfer_nested_constants @context_parts = @full_constant_name.split('::') @const_name = @context_parts.pop @reset_performed = false end
Public Instance Methods
Source
# File lib/rspec/mocks/mutate_const.rb, line 163 def idempotently_reset reset unless @reset_performed @reset_performed = true end
Source
# File lib/rspec/mocks/mutate_const.rb, line 156 def to_constant const = Constant.new(full_constant_name) const.original_value = original_value const end
Private Instance Methods
Source
# File lib/rspec/mocks/mutate_const.rb, line 171 def record_original_source_location @original_source_location = @context.const_source_location(@const_name, false) end
Source
# File lib/rspec/mocks/mutate_const.rb, line 180 def restore_original_value file, line = @original_source_location if file setter = @context.module_eval(CONST_SETTER_SOURCE, file, line) setter.call(@const_name, @original_value) else @context.const_set(@const_name, @original_value) end end