Class | Spec::Mocks::Proxy |
In: |
lib/spec/mocks/proxy.rb
|
Parent: | Object |
DEFAULT_OPTIONS | = | { :null_object => false, } |
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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