diff --git a/lib/savon/soap/fault.rb b/lib/savon/soap/fault.rb index 7da5a433..421c6287 100644 --- a/lib/savon/soap/fault.rb +++ b/lib/savon/soap/fault.rb @@ -19,7 +19,7 @@ def initialize(http) # Returns whether a SOAP fault is present. def present? - @present ||= http.body =~ // + @present ||= http.body =~ /<(.+:)?Body>(\s*)<(.+:)?Fault>/ end # Returns the SOAP fault message. diff --git a/spec/fixtures/response/response_fixture.rb b/spec/fixtures/response/response_fixture.rb index 55c55020..f36d73d3 100644 --- a/spec/fixtures/response/response_fixture.rb +++ b/spec/fixtures/response/response_fixture.rb @@ -18,6 +18,10 @@ def soap_fault12 @soap_fault12 ||= load_fixture :soap_fault12 end + def another_soap_fault + @another_soap_fault ||= load_fixture :another_soap_fault + end + def multi_ref @multi_ref ||= load_fixture :multi_ref end diff --git a/spec/fixtures/response/xml/another_soap_fault.xml b/spec/fixtures/response/xml/another_soap_fault.xml new file mode 100644 index 00000000..2d70d250 --- /dev/null +++ b/spec/fixtures/response/xml/another_soap_fault.xml @@ -0,0 +1,14 @@ + + + + ERR_NO_SESSION + doGetItemsInfo - Wrong session + Wrong session message + 80:1289245853:55 + + + diff --git a/spec/savon/soap/fault_spec.rb b/spec/savon/soap/fault_spec.rb index 3011840c..10ec3646 100644 --- a/spec/savon/soap/fault_spec.rb +++ b/spec/savon/soap/fault_spec.rb @@ -3,6 +3,7 @@ describe Savon::SOAP::Fault do let(:soap_fault) { Savon::SOAP::Fault.new new_response(:body => ResponseFixture.soap_fault) } let(:soap_fault2) { Savon::SOAP::Fault.new new_response(:body => ResponseFixture.soap_fault12) } + let(:another_soap_fault) { Savon::SOAP::Fault.new new_response(:body => ResponseFixture.another_soap_fault) } let(:no_fault) { Savon::SOAP::Fault.new new_response } it "should be a Savon::Error" do @@ -24,6 +25,10 @@ soap_fault2.should be_present end + it "should return true if the HTTP response contains a SOAP fault with different namespaces" do + another_soap_fault.should be_present + end + it "should return false unless the HTTP response contains a SOAP fault" do no_fault.should_not be_present end @@ -42,6 +47,10 @@ it "should return a SOAP 1.2 fault message" do soap_fault2.send(method).should == "(soap:Sender) Sender Timeout" end + + it "should return a SOAP fault message (with different namespaces)" do + another_soap_fault.send(method).should == "(ERR_NO_SESSION) Wrong session message" + end end end