spec/cfoundry/errors_spec.rb in cfoundry-0.4.21 vs spec/cfoundry/errors_spec.rb in cfoundry-0.5.0

- old
+ new

@@ -2,27 +2,24 @@ describe 'Errors' do describe CFoundry::Timeout do let(:parent) { Timeout::Error.new } - subject { CFoundry::Timeout.new(Net::HTTP::Post, '/blah', parent) } + subject { CFoundry::Timeout.new("POST", '/blah', parent) } its(:to_s) { should eq "POST /blah timed out" } - its(:method) { should eq Net::HTTP::Post } + its(:method) { should eq "POST" } its(:uri) { should eq '/blah' } its(:parent) { should eq parent } end describe CFoundry::APIError do - let(:request) { Net::HTTP::Get.new("http://api.cloudfoundry.com/foo") } - let(:response) { Net::HTTPNotFound.new("foo", 404, "bar")} + let(:request) { { :method => "GET", :url => "http://api.cloudfoundry.com/foo", :headers => {} } } let(:response_body) { "NOT FOUND" } - subject { CFoundry::APIError.new(request, response) } + let(:response) { { :status => 404, :headers => {}, :body => response_body } } - before do - stub(response).body {response_body} - end + subject { CFoundry::APIError.new(nil, nil, request, response) } its(:to_s) { should eq "404: NOT FOUND" } its(:request) { should eq request } @@ -33,26 +30,26 @@ context "Response body is JSON" do let(:response_body) { "{\"description\":\"Something went wrong\"}"} it "sets description to description field in parsed JSON" do - CFoundry::APIError.new(request, response).description.should == "Something went wrong" + CFoundry::APIError.new(nil, nil, request, response).description.should == "Something went wrong" end end context "Response body is not JSON" do let(:response_body) { "Some plain text"} it "sets description to body text" do - CFoundry::APIError.new(request, response).description.should == "Some plain text" + CFoundry::APIError.new(nil, nil, request, response).description.should == "Some plain text" end end it "allows override of description" do - CFoundry::APIError.new(request, response, "My description").description.should == "My description" + CFoundry::APIError.new("My description", nil, request, response).description.should == "My description" end end describe "#request_trace" do @@ -62,14 +59,14 @@ describe "#response_trace" do its(:response_trace) { should include "RESPONSE: " } end it "sets error code to response error code by default" do - CFoundry::APIError.new(request, response).error_code.should == 404 + CFoundry::APIError.new(nil, nil, request, response).error_code.should == 404 end it "allows override of error code" do - CFoundry::APIError.new(request, response, nil, 303).error_code.should == 303 + CFoundry::APIError.new(nil, 303, request, response).error_code.should == 303 end end end