Module: RSpec::Mocks::TestDouble

### Home Classes Methods

### In Files

- lib/rspec/mocks/test_double.rb

### Methods

- ::extend_onto
- ::new
- #==
- #__build_mock_proxy
- #as_null_object
- #inspect
- #null_object?
- #respond_to?
- #to_s
- #to_str

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Mocks
- RSpec::Mocks::AllowanceTarget
- RSpec::Mocks::AmbiguousReturnError
- RSpec::Mocks::AndCallOriginalImplementation
- RSpec::Mocks::AndReturnImplementation
- RSpec::Mocks::AndYieldImplementation
- RSpec::Mocks::AnyInstance
- RSpec::Mocks::AnyInstance::Chain
- RSpec::Mocks::AnyInstance::Chain::Customizations
- RSpec::Mocks::AnyInstance::ExpectationChain
- RSpec::Mocks::AnyInstance::MessageChains
- RSpec::Mocks::AnyInstance::PositiveExpectationChain
- 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::BooleanMatcher
- RSpec::Mocks::ArgumentMatchers::DuckTypeMatcher
- RSpec::Mocks::ArgumentMatchers::EqualityProxy
- RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
- RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
- RSpec::Mocks::ArgumentMatchers::InstanceOf
- RSpec::Mocks::ArgumentMatchers::KindOf
- RSpec::Mocks::ArgumentMatchers::MatcherMatcher
- RSpec::Mocks::ArgumentMatchers::NoArgsMatcher
- RSpec::Mocks::ArgumentMatchers::RegexpMatcher
- 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::ConstantStubber
- RSpec::Mocks::Deprecation
- RSpec::Mocks::ErrorGenerator
- RSpec::Mocks::ExampleMethods
- RSpec::Mocks::ExampleMethods::ExpectHost
- RSpec::Mocks::ExpectationTarget
- RSpec::Mocks::Implementation
- RSpec::Mocks::InstanceExec
- RSpec::Mocks::InstanceMethodStasher
- RSpec::Mocks::Matchers
- RSpec::Mocks::Matchers::HaveReceived
- RSpec::Mocks::Matchers::Receive
- RSpec::Mocks::Matchers::Receive::Customization
- RSpec::Mocks::MessageExpectation
- RSpec::Mocks::MethodDouble
- RSpec::Mocks::MethodDouble::ProcWithBlock
- RSpec::Mocks::Mock
- RSpec::Mocks::MockExpectationError
- RSpec::Mocks::OrderGroup
- RSpec::Mocks::Proxy
- RSpec::Mocks::ProxyForNil
- RSpec::Mocks::RecursiveConstMethods
- RSpec::Mocks::Space
- RSpec::Mocks::StubChain
- RSpec::Mocks::Syntax
- RSpec::Mocks::TargetBase
- RSpec::Mocks::TestDouble
- RSpec::Mocks::Version
- Marshal

No matching classes.

# RSpec::Mocks::TestDouble

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

### Public Class Methods

extend_onto(object, name=nil, stubs_and_options={}) click to toggle source

Extends the TestDouble module onto the given object and initializes it as a test double.

@example

    module = Module.new
    RSpec::Mocks::TestDouble.extend_onto(module, "MyMixin", :foo => "bar")
    module.foo  #=> "bar"

    # File lib/rspec/mocks/test_double.rb, line 15
    def self.extend_onto(object, name=nil, stubs_and_options={})
      object.extend self
      object.send(:__initialize_as_test_double, name, stubs_and_options)
    end

new(name=nil, stubs_and_options={}) 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 22
    def initialize(name=nil, stubs_and_options={})
      __initialize_as_test_double(name, stubs_and_options)
    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 43
    def ==(other)
      other == __mock_proxy
    end

__build_mock_proxy() click to toggle source

@private

    # File lib/rspec/mocks/test_double.rb, line 65
    def __build_mock_proxy
      proxy = Proxy.new(self, @name, @options || {})
      proxy.as_null_object if null_object?
      proxy
    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 29
    def as_null_object
      @__null_object = true
      __mock_proxy.as_null_object
    end

inspect() click to toggle source

@private

    # File lib/rspec/mocks/test_double.rb, line 48
    def inspect
      "#<#{self.class}:#{sprintf '0x%x', self.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 35
    def null_object?
      @__null_object
    end

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

@private

    # File lib/rspec/mocks/test_double.rb, line 60
    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 53
    def to_s
      inspect.gsub('<','[').gsub('>',']')
    end

Also aliased as: to_str
to_str() click to toggle source
Alias for: to_s

[Validate]

Generated with the Darkfish Rdoc Generator 2.