savon 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Savon
2
2
 
3
- Version = "0.9.9"
3
+ Version = "0.9.10"
4
4
 
5
5
  end
@@ -23,13 +23,10 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency "gyoku", ">= 0.4.0"
24
24
  s.add_dependency "nokogiri", ">= 1.4.0"
25
25
 
26
- s.add_development_dependency "rake", "~> 0.8.7"
27
- s.add_development_dependency "rspec", "~> 2.5.0"
28
- s.add_development_dependency "mocha", "~> 0.9.8"
29
- s.add_development_dependency "timecop", "~> 0.3.5"
30
-
31
- s.add_development_dependency "autotest"
32
- s.add_development_dependency "ZenTest", "= 4.5.0"
26
+ s.add_development_dependency "rake", "~> 0.9"
27
+ s.add_development_dependency "rspec", "~> 2.10"
28
+ s.add_development_dependency "mocha", "~> 0.11"
29
+ s.add_development_dependency "timecop", "~> 0.3"
33
30
 
34
31
  s.files = `git ls-files`.split("\n")
35
32
  s.require_path = "lib"
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe "webservicex/stockquote" do
4
+
5
+ it "returns the result in a CDATA tag" do
6
+ client = Savon.client("http://www.webservicex.net/stockquote.asmx?WSDL")
7
+ response = client.request(:get_quote, :body => { :symbol => "AAPL" })
8
+
9
+ cdata = response[:get_quote_response][:get_quote_result]
10
+ result = Nori.parse(cdata)
11
+ result[:stock_quotes][:stock][:symbol].should == "AAPL"
12
+ end
13
+
14
+ end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe Savon::Config do
4
+
5
+ describe "#clone" do
6
+ subject do
7
+ config = Savon::Config.new
8
+ config.logger = Savon::Logger.new
9
+ config
10
+ end
11
+
12
+ it "clones the logger" do
13
+ logger = subject.logger
14
+ clone = subject.clone
15
+
16
+ logger.should_not equal(clone.logger)
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+
3
+ describe Savon::Logger do
4
+
5
+ let(:logger) { subject }
6
+ let(:message) { "<?xml version='1.0'?><hello>world</hello>" }
7
+ let(:pretty_message) { Nokogiri::XML(message) }
8
+ let(:filtered_message) { Nokogiri::XML("<?xml version='1.0'?><hello>***FILTERED***</hello>") }
9
+
10
+ it "logs a given message" do
11
+ logger.subject.expects(logger.level).with(message)
12
+ logger.log(message)
13
+ end
14
+
15
+ it "logs a given message (pretty)" do
16
+ logger.subject.expects(logger.level).with(pretty_message.to_xml(:indent => 2))
17
+ logger.log(message, :pretty => true)
18
+ end
19
+
20
+ it "logs a given message (filtered)" do
21
+ logger.subject.expects(logger.level).with(filtered_message.to_s)
22
+ logger.filter << :hello
23
+ warn logger.log(message, :filter => true)
24
+ end
25
+
26
+ it "logs a given message (pretty and filtered)" do
27
+ logger.subject.expects(logger.level).with(filtered_message.to_xml(:indent => 2))
28
+ logger.filter << :hello
29
+ warn logger.log(message, :pretty => true, :filter => true)
30
+ end
31
+
32
+ it "defaults to wrap the standard Logger" do
33
+ logger.subject.should be_a(Logger)
34
+ end
35
+
36
+ it "can be configured to use a different Logger" do
37
+ MyLogger = Object.new
38
+ logger.subject = MyLogger
39
+ logger.subject.should == MyLogger
40
+ end
41
+
42
+ it "defaults to the :debug log level" do
43
+ logger.level.should == :debug
44
+ end
45
+
46
+ it "can be configured to use a different log level" do
47
+ logger.level = :info
48
+ logger.level.should == :info
49
+ end
50
+
51
+ end
@@ -13,11 +13,11 @@ describe Savon::Model do
13
13
  end
14
14
 
15
15
  after do
16
- Savon.hooks.reject! :test_hook
16
+ Savon.config.hooks.reject! :test_hook
17
17
  end
18
18
 
19
19
  it "can be used for pre-processing SOAP responses" do
20
- Savon.hooks.define(:test_hook, :model_soap_response) do |response|
20
+ Savon.config.hooks.define(:test_hook, :model_soap_response) do |response|
21
21
  "hello #{response}"
22
22
  end
23
23
 
