spec/rapidash/http_client_spec.rb in rapidash-0.2.2 vs spec/rapidash/http_client_spec.rb in rapidash-0.3.0.beta
- old
+ new
@@ -44,66 +44,27 @@
before(:each) do
subject.site = "http://example.com"
end
describe "authorization" do
- let!(:options) { { :login => "login", :password => "password" } }
- let!(:subject) { HTTPTester.new(options) }
+ let!(:subject) { HTTPTester.new(:login => "login", :password => "password") }
- it "should authorize with login and password" do
- subject.should_receive(:process_response).with("response", :get, {})
- subject.connection.should_receive(:basic_auth).with(options[:login], options[:password])
- subject.connection.stub_chain('app.call').and_return("response")
- subject.request(:get, "foo")
+ it "should delegate to Faraday's basic auth" do
+ expect(subject.connection.builder.handlers).to include(Faraday::Request::BasicAuthentication)
end
end
- it "should call response" do
- subject.should_receive(:process_response).with("response", :get, {})
- subject.connection.should_receive(:run_request).with(:get, "http://example.com/foo", nil, nil).and_return("response")
- subject.request(:get, "foo")
- end
- end
+ describe "without authorization" do
+ let!(:subject) { HTTPTester.new() }
- describe ".process_response" do
-
- let!(:valid_response) { OpenStruct.new(:status => "200")}
- let!(:redirect_response) { OpenStruct.new(:status => "301", :headers => {"location" => "http://example.com/redirect"})}
- let!(:error_response) { OpenStruct.new(:status => "404")}
-
- before(:each) do
- subject.site = "http://example.com"
- end
-
- describe "valid response" do
- before(:each) do
- Rapidash::Response.should_receive(:new).and_return("response")
+ it "should delegate to Faraday's basic auth" do
+ expect(subject.connection.builder.handlers).to_not include(Faraday::Request::BasicAuthentication)
end
-
- it "should return a response object" do
- response = subject.process_response(valid_response, :get, {})
- response.should eql("response")
- end
-
- it "should perform a redirect" do
- subject.should_receive(:request).with(:get, "http://example.com/redirect", anything).and_return(subject.process_response(valid_response, :get, {}))
- response = subject.process_response(redirect_response, :get, {})
- response.should eql("response")
- end
end
- describe "error response" do
- it "should not raise an error by default" do
- response = subject.process_response(error_response, :get, {})
- response.should be_nil
- end
-
- it "should raise an error if the option is set" do
- subject = HTTPErrorTester.new
- expect {
- response = subject.process_response(error_response, :get, {})
- }.to raise_error(Rapidash::ResponseError)
- end
-
+ it "should call response" do
+ response = double(:body => "response")
+ subject.connection.should_receive(:run_request).with(:get, "http://example.com/foo", nil, nil).and_return(response)
+ subject.request(:get, "foo")
end
end
end