Class: RSpec::Mocks::ConstantMutator::UndefinedConstantSetter

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

Overview

Sets an undefined 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 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



326
327
328
329
330
331
332
333
334
335
336
# File 'lib/rspec/mocks/mutate_const.rb', line 326

def mutate
  @parent = @context_parts.inject(Object) do |klass, name|
    if const_defined_on?(klass, name)
      get_const_defined_on(klass, name)
    else
      ConstantMutator.stub(name_for(klass, name), Module.new)
    end
  end

  @parent.const_set(@const_name, @mutated_value)
end

- (Object) reset



346
347
348
# File 'lib/rspec/mocks/mutate_const.rb', line 346

def reset
  @parent.__send__(:remove_const, @const_name)
end

- (Object) to_constant



338
339
340
341
342
343
344
# File 'lib/rspec/mocks/mutate_const.rb', line 338

def to_constant
  const = super
  const.stubbed = true
  const.previously_defined = false

  const
end