Class Spec::Mocks::Proxy
In: vendor/plugins/rspec/lib/spec/mocks/proxy.rb
Parent: Object

Methods

Constants

DEFAULT_OPTIONS = { :null_object => false, }

Public Class methods

[Source]

    # File vendor/plugins/rspec/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

[Source]

    # File vendor/plugins/rspec/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

[Source]

    # File vendor/plugins/rspec/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

[Source]

    # File vendor/plugins/rspec/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

[Source]

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

[Source]

    # File vendor/plugins/rspec/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:           if expectation = find_almost_matching_expectation(sym, *args)
68:             expectation.advise(args, block) unless expectation.expected_messages_received?
69:           end
70:           stub.invoke([], block)
71:         elsif expectation = find_almost_matching_expectation(sym, *args)
72:           expectation.advise(args, block) if null_object? unless expectation.expected_messages_received?
73:           raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(sym) or null_object?)
74:         else
75:           @target.send :method_missing, sym, *args, &block
76:         end
77:       end

[Source]

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

[Source]

    # File vendor/plugins/rspec/lib/spec/mocks/proxy.rb, line 79
79:       def raise_unexpected_message_args_error(expectation, *args)
80:         @error_generator.raise_unexpected_message_args_error expectation, *args
81:       end

[Source]

    # File vendor/plugins/rspec/lib/spec/mocks/proxy.rb, line 83
83:       def raise_unexpected_message_error(sym, *args)
84:         @error_generator.raise_unexpected_message_error sym, *args
85:       end

[Source]

    # File vendor/plugins/rspec/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

[Source]

    # File vendor/plugins/rspec/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]