Module: RSpec::Mocks::TestDouble

### Home Classes Methods

### In Files

- lib/rspec/mocks/test_double.rb

### Methods

- ::new
- #==
- #__build_mock_proxy_unless_expired
- #__disallow_further_usage!
- #as_null_object
- #freeze
- #inspect
- #null_object?
- #respond_to?
- #to_s

### 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::TestDouble

Implements the methods needed for a pure test double. RSpec::Mocks::Double includes this module, and it is provided for cases where you want a pure test double without subclassing RSpec::Mocks::Double.

### Public Class Methods

new(name=nil, stubs={}) click to toggle source

Creates a new test double with a `name` (that will be used in error messages only)

    # File lib/rspec/mocks/test_double.rb, line 9
    def initialize(name=nil, stubs={})
      @__expired = false
      if Hash === name && stubs.empty?
        stubs = name
        @name = nil
      else
        @name = name
      end
      assign_stubs(stubs)
    end

### Public Instance Methods

==(other) click to toggle source

This allows for comparing the mock to other objects that proxy such as ActiveRecords belongs_to proxy objects. By making the other object run the comparison, we're sure the call gets delegated to the proxy target.

    # File lib/rspec/mocks/test_double.rb, line 36
    def ==(other)
      other == __mock_proxy
    end

__build_mock_proxy_unless_expired(order_group) click to toggle source

@private

    # File lib/rspec/mocks/test_double.rb, line 56
    def __build_mock_proxy_unless_expired(order_group)
      __raise_expired_error || __build_mock_proxy(order_group)
    end

__disallow_further_usage!() click to toggle source

@private

    # File lib/rspec/mocks/test_double.rb, line 61
    def __disallow_further_usage!
      @__expired = true
    end

as_null_object() click to toggle source

Tells the object to respond to all messages. If specific stub values are declared, they'll work as expected. If not, the receiver is returned.

    # File lib/rspec/mocks/test_double.rb, line 23
    def as_null_object
      __mock_proxy.as_null_object
    end

freeze() click to toggle source

Override for default freeze implementation to prevent freezing of test doubles.

    # File lib/rspec/mocks/test_double.rb, line 67
    def freeze
      RSpec.warn_with("WARNING: you attempted to freeze a test double. This is explicitly a no-op as freezing doubles can lead to undesired behaviour when resetting tests.")
    end

inspect() click to toggle source

@private

    # File lib/rspec/mocks/test_double.rb, line 41
    def inspect
      "#<#{self.class}:#{'0x%x' % object_id} @name=#{@name.inspect}>"
    end

null_object?() click to toggle source

Returns true if this object has received `as_null_object`

    # File lib/rspec/mocks/test_double.rb, line 28
    def null_object?
      __mock_proxy.null_object?
    end

respond_to?(message, incl_private=false) click to toggle source

@private

    # File lib/rspec/mocks/test_double.rb, line 51
    def respond_to?(message, incl_private=false)
      __mock_proxy.null_object? ? true : super
    end

to_s() click to toggle source

@private

    # File lib/rspec/mocks/test_double.rb, line 46
    def to_s
      inspect.gsub('<', '[').gsub('>', ']')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.