Module: RSpec::Support::RecursiveConstMethods

### Home Classes Methods

### In Files

- lib/rspec/support/recursive_const_methods.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::CallerFilter
- RSpec::Support
- RSpec::Support::BlockSignature
- RSpec::Support::Differ
- RSpec::Support::DirectoryMaker
- RSpec::Support::EncodedString
- RSpec::Support::FormattingSupport
- RSpec::Support::FuzzyMatcher
- RSpec::Support::HunkGenerator
- RSpec::Support::InSubProcess
- RSpec::Support::LooseSignatureVerifier
- RSpec::Support::LooseSignatureVerifier::SignatureWithKeywordArgumentsMatcher
- RSpec::Support::MethodSignature
- RSpec::Support::MethodSignatureVerifier
- RSpec::Support::OS
- RSpec::Support::RecursiveConstMethods
- RSpec::Support::Ruby
- RSpec::Support::RubyFeatures
- RSpec::Support::ShellOut
- RSpec::Support::Spec
- RSpec::Support::StdErrSplitter
- RSpec::Support::StrictSignatureVerifier
- RSpec::Support::Version
- RSpec::Support::VersionChecker
- RSpec::Support::Warnings
- RSpec::Support::WarningsPrevention
- RSpec::Support::WithIsolatedStdErr
- Object
- RSpecHelpers

No matching classes.

# RSpec::Support::RecursiveConstMethods

Provides recursive constant lookup methods useful for constant stubbing.

### Public Instance Methods

const_defined_on?(mod, const_name) click to toggle source

    # File lib/rspec/support/recursive_const_methods.rb, line 29
    def const_defined_on?(mod, const_name)
      mod.const_defined?(const_name)
    end

constants_defined_on(mod) click to toggle source

    # File lib/rspec/support/recursive_const_methods.rb, line 39
    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/support/recursive_const_methods.rb, line 33
    def get_const_defined_on(mod, const_name)
      return mod.const_get(const_name) if const_defined_on?(mod, const_name)

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

normalize_const_name(const_name) click to toggle source

    # File lib/rspec/support/recursive_const_methods.rb, line 71
    def normalize_const_name(const_name)
      const_name.sub(/\A::/, '')
    end

recursive_const_defined?(const_name) click to toggle source

    # File lib/rspec/support/recursive_const_methods.rb, line 62
    def recursive_const_defined?(const_name)
      parts = normalize_const_name(const_name).split('::')
      parts.inject([Object, '']) do |(mod, full_name), name|
        yield(full_name, name) if block_given? && !(Module === mod)
        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/support/recursive_const_methods.rb, line 56
    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.