Module: RSpec::Mocks::RecursiveConstMethods

### Home Classes Methods

### In Files

- lib/rspec/mocks/mutate_const.rb

### Methods

- #const_defined_on?
- #constants_defined_on
- #get_const_defined_on
- #normalize_const_name
- #recursive_const_defined?
- #recursive_const_get

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Mocks
- RSpec::Mocks::AllowanceTarget
- RSpec::Mocks::AmbiguousReturnError
- RSpec::Mocks::AndCallOriginalImplementation
- RSpec::Mocks::AndReturnImplementation
- RSpec::Mocks::AndYieldImplementation
- RSpec::Mocks::AnyInstance
- RSpec::Mocks::AnyInstance::Chain
- RSpec::Mocks::AnyInstance::Chain::Customizations
- RSpec::Mocks::AnyInstance::ExpectationChain
- RSpec::Mocks::AnyInstance::MessageChains
- RSpec::Mocks::AnyInstance::PositiveExpectationChain
- RSpec::Mocks::AnyInstance::Recorder
- RSpec::Mocks::AnyInstance::StubChain
- RSpec::Mocks::AnyInstance::StubChainChain
- RSpec::Mocks::AnyInstanceAllowanceTarget
- RSpec::Mocks::AnyInstanceExpectationTarget
- RSpec::Mocks::ArgumentListMatcher
- RSpec::Mocks::ArgumentMatchers
- RSpec::Mocks::ArgumentMatchers::AnyArgMatcher
- RSpec::Mocks::ArgumentMatchers::AnyArgsMatcher
- RSpec::Mocks::ArgumentMatchers::BooleanMatcher
- RSpec::Mocks::ArgumentMatchers::DuckTypeMatcher
- RSpec::Mocks::ArgumentMatchers::EqualityProxy
- RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
- RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::InstanceOf
- RSpec::Mocks::ArgumentMatchers::KindOf
- RSpec::Mocks::ArgumentMatchers::MatcherMatcher
- RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
- RSpec::Mocks::ArgumentMatchers::RegexpMatcher
- RSpec::Mocks::Configuration
- RSpec::Mocks::Constant
- RSpec::Mocks::ConstantMutator
- RSpec::Mocks::ConstantMutator::BaseMutator
- RSpec::Mocks::ConstantMutator::ConstantHider
- RSpec::Mocks::ConstantMutator::DefinedConstantReplacer
- RSpec::Mocks::ConstantMutator::UndefinedConstantSetter
- RSpec::Mocks::ConstantStubber
- RSpec::Mocks::Deprecation
- RSpec::Mocks::ErrorGenerator
- RSpec::Mocks::ExampleMethods
- RSpec::Mocks::ExampleMethods::ExpectHost
- RSpec::Mocks::ExpectationTarget
- RSpec::Mocks::Implementation
- RSpec::Mocks::InstanceExec
- RSpec::Mocks::InstanceMethodStasher
- RSpec::Mocks::Matchers
- RSpec::Mocks::Matchers::HaveReceived
- RSpec::Mocks::Matchers::Receive
- RSpec::Mocks::Matchers::Receive::Customization
- RSpec::Mocks::MessageExpectation
- RSpec::Mocks::MethodDouble
- RSpec::Mocks::MethodDouble::ProcWithBlock
- RSpec::Mocks::Mock
- RSpec::Mocks::MockExpectationError
- RSpec::Mocks::OrderGroup
- RSpec::Mocks::Proxy
- RSpec::Mocks::ProxyForNil
- RSpec::Mocks::RecursiveConstMethods
- RSpec::Mocks::Space
- RSpec::Mocks::StubChain
- RSpec::Mocks::Syntax
- RSpec::Mocks::TargetBase
- RSpec::Mocks::TestDouble
- RSpec::Mocks::Version
- Marshal

No matching classes.

# RSpec::Mocks::RecursiveConstMethods

Provides recursive constant lookup methods useful for constant stubbing. @api private

### Public Instance Methods

const_defined_on?(mod, const_name) click to toggle source

    # File lib/rspec/mocks/mutate_const.rb, line 30
    def const_defined_on?(mod, const_name)
      mod.const_defined?(const_name)
    end

constants_defined_on(mod) click to toggle source

    # File lib/rspec/mocks/mutate_const.rb, line 42
    def constants_defined_on(mod)
      mod.constants.select { |c| const_defined_on?(mod, c) }
    end

get_const_defined_on(mod, const_name) click to toggle source

    # File lib/rspec/mocks/mutate_const.rb, line 34
    def get_const_defined_on(mod, const_name)
      if const_defined_on?(mod, const_name)
        return mod.const_get(const_name)
      end

      raise NameError, "uninitialized constant #{mod.name}::#{const_name}"
    end

normalize_const_name(const_name) click to toggle source

    # File lib/rspec/mocks/mutate_const.rb, line 73
    def normalize_const_name(const_name)
      const_name.sub(/\A::/, '')
    end

recursive_const_defined?(const_name) click to toggle source

    # File lib/rspec/mocks/mutate_const.rb, line 65
    def recursive_const_defined?(const_name)
      normalize_const_name(const_name).split('::').inject([Object, '']) do |(mod, full_name), name|
        yield(full_name, name) if block_given? && !mod.is_a?(Module)
        return false unless const_defined_on?(mod, name)
        [get_const_defined_on(mod, name), [mod, name].join('::')]
      end
    end

recursive_const_get(const_name) click to toggle source

    # File lib/rspec/mocks/mutate_const.rb, line 59
    def recursive_const_get(const_name)
      normalize_const_name(const_name).split('::').inject(Object) do |mod, name|
        get_const_defined_on(mod, name)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.