Class: Spec::Mocks::Proxy

Class | Spec::Mocks::Proxy
In: | lib/spec/mocks/proxy.rb
Parent: | Object

### Methods

add_message_expectation add_negative_message_expectation add_stub has_negative_expectation? message_received new null_object? raise_unexpected_message_args_error raise_unexpected_message_error received_message? reset

### Constants

DEFAULT_OPTIONS | = | { :null_object => false, }

### Public Class methods

new(target, name, options={})

[Source]

        # File lib/spec/mocks/proxy.rb, line 8
     8:       def initialize(target, name, options={})
     9:         @target = target
    10:         @name = name
    11:         @error_generator = ErrorGenerator.new target, name
    12:         @expectation_ordering = OrderGroup.new @error_generator
    13:         @expectations = []
    14:         @messages_received = []
    15:         @stubs = []
    16:         @proxied_methods = []
    17:         @options = options ? DEFAULT_OPTIONS.dup.merge(options) : DEFAULT_OPTIONS
    18:       end

### Public Instance methods

add_message_expectation(expected_from, sym, opts={}, &block)

[Source]

        # File lib/spec/mocks/proxy.rb, line 24
    24:       def add_message_expectation(expected_from, sym, opts={}, &block)
    25:         __add sym
    26:         @expectations << MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil, 1, opts)
    27:         @expectations.last
    28:       end

add_negative_message_expectation(expected_from, sym, &block)

[Source]

        # File lib/spec/mocks/proxy.rb, line 30
    30:       def add_negative_message_expectation(expected_from, sym, &block)
    31:         __add sym
    32:         @expectations << NegativeMessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil)
    33:         @expectations.last
    34:       end

add_stub(expected_from, sym, opts={})

[Source]

        # File lib/spec/mocks/proxy.rb, line 36
    36:       def add_stub(expected_from, sym, opts={})
    37:         __add sym
    38:         @stubs.unshift MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, nil, :any, opts)
    39:         @stubs.first
    40:       end

has_negative_expectation?(sym)

[Source]

        # File lib/spec/mocks/proxy.rb, line 59
    59:       def has_negative_expectation?(sym)
    60:         @expectations.detect {|expectation| expectation.negative_expectation_for?(sym)}
    61:       end

message_received(sym, *args, &block)

[Source]

        # File lib/spec/mocks/proxy.rb, line 63
    63:       def message_received(sym, *args, &block)
    64:         if expectation = find_matching_expectation(sym, *args)
    65:           expectation.invoke(args, block)
    66:         elsif stub = find_matching_method_stub(sym, *args)
    67:           stub.invoke([], block)
    68:         elsif expectation = find_almost_matching_expectation(sym, *args)
    69:           raise_unexpected_message_args_error(expectation, *args) unless has_negative_expectation?(sym) unless null_object?
    70:         else
    71:           @target.send :method_missing, sym, *args, &block
    72:         end
    73:       end

null_object?()

[Source]

        # File lib/spec/mocks/proxy.rb, line 20
    20:       def null_object?
    21:         @options[:null_object]
    22:       end

raise_unexpected_message_args_error(expectation, *args)

[Source]

        # File lib/spec/mocks/proxy.rb, line 75
    75:       def raise_unexpected_message_args_error(expectation, *args)
    76:         @error_generator.raise_unexpected_message_args_error expectation, *args
    77:       end

raise_unexpected_message_error(sym, *args)

[Source]

        # File lib/spec/mocks/proxy.rb, line 79
    79:       def raise_unexpected_message_error(sym, *args)
    80:         @error_generator.raise_unexpected_message_error sym, *args
    81:       end

received_message?(sym, *args, &block)

[Source]

        # File lib/spec/mocks/proxy.rb, line 55
    55:       def received_message?(sym, *args, &block)
    56:         @messages_received.any? {|array| array == [sym, args, block]}
    57:       end

reset()

[Source]

        # File lib/spec/mocks/proxy.rb, line 48
    48:       def reset
    49:         clear_expectations
    50:         clear_stubs
    51:         reset_proxied_methods
    52:         clear_proxied_methods
    53:       end

[Validate]