Class: RSpec::Mocks::ConstantMutator::BaseMutator

Inherits:
Object
  • Object
show all
Includes:
RecursiveConstMethods
Defined in:
lib/rspec/mocks/mutate_const.rb

Overview

Contains common functionality used by all of the constant mutators.

Direct Known Subclasses

ConstantHider, DefinedConstantReplacer, UndefinedConstantSetter

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

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

- (BaseMutator) initialize(full_constant_name, mutated_value, transfer_nested_constants)

Returns a new instance of BaseMutator



206
207
208
209
210
211
212
213
# File 'lib/rspec/mocks/mutate_const.rb', line 206

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

Instance Attribute Details

- (Object) full_constant_name (readonly)

Returns the value of attribute full_constant_name



204
205
206
# File 'lib/rspec/mocks/mutate_const.rb', line 204

def full_constant_name
  @full_constant_name
end

- (Object) original_value (readonly)

Returns the value of attribute original_value



204
205
206
# File 'lib/rspec/mocks/mutate_const.rb', line 204

def original_value
  @original_value
end

Instance Method Details

- (Object) idempotently_reset



222
223
224
225
# File 'lib/rspec/mocks/mutate_const.rb', line 222

def idempotently_reset
  reset unless @reset_performed
  @reset_performed = true
end

- (Object) to_constant



215
216
217
218
219
220
# File 'lib/rspec/mocks/mutate_const.rb', line 215

def to_constant
  const = Constant.new(full_constant_name)
  const.original_value = original_value

  const
end