def get_mock_and_run_handlers(method, response_args, options)
response = Response.new(response_args)
if response_args.has_key? :expected_body
raise "#{method} expected body of \"#{response_args[:expected_body]}\" but received #{options[:body]}" if response_args[:expected_body] != options[:body]
end
if response_args.has_key? :expected_headers
check_expected_headers!(response_args, options)
end
if response_args.has_key? :unexpected_headers
check_unexpected_headers!(response_args, options)
end
if response.code >= 200 && response.code < 300 && options.has_key?(:on_success)
response = options[:on_success].call(response)
elsif options.has_key?(:on_failure)
response = options[:on_failure].call(response)
end
encode_nil_response(response)
end