@@ -37,6 +37,15 @@ describe Savon::Model do
37
37
 
38
38
  end
39
39
 
40
+ describe ".config" do
41
+
42
+ it "memoizes a clone of the global config" do
43
+ model.config.should be_a(Savon::Config)
44
+ model.config.should_not equal(Savon.config)
45
+ end
46
+
47
+ end
48
+
40
49
  describe ".endpoint" do
41
50
 
42
51
  it "sets the SOAP endpoint" do
@@ -2,105 +2,31 @@ require "spec_helper"
2
2
 
3
3
  describe Savon do
4
4
 
5
- describe ".configure" do
6
- around do |example|
7
- Savon.reset_config!
8
- example.run
9
- Savon.reset_config!
10
- Savon.log = false # disable logging
11
- end
12
-
13
- describe "log" do
14
- it "should default to true" do
15
- Savon.log?.should be_true
16
- end
17
-
18
- it "should set whether to log HTTP requests" do
19
- Savon.configure { |config| config.log = false }
20
- Savon.log?.should be_false
21
- end
22
-
23
- context "when instructed to filter" do
24
- before do
25
- Savon.log = true
26
- end
27
-
28
- context "and no log filter set" do
29
- it "should not filter the message" do
30
- Savon.logger.expects(Savon.log_level).with(Fixture.response(:authentication))
31
- Savon.log(Fixture.response(:authentication), :filter)
32
- end
33
- end
34
-
35
- context "and multiple log filters" do
36
- before do
37
- Savon.configure { |config| config.log_filter = ["logType", "logTime"] }
38
- end
39
-
40
- it "should filter element values" do
41
- filtered_values = /Notes Log|2010-09-21T18:22:01|2010-09-21T18:22:07/
42
-
43
- Savon.logger.expects(Savon.log_level).with do |msg|
44
- msg !~ filtered_values &&
45
- msg.include?('<ns10:logTime>***FILTERED***</ns10:logTime>') &&
46
- msg.include?('<ns10:logType>***FILTERED***</ns10:logType>') &&
47
- msg.include?('<ns11:logTime>***FILTERED***</ns11:logTime>') &&
48
- msg.include?('<ns11:logType>***FILTERED***</ns11:logType>')
49
- end
50
-
51
- Savon.log(Fixture.response(:list), :filter)
52
- end
53
- end
54
- end
55
- end
5
+ it "provides a shortcut for creating a new client" do
6
+ Savon.client("http://example.com").should be_a(Savon::Client)
7
+ end
56
8
 
57
- describe "logger" do
58
- it "should set the logger to use" do
59
- MyLogger = Class.new
60
- Savon.configure { |config| config.logger = MyLogger }
61
- Savon.logger.should == MyLogger
62
- end
9
+ it "memoizes the global config" do
10
+ Savon.config.should equal(Savon.config)
11
+ end
63
12
 
64
- it "should default to Logger writing to STDOUT" do
65
- Savon.logger.should be_a(Logger)
66
- end
13
+ it "yields the global config to a block" do
14
+ Savon.configure do |config|
15
+ config.should equal(Savon.config)
67
16
  end
17
+ end
68
18
 
69
- describe "log_level" do
70
- it "should default to :debug" do
71
- Savon.log_level.should == :debug
72
- end
73
-
74
- it "should set the log level to use" do
75
- Savon.configure { |config| config.log_level = :info }
76
- Savon.log_level.should == :info
77
- end
19
+ describe ".config" do
20
+ it "defaults to a log facade" do
21
+ Savon.config.logger.should be_a(Savon::Logger)
78
22
  end
79
23
 
80
- describe "raise_errors" do
81
- it "should default to true" do
82
- Savon.raise_errors?.should be_true
83
- end
84
-
85
- it "should not raise errors when disabled" do
86
- Savon.raise_errors = false
87
- Savon.raise_errors?.should be_false
88
- end
24
+ it "defaults to raise errors" do
25
+ Savon.config.raise_errors.should be_true
89
26
  end
90
27
 
91
- describe "soap_version" do
92
- it "should default to SOAP 1.1" do
93
- Savon.soap_version.should == 1
94
- end
95
-
96
- it "should return 2 if set to SOAP 1.2" do
97
- Savon.soap_version = 2
98
- Savon.soap_version.should == 2
99
- end
100
-
101
- it "should raise an ArgumentError in case of an invalid version" do
102
- lambda { Savon.soap_version = 3 }.should raise_error(ArgumentError)
103
- end
28
+ it "defaults to SOAP 1.1" do
29
+ Savon.config.soap_version.should == 1
104
30
  end
