Module: RSpec::Mocks::RecursiveConstMethods Private

Included in:
Constant, ConstantStubber, ConstantStubber::BaseStubber
Defined in:
lib/rspec/mocks/stub_const.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Provides recursive constant lookup methods useful for constant stubbing.

API:

  • private

Instance Method Summary collapse

Instance Method Details

#recursive_const_defined?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

API:

  • private



11
12
13
14
15
16
17
# File 'lib/rspec/mocks/stub_const.rb', line 11

def recursive_const_defined?(name)
  name.split('::').inject([Object, '']) do |(mod, full_name), name|
    yield(full_name, name) if block_given? && !mod.is_a?(Module)
    return false unless mod.const_defined?(name)
    [mod.const_get(name), [mod, name].join('::')]
  end
end

#recursive_const_get(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



7
8
9
# File 'lib/rspec/mocks/stub_const.rb', line 7

def recursive_const_get(name)
  name.split('::').inject(Object) { |mod, name| mod.const_get name }
end