class Savon::MockExpectation
Public Class Methods
new(operation_name)
click to toggle source
# File lib/savon/mock/expectation.rb, line 7 def initialize(operation_name) @expected = { :operation_name => operation_name } @actual = nil end
Public Instance Methods
actual(operation_name, builder, globals, locals)
click to toggle source
# File lib/savon/mock/expectation.rb, line 23 def actual(operation_name, builder, globals, locals) @actual = { :operation_name => operation_name, :message => locals[:message] } end
response!()
click to toggle source
# File lib/savon/mock/expectation.rb, line 40 def response! unless @response raise ExpectationError, "This expectation was not set up with a response." end HTTPI::Response.new(@response[:code], @response[:headers], @response[:body]) end
returns(response)
click to toggle source
# File lib/savon/mock/expectation.rb, line 17 def returns(response) response = { :code => 200, :headers => {}, :body => response } if response.kind_of?(String) @response = response self end
verify!()
click to toggle source
# File lib/savon/mock/expectation.rb, line 30 def verify! unless @actual raise ExpectationError, "Expected a request to the #{@expected[:operation_name].inspect} operation, " \ "but no request was executed." end verify_operation_name! verify_message! end
with(locals)
click to toggle source
# File lib/savon/mock/expectation.rb, line 12 def with(locals) @expected[:message] = locals[:message] self end
Private Instance Methods
equals_except_any(msg_expected, msg_real)
click to toggle source
# File lib/savon/mock/expectation.rb, line 71 def equals_except_any(msg_expected, msg_real) return true if msg_expected === msg_real return false if (msg_expected.nil? || msg_real.nil?) # If both are nil has returned true msg_expected.each do |key, expected_value| next if (expected_value == :any && msg_real.include?(key)) return false if expected_value != msg_real[key] end return true end
verify_message!()
click to toggle source
# File lib/savon/mock/expectation.rb, line 57 def verify_message! return if @expected[:message].eql? :any unless equals_except_any(@expected[:message], @actual[:message]) expected_message = " with this message: #{@expected[:message].inspect}" if @expected[:message] expected_message ||= " with no message." actual_message = " with this message: #{@actual[:message].inspect}" if @actual[:message] actual_message ||= " with no message." raise ExpectationError, "Expected a request to the #{@expected[:operation_name].inspect} operation\n#{expected_message}\n" \ "Received a request to the #{@actual[:operation_name].inspect} operation\n#{actual_message}" end end
verify_operation_name!()
click to toggle source
# File lib/savon/mock/expectation.rb, line 50 def verify_operation_name! unless @expected[:operation_name] == @actual[:operation_name] raise ExpectationError, "Expected a request to the #{@expected[:operation_name].inspect} operation.\n" \ "Received a request to the #{@actual[:operation_name].inspect} operation instead." end end