spec/httpi/adapter/net_http_spec.rb in httpi-2.4.1 vs spec/httpi/adapter/net_http_spec.rb in httpi-2.4.2
- old
+ new
@@ -12,10 +12,26 @@
after :all do
@server.stop
end
+ context 'when socks is specified' do
+
+ let(:socks_client) { mock('socks_client') }
+ let(:request){HTTPI::Request.new(@server.url)}
+
+ it 'uses Net::HTTP.SOCKSProxy as client' do
+ socks_client.expects(:new).with(URI(@server.url).host, URI(@server.url).port).returns(:socks_client_instance)
+ Net::HTTP.expects(:SOCKSProxy).with('localhost', 8080).returns socks_client
+
+ request.proxy = 'socks://localhost:8080'
+ adapter = HTTPI::Adapter::NetHTTP.new(request)
+
+ expect(adapter.client).to eq(:socks_client_instance)
+ end
+ end
+
it "sends and receives HTTP headers" do
request = HTTPI::Request.new(@server.url + "x-header")
request.headers["X-Header"] = "HTTPI"
response = HTTPI.get(request, adapter)
@@ -50,10 +66,40 @@
response = HTTPI.delete(@server.url, adapter)
expect(response.body).to eq("delete")
expect(response.headers["Content-Type"]).to eq("text/plain")
end
+ context "supports custom methods supported by Net::HTTP" do
+ let(:request) do
+ HTTPI::Request.new(@server.url).tap do|r|
+ r.body = request_body if request_body
+ end
+ end
+
+ let(:request_body) { nil }
+
+ let(:response) { HTTPI.request(http_method, request, adapter) }
+
+ shared_examples_for 'any supported custom method' do
+ specify { response.body.should eq http_method.to_s }
+ specify { response.headers["Content-Type"].should eq('text/plain') }
+ end
+
+ context 'PATCH' do
+ let(:http_method) { :patch }
+ let(:request_body) { "<some>xml</some>" }
+
+ it_behaves_like 'any supported custom method'
+ end
+
+ context 'UNSUPPORTED method' do
+ let(:http_method) { :unsupported }
+
+ specify { expect { response }.to raise_error HTTPI::NotSupportedError }
+ end
+ end
+
it "supports basic authentication" do
request = HTTPI::Request.new(@server.url + "basic-auth")
request.auth.basic("admin", "secret")
response = HTTPI.get(request, adapter)
@@ -82,9 +128,20 @@
request = HTTPI::Request.new(@server.url + 'ntlm-auth')
request.auth.ntlm("testing", "failures")
expect { HTTPI.get(request, adapter) }.
to raise_error(HTTPI::NotSupportedError, /Net::NTLM is not available/)
+ end
+
+ it "does not crash when authenticate header is missing (on second request)" do
+ request = HTTPI::Request.new(@server.url + 'ntlm-auth')
+ request.auth.ntlm("tester", "vReqSoafRe5O")
+
+ expect { HTTPI.get(request, adapter) }.
+ to_not raise_error
+
+ expect { HTTPI.get(request, adapter) }.
+ to_not raise_error
end
end
# it does not support digest auth