Class: RSpec::Mocks::Constant

### Home Classes Methods

### In Files

- lib/rspec/mocks/mutate_const.rb

### Parent

Object

### Methods

- ::new
- ::original
- ::unmutated
- #hidden?
- #inspect
- #mutated?
- #previously_defined?
- #stubbed?
- #to_s
- #valid_name?

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Mocks
- RSpec::Mocks::AllowanceTarget
- RSpec::Mocks::AndReturnImplementation
- RSpec::Mocks::AndWrapOriginalImplementation
- RSpec::Mocks::AndYieldImplementation
- RSpec::Mocks::AnyInstance
- RSpec::Mocks::AnyInstance::Chain
- RSpec::Mocks::AnyInstance::Chain::Customizations
- RSpec::Mocks::AnyInstance::ExpectChainChain
- RSpec::Mocks::AnyInstance::ExpectationChain
- RSpec::Mocks::AnyInstance::FluentInterfaceProxy
- RSpec::Mocks::AnyInstance::MessageChains
- RSpec::Mocks::AnyInstance::PositiveExpectationChain
- RSpec::Mocks::AnyInstance::Proxy
- 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::ArrayIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::BaseHashMatcher
- RSpec::Mocks::ArgumentMatchers::BooleanMatcher
- RSpec::Mocks::ArgumentMatchers::DuckTypeMatcher
- RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
- RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::InstanceOf
- RSpec::Mocks::ArgumentMatchers::KindOf
- RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
- RSpec::Mocks::ArgumentMatchers::SingletonMatcher
- RSpec::Mocks::ClassVerifyingDouble
- 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::DirectObjectReference
- RSpec::Mocks::Double
- RSpec::Mocks::ErrorGenerator
- RSpec::Mocks::ExampleMethods
- RSpec::Mocks::ExampleMethods::ExpectHost
- RSpec::Mocks::ExpectChain
- RSpec::Mocks::ExpectationTarget
- RSpec::Mocks::Implementation
- RSpec::Mocks::InsertOntoBacktrace
- RSpec::Mocks::InstanceMethodReference
- RSpec::Mocks::InstanceMethodStasher
- RSpec::Mocks::InstanceVerifyingDouble
- RSpec::Mocks::MarshalExtension
- RSpec::Mocks::Matchers
- RSpec::Mocks::Matchers::ExpectationCustomization
- RSpec::Mocks::Matchers::HaveReceived
- RSpec::Mocks::Matchers::Receive
- RSpec::Mocks::Matchers::Receive::DefaultDescribable
- RSpec::Mocks::Matchers::ReceiveMessageChain
- RSpec::Mocks::Matchers::ReceiveMessages
- RSpec::Mocks::MessageChain
- RSpec::Mocks::MessageExpectation
- RSpec::Mocks::MessageExpectation::ImplementationDetails
- RSpec::Mocks::MethodDouble
- RSpec::Mocks::MethodReference
- RSpec::Mocks::NamedObjectReference
- RSpec::Mocks::NestedSpace
- RSpec::Mocks::ObjectMethodReference
- RSpec::Mocks::ObjectReference
- RSpec::Mocks::ObjectVerifyingDouble
- RSpec::Mocks::ObjectVerifyingDoubleMethods
- RSpec::Mocks::OrderGroup
- RSpec::Mocks::PartialClassDoubleProxy
- RSpec::Mocks::PartialClassDoubleProxyMethods
- RSpec::Mocks::PartialDoubleProxy
- RSpec::Mocks::Proxy
- RSpec::Mocks::ProxyForNil
- RSpec::Mocks::RootSpace
- RSpec::Mocks::SimpleMessageExpectation
- RSpec::Mocks::Space
- RSpec::Mocks::Space::FakeMutex
- RSpec::Mocks::StubChain
- RSpec::Mocks::Syntax
- RSpec::Mocks::TargetBase
- RSpec::Mocks::TestDouble
- RSpec::Mocks::TestDoubleProxy
- RSpec::Mocks::VerifyingDouble
- RSpec::Mocks::VerifyingExistingMethodDouble
- RSpec::Mocks::VerifyingMessageExpectation
- RSpec::Mocks::VerifyingMethodDouble
- RSpec::Mocks::VerifyingPartialClassDoubleProxy
- RSpec::Mocks::VerifyingPartialDoubleProxy
- RSpec::Mocks::VerifyingProxy
- RSpec::Mocks::VerifyingProxyMethods
- RSpec::Mocks::Version
- BasicObject
- Class

No matching classes.

# RSpec::Mocks::Constant

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

### Attributes

hidden[W]

@private

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 mutated by rspec-mocks) of the constant, or
    nil if the constant was not previously defined.

previously_defined[W]

@private

stubbed[W]

@private

valid_name[W]

@private

### Public Class Methods

new(name) click to toggle source

@api private

    # File lib/rspec/mocks/mutate_const.rb, line 11
    def initialize(name)
      @name = name
      @previously_defined = false
      @stubbed = false
      @hidden = false
      @valid_name = true
      yield self if block_given?
    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/mutate_const.rb, line 86
    def self.original(name)
      mutator = ::RSpec::Mocks.space.constant_mutator_for(name)
      mutator ? mutator.to_constant : unmutated(name)
    end

unmutated(name) click to toggle source

@private

    # File lib/rspec/mocks/mutate_const.rb, line 68
    def self.unmutated(name)
      previously_defined = recursive_const_defined?(name)
    rescue NameError
      new(name) do |c|
        c.valid_name = false
      end
    else
      new(name) do |const|
        const.previously_defined = previously_defined
        const.original_value = recursive_const_get(name) if previously_defined
      end
    end

### Public Instance Methods

hidden?() click to toggle source

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

    this constant.

    # File lib/rspec/mocks/mutate_const.rb, line 51
    def hidden?
      @hidden
    end

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

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

    (stubbed or hidden) this constant.

    # File lib/rspec/mocks/mutate_const.rb, line 39
    def mutated?
      @stubbed || @hidden
    end

previously_defined?() click to toggle source

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

    before the current example.

    # File lib/rspec/mocks/mutate_const.rb, line 33
    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/mutate_const.rb, line 45
    def stubbed?
      @stubbed
    end

to_s() click to toggle source

The default `to_s` isn't very useful, so a custom version is provided.

    # File lib/rspec/mocks/mutate_const.rb, line 62
    def to_s
      "#<#{self.class.name} #{name}>"
    end

Also aliased as: inspect
valid_name?() click to toggle source

@return [Boolean] Whether or not the provided constant name

    is a valid Ruby constant name.

    # File lib/rspec/mocks/mutate_const.rb, line 57
    def valid_name?
      @valid_name
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.