A proxy for mock objects. Stubs and expectations are set on this proxy.
# File lib/facon/proxy.rb, line 9 def initialize(target, name) @target, @name = target, name @expectations = [] @stubs = [] @proxied_methods = [] @error_generator = ErrorGenerator.new(target, name) @expectation_ordering = nil unless defined?(@expectation_ordering) end
# File lib/facon/proxy.rb, line 26 def add_expectation(expected_from, method, &block) add_method(method) @expectations << Expectation.new(@error_generator, @expectation_ordering, expected_from, method, (block_given? ? block : nil), 1) @expectations.last end
# File lib/facon/proxy.rb, line 33 def add_negative_expectation(expected_from, method, &block) add_method(method) @expectations << NegativeExpectation.new(@error_generator, @expectation_ordering, expected_from, method, (block_given? ? block : nil)) @expectations.last end
# File lib/facon/proxy.rb, line 18 def add_stub(expected_from, method) add_method(method) # A stub is really an expectation that can be called any number of times. @stubs.unshift(Expectation.new(@error_generator, @expectation_ordering, expected_from, method, nil, :any)) @stubs.first end
# File lib/facon/proxy.rb, line 40 def message_received(method, *args, &block) if expectation = find_matching_expectation(method, *args) expectation.invoke(args, block) elsif stub = find_matching_method_stub(method, *args) stub.invoke([], block) elsif expectation = find_almost_matching_expectation(method, *args) raise_unexpected_message_args_error(expectation, *args) unless has_negative_expectation?(method) else @target.send(:method_missing, method, *args, &block) end end
Generated with the Darkfish Rdoc Generator 2.