Skip to content

Commit

Permalink
Merge pull request #450 from pigoz/errors_attr_readers
Browse files Browse the repository at this point in the history
Missing getters on Savon::Response soap_fault/soap_error
  • Loading branch information
rubiii committed May 14, 2013
2 parents e36d6e1 + fd0bc3f commit c4b3e48
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## master

* Fix: [#450](https://github.com/savonrb/savon/pull/450) Add back attr_readers Response#soap_fault and Response#http_error

* Feature: [#402](https://github.com/savonrb/savon/issues/402) Makes it possible to create mocks that don't care about the message sent: `savon.expects(:authenticate).with(message: :any)`.

* Feature: [#424](https://github.com/savonrb/savon/issues/424) Adds support for multipart responses
Expand Down
12 changes: 9 additions & 3 deletions lib/savon/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ def initialize(http, globals, locals)
@globals = globals
@locals = locals

build_soap_and_http_errors!
raise_soap_and_http_errors! if @globals[:raise_errors]
end

attr_reader :http, :globals, :locals
attr_reader :http, :globals, :locals, :soap_fault, :http_error

def success?
!soap_fault? && !http_error?
Expand Down Expand Up @@ -66,9 +67,14 @@ def xpath(path, namespaces = nil)

private

def build_soap_and_http_errors!
@soap_fault = SOAPFault.new(@http, nori) if soap_fault?
@http_error = HTTPError.new(@http) if http_error?
end

def raise_soap_and_http_errors!
raise SOAPFault.new(@http, nori) if soap_fault?
raise HTTPError.new(@http) if http_error?
raise soap_fault if soap_fault?
raise http_error if http_error?
end

def raise_invalid_response_error!
Expand Down
24 changes: 24 additions & 0 deletions spec/savon/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
end
end

describe "#soap_fault" do
before { globals[:raise_errors] = false }

it "should return nil in case the response seems to be ok" do
soap_response.soap_fault.should be_nil
end

it "should return a SOAPFault in case of a SOAP fault" do
soap_fault_response.soap_fault.should be_a(Savon::SOAPFault)
end
end

describe "#http_error?" do
before { globals[:raise_errors] = false }

Expand All @@ -65,6 +77,18 @@
end
end

describe "#http_error" do
before { globals[:raise_errors] = false }

it "should return nil in case the response seems to be ok" do
soap_response.http_error.should be_nil
end

it "should return a HTTPError in case of an HTTP error" do
soap_response(:code => 500).http_error.should be_a(Savon::HTTPError)
end
end

describe "#header" do
it "should return the SOAP response header as a Hash" do
response = soap_response :body => Fixture.response(:header)
Expand Down

0 comments on commit c4b3e48

Please sign in to comment.