105
31
  end
106
32
 
@@ -1,8 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Savon::SOAP::Request do
4
- let(:soap_request) { Savon::SOAP::Request.new HTTPI::Request.new, soap }
5
- let(:soap) { Savon::SOAP::XML.new Endpoint.soap, [nil, :get_user, {}], :id => 1 }
4
+ let(:soap_request) { Savon::SOAP::Request.new(config, http_request, soap) }
5
+ let(:http_request) { HTTPI::Request.new }
6
+ let(:soap) { Savon::SOAP::XML.new config, Endpoint.soap, [nil, :get_user, {}], :id => 1 }
7
+ let(:config) { Savon::Config.default }
6
8
 
7
9
  it "contains the content type for each supported SOAP version" do
8
10
  content_type = Savon::SOAP::Request::ContentType
@@ -13,7 +15,7 @@ describe Savon::SOAP::Request do
13
15
  describe ".execute" do
14
16
  it "executes a SOAP request and returns the response" do
15
17
  HTTPI.expects(:post).returns(HTTPI::Response.new 200, {}, Fixture.response(:authentication))
16
- response = Savon::SOAP::Request.execute HTTPI::Request.new, soap
18
+ response = Savon::SOAP::Request.execute config, http_request, soap
17
19
  response.should be_a(Savon::SOAP::Response)
18
20
  end
19
21
  end
@@ -42,11 +44,11 @@ describe Savon::SOAP::Request do
42
44
 
43
45
  it "sets the Content-Length header for every request" do
44
46
  http = HTTPI::Request.new
45
- soap_request = Savon::SOAP::Request.new(http, soap)
47
+ soap_request = Savon::SOAP::Request.new(config, http, soap)
46
48
  http.headers.should include("Content-Length" => "272")
47
49
 
48
- soap = Savon::SOAP::XML.new Endpoint.soap, [nil, :create_user, {}], :id => 123
49
- soap_request = Savon::SOAP::Request.new(http, soap)
50
+ soap = Savon::SOAP::XML.new config, Endpoint.soap, [nil, :create_user, {}], :id => 123
51
+ soap_request = Savon::SOAP::Request.new(config, http, soap)
50
52
  http.headers.should include("Content-Length" => "280")
51
53
  end
52
54
  end
@@ -56,16 +58,6 @@ describe Savon::SOAP::Request do
56
58
  HTTPI.expects(:post).returns(HTTPI::Response.new 200, {}, Fixture.response(:authentication))
57
59
  soap_request.response.should be_a(Savon::SOAP::Response)
58
60
  end
59
-
60
- it "logs the filtered SOAP request body" do
61
- HTTPI.stubs(:post).returns(HTTPI::Response.new 200, {}, "")
62
-
63
- Savon.stubs(:log).times(2)
64
- Savon.expects(:log).with(soap.to_xml, :filter)
65
- Savon.stubs(:log).times(2)
66
-
67
- soap_request.response
68
- end
69
61
  end
70
62
 
71
63
  end
@@ -2,15 +2,16 @@ require "spec_helper"
2
2
 
3
3
  describe Savon::SOAP::Response do
4
4
 
5
+ let(:config) { Savon::Config.default }
6
+
5
7
  describe ".new" do
6
8
  it "should raise a Savon::SOAP::Fault in case of a SOAP fault" do
7
9
  lambda { soap_fault_response }.should raise_error(Savon::SOAP::Fault)
8
10
  end
9
11
 
10
12
  it "should not raise a Savon::SOAP::Fault in case the default is turned off" do
11
- Savon.raise_errors = false
13
+ config.raise_errors = false
12
14
  lambda { soap_fault_response }.should_not raise_error(Savon::SOAP::Fault)
13
- Savon.raise_errors = true
14
15
  end
15
16
 
16
17
  it "should raise a Savon::HTTP::Error in case of an HTTP error" do
@@ -18,18 +19,13 @@ describe Savon::SOAP::Response do
18
19
  end
19
20
 
20
21
  it "should not raise a Savon::HTTP::Error in case the default is turned off" do
21
- Savon.raise_errors = false
22
+ config.raise_errors = false
22
23
  soap_response :code => 500
23
- Savon.raise_errors = true
24
24
  end
25
25
  end
26
26
 
27
27
  describe "#success?" do
28
- around do |example|
29
- Savon.raise_errors = false
30
- example.run
31
- Savon.raise_errors = true
32
- end
28
+ before { config.raise_errors = false }
33
29
 
