Skip to content

Commit

Permalink
converted the response for version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiii committed Dec 12, 2012
1 parent 171c8f9 commit 79c74e1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 64 deletions.
2 changes: 1 addition & 1 deletion spec/integration/new_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe "NewClient Integration" do

subject(:client) {
Savon.new_client(:wsdl => service_endpoint, :open_timeout => 3, :read_timeout => 3, :logger => Savon::NullLogger.new)
Savon.new_client(:wsdl => service_endpoint, :open_timeout => 3, :read_timeout => 3, :raise_errors => false, :logger => Savon::NullLogger.new)
}

context "stockquote" do
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ def log(message, options = {})

}

client = new_client(:logger => duck_logger.new)
client = new_client(:endpoint => @server.url, :logger => duck_logger.new)
client.call(:authenticate)

expect(duck_logger.logs).to include("SOAP request: http://example.com/validation/1.0/AuthenticationService")
expect(duck_logger.logs).to include("SOAP request: #{@server.url}")
end
end

Expand Down Expand Up @@ -252,7 +252,7 @@ def log(message, options = {})

}

client = new_client(:logger => duck_logger.new, :pretty_print_xml => true)
client = new_client(:endpoint => @server.url, :logger => duck_logger.new, :pretty_print_xml => true)
client.call(:authenticate)

xml = unindent <<-xml
Expand Down
76 changes: 17 additions & 59 deletions spec/savon/soap/response_spec.rb → spec/savon/response_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
require "spec_helper"

describe Savon::SOAP::Response do
describe Savon::Response do

let(:config) { Savon::Config.default }
let(:globals) { Savon::GlobalOptions.new_with_defaults }
let(:locals) { Savon::LocalOptions.new }

describe ".new" do
it "should raise a Savon::SOAP::Fault in case of a SOAP fault" do
lambda { soap_fault_response }.should raise_error(Savon::SOAP::Fault)
it "should raise a Savon::Fault in case of a SOAP fault" do
lambda { soap_fault_response }.should raise_error(Savon::SOAPFault)
end

it "should not raise a Savon::SOAP::Fault in case the default is turned off" do
config.raise_errors = false
lambda { soap_fault_response }.should_not raise_error(Savon::SOAP::Fault)
it "should not raise a Savon::Fault in case the default is turned off" do
globals[:raise_errors] = false
lambda { soap_fault_response }.should_not raise_error(Savon::SOAPFault)
end

it "should raise a Savon::HTTP::Error in case of an HTTP error" do
lambda { soap_response :code => 500 }.should raise_error(Savon::HTTP::Error)
lambda { soap_response :code => 500 }.should raise_error(Savon::HTTPError)
end

it "should not raise a Savon::HTTP::Error in case the default is turned off" do
config.raise_errors = false
globals[:raise_errors] = false
soap_response :code => 500
end
end

describe "#success?" do
before { config.raise_errors = false }
before { globals[:raise_errors] = false }

it "should return true if the request was successful" do
soap_response.should be_a_success
Expand All @@ -41,7 +42,7 @@
end

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

it "should not return true in case the response seems to be ok" do
soap_response.soap_fault?.should be_false
Expand All @@ -52,24 +53,8 @@
end
end

describe "#soap_fault" do
before { config.raise_errors = false }

it "should return a Savon::SOAP::Fault" do
soap_fault_response.soap_fault.should be_a(Savon::SOAP::Fault)
end

it "should return a Savon::SOAP::Fault containing the HTTPI::Response" do
soap_fault_response.soap_fault.http.should be_an(HTTPI::Response)
end

it "should return a Savon::SOAP::Fault even if the SOAP response seems to be ok" do
soap_response.soap_fault.should be_a(Savon::SOAP::Fault)
end
end

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

it "should not return true in case the response seems to be ok" do
soap_response.http_error?.should_not be_true
Expand All @@ -80,41 +65,14 @@
end
end

describe "#http_error" do
before { config.raise_errors = false }

it "should return a Savon::HTTP::Error" do
http_error_response.http_error.should be_a(Savon::HTTP::Error)
end

it "should return a Savon::HTTP::Error containing the HTTPI::Response" do
http_error_response.http_error.http.should be_an(HTTPI::Response)
end

it "should return a Savon::HTTP::Error even if the HTTP response seems to be ok" do
soap_response.http_error.should be_a(Savon::HTTP::Error)
end
end

describe "#[]" do
it "should return the SOAP response body as a Hash" do
soap_response[:authenticate_response][:return].should ==
Fixture.response_hash(:authentication)[:authenticate_response][:return]
end

it "should throw an exception when the response body isn't parsable" do
lambda { invalid_soap_response.body }.should raise_error Savon::SOAP::InvalidResponseError
end
end

describe "#header" do
it "should return the SOAP response header as a Hash" do
response = soap_response :body => Fixture.response(:header)
response.header.should include(:session_number => "ABCD1234")
end

it "should throw an exception when the response header isn't parsable" do
lambda { invalid_soap_response.header }.should raise_error Savon::SOAP::InvalidResponseError
lambda { invalid_soap_response.header }.should raise_error Savon::InvalidResponseError
end
end

Expand Down Expand Up @@ -204,7 +162,7 @@ def soap_response(options = {})
response = defaults.merge options
http_response = HTTPI::Response.new(response[:code], response[:headers], response[:body])

Savon::SOAP::Response.new(config, http_response)
Savon::Response.new(http_response, globals, locals)
end

def soap_fault_response
Expand All @@ -215,12 +173,12 @@ def http_error_response
soap_response :code => 404, :body => "Not found"
end

def invalid_soap_response(options={})
def invalid_soap_response(options = {})
defaults = { :code => 200, :headers => {}, :body => "I'm not SOAP" }
response = defaults.merge options
http_response = HTTPI::Response.new(response[:code], response[:headers], response[:body])

Savon::SOAP::Response.new(config, http_response)
Savon::Response.new(http_response, globals, locals)
end

end
6 changes: 5 additions & 1 deletion spec/support/fixture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def [](type, fixture)

def response_hash(fixture)
@response_hash ||= {}
@response_hash[fixture] ||= Nori.parse(response(fixture))[:envelope][:body]
@response_hash[fixture] ||= nori.parse(response(fixture))[:envelope][:body]
end

TYPES.each do |type, ext|
Expand All @@ -19,6 +19,10 @@ def response_hash(fixture)

private

def nori
Nori.new(:strip_namespaces => true, :convert_tags_to => lambda { |tag| tag.snakecase.to_sym })
end

def fixtures(type)
@fixtures ||= {}
@fixtures[type] ||= {}
Expand Down

0 comments on commit 79c74e1

Please sign in to comment.