module Hurley::Test::Integration::Common
Public Instance Methods
client()
click to toggle source
# File lib/hurley/test/integration.rb, line 195 def client @client ||= Client.new(Integration.live_endpoint) do |cli| cli.header["X-Hurley-Connection"] = connection.class.name cli.connection = connection if Integration.ssl? cli.ssl_options.ca_file = Integration.ssl_file end end end
proxy_url()
click to toggle source
# File lib/hurley/test/integration.rb, line 206 def proxy_url @proxy_url ||= if raw_url = ENV["HURLEY_PROXY"] Url.parse(raw_url) end end
test_DELETE_retrieves_the_body()
click to toggle source
# File lib/hurley/test/integration.rb, line 152 def test_DELETE_retrieves_the_body assert_equal %(delete), client.delete("echo").body end
test_DELETE_retrieves_the_response_headers()
click to toggle source
# File lib/hurley/test/integration.rb, line 148 def test_DELETE_retrieves_the_response_headers assert_match(/text\/plain/, client.delete("echo").header[:content_type]) end
test_GET_retrieves_the_response_body()
click to toggle source
# File lib/hurley/test/integration.rb, line 30 def test_GET_retrieves_the_response_body assert_equal "get", client.get("echo").body end
test_GET_retrieves_the_response_headers()
click to toggle source
# File lib/hurley/test/integration.rb, line 38 def test_GET_retrieves_the_response_headers response = client.get("echo") assert_match(/text\/plain/, response.header["Content-Type"]) assert_match(/text\/plain/, response.header["content-type"]) assert_match(/text\/plain/, response.header[:content_type]) end
test_GET_send_url_encoded_params()
click to toggle source
# File lib/hurley/test/integration.rb, line 34 def test_GET_send_url_encoded_params assert_equal %(get ?{"name"=>"zack"}), client.get("echo", :name => :zack).body end
test_GET_sends_user_agent()
click to toggle source
# File lib/hurley/test/integration.rb, line 45 def test_GET_sends_user_agent assert_equal Hurley::USER_AGENT, client.get("echo_header", :name => :user_agent).body end
test_GET_ssl()
click to toggle source
# File lib/hurley/test/integration.rb, line 49 def test_GET_ssl expected = Integration.ssl?.to_s assert_equal expected, client.get("ssl").body end
test_HEAD_retrieves_no_response_body()
click to toggle source
# File lib/hurley/test/integration.rb, line 140 def test_HEAD_retrieves_no_response_body assert_nil client.head("echo").body end
test_HEAD_retrieves_the_response_headers()
click to toggle source
# File lib/hurley/test/integration.rb, line 144 def test_HEAD_retrieves_the_response_headers assert_match(/text\/plain/, client.head("echo").header[:content_type]) end
test_OPTIONS()
click to toggle source
# File lib/hurley/test/integration.rb, line 136 def test_OPTIONS assert_equal "options", client.options("echo").body end
test_PATCH_send_url_encoded_params()
click to toggle source
# File lib/hurley/test/integration.rb, line 128 def test_PATCH_send_url_encoded_params res = client.patch "echo" do |req| req.header[:content_type] = "application/x-www-form-urlencoded" req.body = "name=zack" end assert_equal %(patch {"name"=>"zack"}), res.body end
test_POST_retrieves_the_response_headers()
click to toggle source
# File lib/hurley/test/integration.rb, line 70 def test_POST_retrieves_the_response_headers assert_match(/text\/plain/, client.post("echo").header[:content_type]) end
test_POST_send_url_encoded_nested_params()
click to toggle source
# File lib/hurley/test/integration.rb, line 62 def test_POST_send_url_encoded_nested_params res = client.post "echo" do |req| req.body = "name[first]=zack" req.header[:content_type] = "application/x-www-form-urlencoded" end assert_equal %(post {"name"=>{"first"=>"zack"}}), res.body end
test_POST_send_url_encoded_params()
click to toggle source
# File lib/hurley/test/integration.rb, line 54 def test_POST_send_url_encoded_params res = client.post "echo" do |req| req.body = "name=zack" req.header[:content_type] = "application/x-www-form-urlencoded" end assert_equal %(post {"name"=>"zack"}), res.body end
test_POST_sends_files_as_multipart()
click to toggle source
# File lib/hurley/test/integration.rb, line 74 def test_POST_sends_files_as_multipart resp = client.post("file") do |req| ctype, body = Query::Flat.new( :uploaded_file => UploadIO.new(__FILE__, "text/x-ruby"), ).to_form req.header[:content_type] = ctype req.body = body end assert_equal "file integration.rb text/x-ruby #{File.size(__FILE__)}", resp.body end
test_PUT_retrieves_the_response_headers()
click to toggle source
# File lib/hurley/test/integration.rb, line 124 def test_PUT_retrieves_the_response_headers assert_match(/text\/plain/, client.put("echo").header[:content_type]) end
test_PUT_send_url_encoded_nested_params()
click to toggle source
# File lib/hurley/test/integration.rb, line 116 def test_PUT_send_url_encoded_nested_params res = client.put "echo" do |req| req.body = "name[first]=zack" req.header[:content_type] = "application/x-www-form-urlencoded" end assert_equal %(put {"name"=>{"first"=>"zack"}}), res.body end
test_PUT_send_url_encoded_params()
click to toggle source
# File lib/hurley/test/integration.rb, line 108 def test_PUT_send_url_encoded_params res = client.put "echo" do |req| req.body = "name=zack" req.header[:content_type] = "application/x-www-form-urlencoded" end assert_equal %(put {"name"=>"zack"}), res.body end
test_PUT_sends_files()
click to toggle source
# File lib/hurley/test/integration.rb, line 85 def test_PUT_sends_files resp = client.put("raw") do |req| req.header[:content_length] = File.size(__FILE__) req.body = File.open(__FILE__) end assert_equal "raw application/octet-stream #{File.size(__FILE__)} #{File.size(__FILE__)}", resp.body end
test_PUT_sends_io()
click to toggle source
# File lib/hurley/test/integration.rb, line 93 def test_PUT_sends_io resp = client.put("raw") do |req| req.body = GenericIO.new("READ") req.header[:content_length] = 4 end assert_equal "raw application/octet-stream 4 4", resp.body end
test_PUT_sends_io_with_chunked_encoding()
click to toggle source
# File lib/hurley/test/integration.rb, line 101 def test_PUT_sends_io_with_chunked_encoding resp = client.put("raw") do |req| req.body = GenericIO.new("READ") end assert_equal "raw application/octet-stream -1 4", resp.body end
test_connection_error()
click to toggle source
# File lib/hurley/test/integration.rb, line 163 def test_connection_error assert_raises Hurley::ConnectionFailed do client.get "http://localhost:4" end end
test_empty_body_response_represented_as_nil()
click to toggle source
# File lib/hurley/test/integration.rb, line 169 def test_empty_body_response_represented_as_nil res = client.get("204") assert_equal 204, res.status_code assert_nil res.body end
test_proxy()
click to toggle source
# File lib/hurley/test/integration.rb, line 175 def test_proxy return unless client.request_options.proxy = proxy_url res = client.get("/echo") assert_equal "get", res.body unless Integration.ssl? # proxy can't append "Via" header for HTTPS responses assert_match(/:#{proxy_url.port}$/, res.header[:Via]) end end
test_proxy_auth_fail()
click to toggle source
# File lib/hurley/test/integration.rb, line 187 def test_proxy_auth_fail return unless client.request_options.proxy = proxy_url client.request_options.proxy.password = "WRONG" assert_equal 407, client.put("/echo").status_code rescue Hurley::ConnectionFailed # this exception is allowed too end
test_timeout()
click to toggle source
# File lib/hurley/test/integration.rb, line 156 def test_timeout client.request_options.timeout = 0.5 assert_raises Hurley::Timeout do client.get "/slow" end end