class RSpec::Mocks::Constant

Provides information about constants that may (or may not) have been stubbed by rspec-mocks.

Attributes

name[R]

@return [String] The fully qualified name of the constant.

original_value[RW]

@return [Object, nil] The original value (e.g. before it

was stubbed by rspec-mocks) of the constant, or
nil if the constant was not previously defined.
previously_defined[W]

@api private

stubbed[W]

@api private

Public Class Methods

new(name) click to toggle source

@api private

# File lib/rspec/mocks/stub_const.rb, line 26
def initialize(name)
  @name = name
end
original(name) click to toggle source

Queries rspec-mocks to find out information about the named constant.

@param [String] name the name of the constant @return [Constant] an object contaning information about the named

constant.
# File lib/rspec/mocks/stub_const.rb, line 74
def self.original(name)
  stubber = ConstantStubber.find(name)
  stubber ? stubber.to_constant : unstubbed(name)
end

Private Class Methods

unstubbed(name) click to toggle source

@api private

# File lib/rspec/mocks/stub_const.rb, line 59
def self.unstubbed(name)
  const = new(name)
  const.previously_defined = recursive_const_defined?(name)
  const.stubbed = false
  const.original_value = recursive_const_get(name) if const.previously_defined?

  const
end

Public Instance Methods

inspect()
Alias for: to_s
previously_defined?() click to toggle source

@return [Boolean] Whether or not the constant was defined

before the current example.
# File lib/rspec/mocks/stub_const.rb, line 43
def previously_defined?
  @previously_defined
end
stubbed?() click to toggle source

@return [Boolean] Whether or not rspec-mocks has stubbed

this constant.
# File lib/rspec/mocks/stub_const.rb, line 49
def stubbed?
  @stubbed
end
to_s() click to toggle source
# File lib/rspec/mocks/stub_const.rb, line 53
def to_s
  "#<#{self.class.name} #{name}>"
end
Also aliased as: inspect