spec/httpi/adapter/net_http_spec.rb in httpi-2.0.0.rc1 vs spec/httpi/adapter/net_http_spec.rb in httpi-2.0.0

- old
+ new

@@ -1,19 +1,93 @@ require "spec_helper" -require "httpi/adapter/net_http" -require "httpi/request" +require "integration/support/server" -HTTPI::Adapter.load_adapter(:net_http) - describe HTTPI::Adapter::NetHTTP do - let(:net_http) { Net::HTTP.any_instance } - let(:request) { HTTPI::Request.new("http://example.com") } - let(:basic_response) { { :body => Fixture.xml, :headers => { "Accept-encoding" => "utf-8" } } } + subject(:adapter) { :net_http } - let(:adapter) { - HTTPI::Adapter::NetHTTP.new(request) - } + context "http requests" do + before :all do + @server = IntegrationServer.run + end + + after :all do + @server.stop + 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) + response.body.should include("HTTPI") + end + + it "executes GET requests" do + response = HTTPI.get(@server.url, adapter) + response.body.should eq("get") + response.headers["Content-Type"].should eq("text/plain") + end + + it "executes POST requests" do + response = HTTPI.post(@server.url, "<some>xml</some>", adapter) + response.body.should eq("post") + response.headers["Content-Type"].should eq("text/plain") + end + + it "executes HEAD requests" do + response = HTTPI.head(@server.url, adapter) + response.code.should == 200 + response.headers["Content-Type"].should eq("text/plain") + end + + it "executes PUT requests" do + response = HTTPI.put(@server.url, "<some>xml</some>", adapter) + response.body.should eq("put") + response.headers["Content-Type"].should eq("text/plain") + end + + it "executes DELETE requests" do + response = HTTPI.delete(@server.url, adapter) + response.body.should eq("delete") + response.headers["Content-Type"].should eq("text/plain") + end + + it "supports basic authentication" do + request = HTTPI::Request.new(@server.url + "basic-auth") + request.auth.basic("admin", "secret") + + response = HTTPI.get(request, adapter) + response.body.should eq("basic-auth") + end + end + + # it does not support digest auth + + context "https requests" do + before :all do + @server = IntegrationServer.run(:ssl => true) + end + + after :all do + @server.stop + end + + # it does not raise when no certificate was set up + + it "works when set up properly" do + request = HTTPI::Request.new(@server.url) + request.auth.ssl.ca_cert_file = IntegrationServer.ssl_ca_file + + response = HTTPI.get(request, adapter) + expect(response.body).to eq("get") + end + end + +end + + +__END__ describe "#request(:get)" do it "should return a valid HTTPI::Response" do stub_request(:get, request.url.to_s).to_return(basic_response) adapter.request(:get).should match_response(:body => Fixture.xml)