34
30
  it "should return true if the request was successful" do
35
31
  soap_response.should be_a_success
@@ -45,11 +41,7 @@ describe Savon::SOAP::Response do
45
41
  end
46
42
 
47
43
  describe "#soap_fault?" do
48
- around do |example|
49
- Savon.raise_errors = false
50
- example.run
51
- Savon.raise_errors = true
52
- end
44
+ before { config.raise_errors = false }
53
45
 
54
46
  it "should not return true in case the response seems to be ok" do
55
47
  soap_response.soap_fault?.should be_false
@@ -61,11 +53,7 @@ describe Savon::SOAP::Response do
61
53
  end
62
54
 
63
55
  describe "#soap_fault" do
64
- around do |example|
65
- Savon.raise_errors = false
66
- example.run
67
- Savon.raise_errors = true
68
- end
56
+ before { config.raise_errors = false }
69
57
 
70
58
  it "should return a Savon::SOAP::Fault" do
71
59
  soap_fault_response.soap_fault.should be_a(Savon::SOAP::Fault)
@@ -81,11 +69,7 @@ describe Savon::SOAP::Response do
81
69
  end
82
70
 
83
71
  describe "#http_error?" do
84
- around do |example|
85
- Savon.raise_errors = false
86
- example.run
87
- Savon.raise_errors = true
88
- end
72
+ before { config.raise_errors = false }
89
73
 
90
74
  it "should not return true in case the response seems to be ok" do
91
75
  soap_response.http_error?.should_not be_true
@@ -97,11 +81,7 @@ describe Savon::SOAP::Response do
97
81
  end
98
82
 
99
83
  describe "#http_error" do
100
- around do |example|
101
- Savon.raise_errors = false
102
- example.run
103
- Savon.raise_errors = true
104
- end
84
+ before { config.raise_errors = false }
105
85
 
106
86
  it "should return a Savon::HTTP::Error" do
107
87
  http_error_response.http_error.should be_a(Savon::HTTP::Error)
@@ -217,8 +197,9 @@ describe Savon::SOAP::Response do
217
197
  def soap_response(options = {})
218
198
  defaults = { :code => 200, :headers => {}, :body => Fixture.response(:authentication) }
219
199
  response = defaults.merge options
200
+ http_response = HTTPI::Response.new(response[:code], response[:headers], response[:body])
220
201
 
221
- Savon::SOAP::Response.new HTTPI::Response.new(response[:code], response[:headers], response[:body])
202
+ Savon::SOAP::Response.new(config, http_response)
222
203
  end
223
204
 
224
205
  def soap_fault_response
@@ -230,10 +211,11 @@ describe Savon::SOAP::Response do
230
211
  end
231
212
 
232
213
  def invalid_soap_response(options={})
233
- defaults = { :code => 200, :headers => {}, :body => "I'm not SOAP" }
214
+ defaults = { :code => 200, :headers => {}, :body => "I'm not SOAP" }
234
215
  response = defaults.merge options
216
+ http_response = HTTPI::Response.new(response[:code], response[:headers], response[:body])
235
217
 
236
- Savon::SOAP::Response.new HTTPI::Response.new(response[:code], response[:headers], response[:body])
218
+ Savon::SOAP::Response.new(config, http_response)
237
219
  end
238
220
 
239
221
  end
@@ -1,11 +1,12 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Savon::SOAP::XML do
4
- let(:xml) { Savon::SOAP::XML.new Endpoint.soap, [nil, :authenticate, {}], :id => 1 }
4
+ let(:xml) { Savon::SOAP::XML.new(config, Endpoint.soap, [nil, :authenticate, {}], :id => 1) }
5
+ let(:config) { Savon::Config.default }
5
6
 
6
7
  describe ".new" do
7
8
  it "should accept an endpoint, an input tag and a SOAP body" do
8
- xml = Savon::SOAP::XML.new Endpoint.soap, [nil, :authentication, {}], :id => 1
9
+ xml = Savon::SOAP::XML.new(config, Endpoint.soap, [nil, :authentication, {}], :id => 1)
9
10
 
10
11
  xml.endpoint.should == Endpoint.soap
11
12
  xml.input.should == [nil, :authentication, {}]
@@ -33,10 +34,8 @@ describe Savon::SOAP::XML do
33
34
  end
34
35
 
35
36
  it "should default to the global default" do
