Class: RSpec::Mocks::Proxy

### Home Classes Methods

### In Files

- lib/rspec/mocks/proxy.rb

### Parent

Object

### Methods

- ::new
- #add_message_expectation
- #add_stub
- #already_proxied_respond_to
- #already_proxied_respond_to?
- #as_null_object
- #build_expectation
- #check_for_unexpected_arguments
- #has_negative_expectation?
- #message_received
- #null_object?
- #raise_missing_default_stub_error
- #raise_unexpected_message_args_error
- #raise_unexpected_message_error
- #received_message?
- #record_message_received
- #remove_stub
- #replay_received_message_on
- #reset
- #verify

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

@private

### Public Class Methods

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

@private

    # File lib/rspec/mocks/proxy.rb, line 7
    def initialize(object, name=nil, options={})
      @object = object
      @name = name
      @error_generator = ErrorGenerator.new object, name, options
      @expectation_ordering = RSpec::Mocks::space.expectation_ordering
      @messages_received = []
      @options = options
      @already_proxied_respond_to = false
      @null_object = false
    end

### Public Instance Methods

add_message_expectation(location, method_name, opts={}, &block) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 42
    def add_message_expectation(location, method_name, opts={}, &block)
      meth_double = method_double[method_name]

      if null_object? && !block
        meth_double.add_default_stub(@error_generator, @expectation_ordering, location, opts) do
          @object
        end
      end

      meth_double.add_expectation @error_generator, @expectation_ordering, location, opts, &block
    end

add_stub(location, method_name, opts={}, &implementation) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 94
    def add_stub(location, method_name, opts={}, &implementation)
      method_double[method_name].add_stub @error_generator, @expectation_ordering, location, opts, &implementation
    end

already_proxied_respond_to() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 32
    def already_proxied_respond_to
      @already_proxied_respond_to = true
    end

already_proxied_respond_to?() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 37
    def already_proxied_respond_to?
      @already_proxied_respond_to
    end

as_null_object() click to toggle source

@private Tells the object to ignore any messages that aren't explicitly set as stubs or message expectations.

    # File lib/rspec/mocks/proxy.rb, line 26
    def as_null_object
      @null_object = true
      @object
    end

build_expectation(method_name) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 55
    def build_expectation(method_name)
      meth_double = method_double[method_name]

      meth_double.build_expectation(
        @error_generator,
        @expectation_ordering
      )
    end

check_for_unexpected_arguments(expectation) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 85
    def check_for_unexpected_arguments(expectation)
      @messages_received.each do |(method_name, args, _)|
        if expectation.matches_name_but_not_args(method_name, *args)
          raise_unexpected_message_args_error(expectation, *args)
        end
      end
    end

has_negative_expectation?(message) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 122
    def has_negative_expectation?(message)
      method_double[message].expectations.detect {|expectation| expectation.negative_expectation_for?(message)}
    end

message_received(message, *args, &block) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 132
    def message_received(message, *args, &block)
      record_message_received message, *args, &block
      expectation = find_matching_expectation(message, *args)
      stub = find_matching_method_stub(message, *args)

      if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
        expectation.increase_actual_received_count! if expectation && expectation.actual_received_count_matters?
        if expectation = find_almost_matching_expectation(message, *args)
          expectation.advise(*args) unless expectation.expected_messages_received?
        end
        stub.invoke(nil, *args, &block)
      elsif expectation
        expectation.invoke(stub, *args, &block)
      elsif expectation = find_almost_matching_expectation(message, *args)
        expectation.advise(*args) if null_object? unless expectation.expected_messages_received?
        raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(message) or null_object?)
      elsif stub = find_almost_matching_stub(message, *args)
        stub.advise(*args)
        raise_missing_default_stub_error(stub, *args)
      elsif @object.is_a?(Class)
        @object.superclass.__send__(message, *args, &block)
      else
        @object.__send__(:method_missing, message, *args, &block)
      end
    end

null_object?() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 19
    def null_object?
      @null_object
    end

raise_missing_default_stub_error(expectation, *args) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 169
    def raise_missing_default_stub_error(expectation, *args)
      @error_generator.raise_missing_default_stub_error(expectation, *args)
    end

raise_unexpected_message_args_error(expectation, *args) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 164
    def raise_unexpected_message_args_error(expectation, *args)
      @error_generator.raise_unexpected_message_args_error(expectation, *args)
    end

raise_unexpected_message_error(method_name, *args) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 159
    def raise_unexpected_message_error(method_name, *args)
      @error_generator.raise_unexpected_message_error method_name, *args
    end

received_message?(method_name, *args, &block) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 117
    def received_message?(method_name, *args, &block)
      @messages_received.any? {|array| array == [method_name, args, block]}
    end

record_message_received(message, *args, &block) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 127
    def record_message_received(message, *args, &block)
      @messages_received << [message, args, block]
    end

remove_stub(method_name) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 99
    def remove_stub(method_name)
      method_double[method_name].remove_stub
    end

replay_received_message_on(expectation) click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 65
    def replay_received_message_on(expectation)
      expected_method_name = expectation.message
      meth_double = method_double[expected_method_name]

      if meth_double.expectations.any?
        @error_generator.raise_expectation_on_mocked_method(expected_method_name)
      end

      unless null_object? || meth_double.stubs.any?
        @error_generator.raise_expectation_on_unstubbed_method(expected_method_name)
      end

      @messages_received.each do |(actual_method_name, args, _)|
        if expectation.matches?(actual_method_name, *args)
          expectation.invoke(nil)
        end
      end
    end

reset() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 111
    def reset
      method_doubles.each {|d| d.reset}
      @messages_received.clear
    end

verify() click to toggle source

@private

    # File lib/rspec/mocks/proxy.rb, line 104
    def verify
      method_doubles.each {|d| d.verify}
    ensure
      reset
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.