36
- Savon.soap_version = 2
37
+ config.soap_version = 2
37
38
  xml.version.should == 2
38
-
39
- reset_soap_version
40
39
  end
41
40
 
42
41
  it "should set the SOAP version to use" do
@@ -60,7 +59,7 @@ describe Savon::SOAP::XML do
60
59
  end
61
60
 
62
61
  it "should use the global soap_header if set" do
63
- Savon.stubs(:soap_header).returns({ "MySecret" => "abc" })
62
+ config.stubs(:soap_header).returns({ "MySecret" => "abc" })
64
63
  xml.header.should == { "MySecret" => "abc" }
65
64
  end
66
65
  end
@@ -76,7 +75,7 @@ describe Savon::SOAP::XML do
76
75
  end
77
76
 
78
77
  it "should use the global env_namespace if set as the SOAP envelope namespace" do
79
- Savon.stubs(:env_namespace).returns(:soapenv)
78
+ config.stubs(:env_namespace).returns(:soapenv)
80
79
  xml.env_namespace.should == :soapenv
81
80
  end
82
81
  end
@@ -156,8 +155,6 @@ describe Savon::SOAP::XML do
156
155
  end
157
156
 
158
157
  describe "#to_xml" do
159
- after { reset_soap_version }
160
-
161
158
  context "by default" do
162
159
  it "should start with an XML declaration" do
163
160
  xml.to_xml.should match(/^<\?xml version="1.0" encoding="UTF-8"\?>/)
@@ -208,34 +205,42 @@ describe Savon::SOAP::XML do
208
205
  end
209
206
 
210
207
  context "with a SOAP header" do
211
- it "should contain the given header" do
212
- xml.header = {
213
- :token => "secret",
214
- :attributes! => { :token => { :xmlns => "http://example.com" } }
215
- }
208
+ context "as a Hash" do
209
+ it "should contain the given header" do
210
+ xml.header = {
211
+ :token => "secret",
212
+ :attributes! => { :token => { :xmlns => "http://example.com" } }
213
+ }
214
+
215
+ xml.to_xml.should include('<env:Header><token xmlns="http://example.com">secret</token></env:Header>')
216
+ end
217
+ end
216
218
 
217
- xml.to_xml.should include('<env:Header><token xmlns="http://example.com">secret</token></env:Header>')
219
+ context "as a String" do
220
+ it "should contain the given header" do
221
+ xml.header = %{<token xmlns="http://example.com">secret</token>}
222
+
223
+ xml.to_xml.should include('<env:Header><token xmlns="http://example.com">secret</token></env:Header>')
224
+ end
218
225
  end
219
226
  end
220
227
 
221
228
  context "with the global SOAP version set to 1.2" do
222
229
  it "should contain the namespace for SOAP 1.2" do
223
- Savon.soap_version = 2
230
+ config.soap_version = 2
224
231
 
225
232
  uri = "http://www.w3.org/2003/05/soap-envelope"
226
233
  xml.to_xml.should match(/<env:Envelope (.*)xmlns:env="#{uri}"(.*)>/)
227
- reset_soap_version
228
234
  end
229
235
  end
230
236
 
231
237
  context "with a global and request SOAP version" do
232
238
  it "should contain the namespace for the request SOAP version" do
233
- Savon.soap_version = 2
239
+ config.soap_version = 2
234
240
  xml.version = 1
235
241
 
236
242
  uri = "http://schemas.xmlsoap.org/soap/envelope/"
237
243
  xml.to_xml.should match(/<env:Envelope (.*)xmlns:env="#{uri}"(.*)>/)
238
- reset_soap_version
239
244
  end
240
245
  end
241
246
 
@@ -256,7 +261,7 @@ describe Savon::SOAP::XML do
256
261
 
257
262
  context "with :element_form_default set to :qualified and a :namespace" do
258
263
  let :xml do
259
- Savon::SOAP::XML.new Endpoint.soap, [nil, :authenticate, {}], :user => { :id => 1, ":noNamespace" => true }
264
+ Savon::SOAP::XML.new(config, Endpoint.soap, [nil, :authenticate, {}], :user => { :id => 1, ":noNamespace" => true })
260
265
  end
261
266
 
262
267
  it "should namespace the default elements" do
@@ -318,9 +323,5 @@ describe Savon::SOAP::XML do
318
323
  end
319
324
  end
320
325
 
321
- def reset_soap_version
322
- Savon.soap_version = Savon::SOAP::DefaultVersion
323
- end
324
-
325
326
  end
326
327