savon 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGELOG +31 -7
  2. data/README.textile +0 -0
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/lib/savon.rb +0 -0
  6. data/lib/savon/client.rb +6 -1
  7. data/lib/savon/core_ext.rb +0 -0
  8. data/lib/savon/core_ext/datetime.rb +0 -0
  9. data/lib/savon/core_ext/hash.rb +0 -0
  10. data/lib/savon/core_ext/object.rb +0 -0
  11. data/lib/savon/core_ext/string.rb +0 -0
  12. data/lib/savon/core_ext/symbol.rb +0 -0
  13. data/lib/savon/core_ext/uri.rb +0 -0
  14. data/lib/savon/request.rb +5 -0
  15. data/lib/savon/response.rb +0 -0
  16. data/lib/savon/soap.rb +11 -9
  17. data/lib/savon/wsdl.rb +67 -31
  18. data/lib/savon/wsse.rb +0 -0
  19. data/spec/fixtures/multiple_user_response.xml +0 -0
  20. data/spec/fixtures/soap_fault.xml +0 -0
  21. data/spec/fixtures/user_fixture.rb +8 -4
  22. data/spec/fixtures/user_response.xml +0 -0
  23. data/spec/fixtures/user_wsdl.xml +0 -0
  24. data/spec/http_stubs.rb +15 -17
  25. data/spec/savon/client_spec.rb +46 -47
  26. data/spec/savon/core_ext/datetime_spec.rb +0 -0
  27. data/spec/savon/core_ext/hash_spec.rb +0 -0
  28. data/spec/savon/core_ext/object_spec.rb +0 -0
  29. data/spec/savon/core_ext/string_spec.rb +0 -0
  30. data/spec/savon/core_ext/symbol_spec.rb +0 -0
  31. data/spec/savon/core_ext/uri_spec.rb +0 -0
  32. data/spec/savon/request_spec.rb +44 -64
  33. data/spec/savon/response_spec.rb +34 -51
  34. data/spec/savon/savon_spec.rb +13 -19
  35. data/spec/savon/soap_spec.rb +61 -92
  36. data/spec/savon/wsdl_spec.rb +19 -34
  37. data/spec/savon/wsse_spec.rb +42 -58
  38. data/spec/spec_helper.rb +1 -1
  39. data/spec/{spec_helper_methods.rb → spec_helper_classes.rb} +32 -4
  40. metadata +15 -15
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,92 +1,72 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Savon::Request do
4
- before { @request = some_request_instance }
4
+ before { @request = Savon::Request.new EndpointHelper.wsdl_endpoint }
5
5
 
6
- def some_request_instance
7
- Savon::Request.new SpecHelper.some_endpoint
6
+ it "contains the ContentType for each supported SOAP version" do
7
+ Savon::SOAPVersions.each do |soap_version|
8
+ Savon::Request::ContentType[soap_version].should be_a String
9
+ Savon::Request::ContentType[soap_version].should_not be_empty
10
+ end
8
11
  end
9
12
 
10
- def some_soap_instance(options = {})
11
- Savon::SOAP.new UserFixture.soap_actions[:find_user]
12
- end
13
+ # defaults to log request and response. disabled for spec execution
13
14
 
14
- describe "ContentType" do
15
- it "contains the ContentType for each supported SOAP version" do
16
- Savon::SOAPVersions.each do |soap_version|
17
- Savon::Request::ContentType[soap_version].should be_a String
18
- Savon::Request::ContentType[soap_version].should_not be_empty
19
- end
20
- end
15
+ it "has both getter and setter for whether to log (global setting)" do
16
+ Savon::Request.log = true
17
+ Savon::Request.log?.should be_true
18
+ Savon::Request.log = false
19
+ Savon::Request.log?.should be_false
21
20
  end
22
21
 
23
- describe "@log" do
24
- # It defaults to true, but it's turned off for spec execution.
25
-
26
- it "has accessor methods" do
27
- Savon::Request.log = true
28
- Savon::Request.log?.should be_true
29
- Savon::Request.log = false
30
- Savon::Request.log?.should be_false
31
- end
22
+ it "defaults to use a Logger instance for logging" do
23
+ Savon::Request.logger.should be_a Logger
32
24
  end
33
25
 
34
- describe "@logger" do
35
- it "defaults to Logger" do
36
- Savon::Request.logger.should be_a Logger
37
- end
26
+ it "has both getter and setter for the logger to use (global setting)" do
27
+ Savon::Request.logger = nil
28
+ Savon::Request.logger.should be_nil
29
+ Savon::Request.logger = Logger.new STDOUT
30
+ end
38
31
 
39
- it "has accessor methods" do
40
- Savon::Request.logger = nil
41
- Savon::Request.logger.should be_nil
42
- Savon::Request.logger = Logger.new STDOUT
43
- end
32
+ it "defaults to :debug for logging" do
33
+ Savon::Request.log_level.should == :debug
44
34
  end
45
35
 
46
- describe "@log_level" do
47
- it "defaults to :debug" do
48
- Savon::Request.log_level.should == :debug
49
- end
36
+ it "has both getter and setter for the log level to use (global setting)" do
37
+ Savon::Request.log_level = :info
38
+ Savon::Request.log_level.should == :info
39
+ Savon::Request.log_level = :debug
40
+ end
50
41
 
51
- it "has accessor methods" do
52
- Savon::Request.log_level = :info
53
- Savon::Request.log_level.should == :info
54
- Savon::Request.log_level = :debug
55
- end
42
+ it "is initialized with a SOAP endpoint String" do
43
+ Savon::Request.new EndpointHelper.wsdl_endpoint
56
44
  end
57
45
 
58
- describe "initialize" do
59
- it "expects a SOAP endpoint String" do
60
- some_request_instance
61
- end
46
+ it "raises an ArgumentError when initialized with an invalid endpoint" do
47
+ lambda { Savon::Request.new "invalid" }.should raise_error ArgumentError
48
+ end
62
49
 
63
- it "raises an ArgumentError in case of an invaluid endpoint" do
64
- lambda { Savon::Request.new "invalid" }.should raise_error ArgumentError
65
- end
50
+ it "has a getter for the SOAP endpoint URI" do
51
+ @request.endpoint.should == URI(EndpointHelper.wsdl_endpoint)
66
52
  end
67
53
 
68
- describe "endpoint" do
69
- it "returns the SOAP endpoint URI" do
70
- @request.endpoint.should == SpecHelper.some_endpoint_uri
71
- end
54
+ it "has a setter for specifying a read_timeout" do
55
+ @request.read_timeout = 30
72
56
  end
73
57
 
74
- describe "wsdl" do
75
- it "retrieves the WSDL document and returns the Net::HTTPResponse" do
76
- wsdl_response = @request.wsdl
58
+ it "retrieves the WSDL document and returns the Net::HTTPResponse" do
59
+ wsdl_response = @request.wsdl
77
60
 
78
- wsdl_response.should be_a Net::HTTPResponse
79
- wsdl_response.body.should == UserFixture.user_wsdl
80
- end
61
+ wsdl_response.should be_a Net::HTTPResponse
62
+ wsdl_response.body.should == UserFixture.user_wsdl
81
63
  end
82
64
 
83
- describe "soap" do
84
- it "executes a SOAP request and returns the Net::HTTPResponse" do
85
- soap_response = @request.soap some_soap_instance
65
+ it "executes a SOAP request and returns the Net::HTTPResponse" do
66
+ soap_response = @request.soap Savon::SOAP.new
86
67
 
87
- soap_response.should be_a Net::HTTPResponse
88
- soap_response.body.should == UserFixture.user_response
89
- end
68
+ soap_response.should be_a Net::HTTPResponse
69
+ soap_response.body.should == UserFixture.user_response
90
70
  end
91
71
 
92
- end
72
+ end
@@ -1,54 +1,40 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Savon::Response do
4
- before { @response = some_response_instance }
4
+ before { @response = Savon::Response.new http_response_mock }
5
5
 
6
- def some_response_instance
7
- Savon::Response.new http_response_mock
6
+ it "defaults to raises both Savon::SOAPFault and Savon::HTTPError" do
7
+ Savon::Response.raise_errors?.should be_true
8
8
  end
9
9
 
10
- def soap_fault_response_instance
11
- Savon::Response.new http_response_mock(200, UserFixture.soap_fault)
12
- end
13
-
14
- def http_error_response_instance
15
- Savon::Response.new http_response_mock(404, "", "Not found")
16
- end
17
-
18
- describe "@raise_errors" do
19
- it "defaults to true" do
20
- Savon::Response.raise_errors?.should be_true
21
- end
22
-
23
- it "has accessor methods" do
24
- Savon::Response.raise_errors = false
25
- Savon::Response.raise_errors?.should == false
26
- Savon::Response.raise_errors = true
27
- end
10
+ it "has both getter and setter for whether to raise errors (global setting)" do
11
+ Savon::Response.raise_errors = false
12
+ Savon::Response.raise_errors?.should == false
13
+ Savon::Response.raise_errors = true
28
14
  end
29
15
 
30
16
  describe "initialize" do
31
17
  it "expects a Net::HTTPResponse" do
32
- some_response_instance
18
+ Savon::Response.new http_response_mock
33
19
  end
34
20
 
35
21
  it "raises a Savon::SOAPFault in case of a SOAP fault" do
36
- lambda { soap_fault_response_instance }.should raise_error Savon::SOAPFault
22
+ lambda { savon_response_with :soap_fault }.should raise_error Savon::SOAPFault
37
23
  end
38
24
 
39
25
  it "does not raise a Savon::SOAPFault in case the default is turned off" do
40
26
  Savon::Response.raise_errors = false
41
- soap_fault_response_instance
27
+ savon_response_with :soap_fault
42
28
  Savon::Response.raise_errors = true
43
29
  end
44
30
 
45
31
  it "raises a Savon::HTTPError in case of an HTTP error" do
46
- lambda { http_error_response_instance }.should raise_error Savon::HTTPError
32
+ lambda { savon_response_with :http_error }.should raise_error Savon::HTTPError
47
33
  end
48
34
 
49
35
  it "does not raise a Savon::HTTPError in case the default is turned off" do
50
36
  Savon::Response.raise_errors = false
51
- http_error_response_instance
37
+ savon_response_with :http_error
52
38
  Savon::Response.raise_errors = true
53
39
  end
54
40
  end
@@ -61,8 +47,7 @@ describe Savon::Response do
61
47
  end
62
48
 
63
49
  it "returns true in case of a SOAP fault" do
64
- response = soap_fault_response_instance
65
- response.soap_fault?.should be_true
50
+ savon_response_with(:soap_fault).soap_fault?.should be_true
66
51
  end
67
52
 
68
53
  after { Savon::Response.raise_errors = true }
@@ -72,8 +57,8 @@ describe Savon::Response do
72
57
  before { Savon::Response.raise_errors = false }
73
58
 
74
59
  it "returns the SOAP fault message in case of a SOAP fault" do
75
- response = soap_fault_response_instance
76
- response.soap_fault.should == "(soap:Server) Fault occurred while processing."
60
+ savon_response_with(:soap_fault).soap_fault.
61
+ should == "(soap:Server) Fault occurred while processing."
77
62
  end
78
63
 
79
64
  after { Savon::Response.raise_errors = true }
@@ -87,8 +72,7 @@ describe Savon::Response do
87
72
  end
88
73
 
89
74
  it "returns true in case of an HTTP error" do
90
- response = http_error_response_instance
91
- response.http_error?.should be_true
75
+ savon_response_with(:http_error).http_error?.should be_true
92
76
  end
93
77
 
94
78
  after { Savon::Response.raise_errors = true }
@@ -98,36 +82,35 @@ describe Savon::Response do
98
82
  before { Savon::Response.raise_errors = false }
99
83
 
100
84
  it "returns the HTTP error message in case of an HTTP error" do
101
- response = http_error_response_instance
102
- response.http_error.should == "Not found (404)"
85
+ savon_response_with(:http_error).http_error.should == "Not found (404)"
103
86
  end
104
87
 
105
88
  after { Savon::Response.raise_errors = true }
106
89
  end
107
90
 
108
- describe "to_hash" do
109
- it "returns the SOAP response body as a Hash" do
110
- @response.to_hash.should == UserFixture.response_hash
111
- end
91
+ it "can return the SOAP response body as a Hash" do
92
+ @response.to_hash.should == UserFixture.response_hash
112
93
  end
113
94
 
114
- describe "to_xml" do
115
- it "returns the SOAP response body" do
116
- @response.to_xml.should == UserFixture.user_response
117
- end
95
+ it "can return the raw SOAP response body" do
96
+ @response.to_xml.should == UserFixture.user_response
97
+ @response.to_s.should == UserFixture.user_response
118
98
  end
119
99
 
120
- describe "to_s (alias)" do
121
- it "returns the SOAP response body" do
122
- @response.to_s.should == UserFixture.user_response
100
+ def savon_response_with(error_type)
101
+ mock = case error_type
102
+ when :soap_fault then http_response_mock(200, UserFixture.soap_fault)
103
+ when :http_error then http_response_mock(404, "", "Not found")
123
104
  end
105
+ Savon::Response.new mock
124
106
  end
125
107
 
126
- def http_response_mock(code = 200, body = UserFixture.user_response, message = "OK")
127
- http_response_mock = mock "Net::HTTPResponse"
128
- http_response_mock.stubs :code => code.to_s, :message => message,
129
- :content_type => "text/html", :body => body
130
- http_response_mock
108
+ def http_response_mock(code = 200, body = nil, message = "OK")
109
+ body ||= UserFixture.user_response
110
+ mock = mock "Net::HTTPResponse"
111
+ mock.stubs :code => code.to_s, :message => message,
112
+ :content_type => "text/html", :body => body
113
+ mock
131
114
  end
132
115
 
133
- end
116
+ end
@@ -2,29 +2,23 @@ require "spec_helper"
2
2
 
3
3
  describe Savon do
4
4
 
5
- describe "SOAPVersions" do
6
- it "contains an Array of supported SOAP versions" do
7
- Savon::SOAPVersions.should be_an Array
8
- Savon::SOAPVersions.should_not be_empty
9
- end
5
+ it "contains an Array of supported SOAP versions" do
6
+ Savon::SOAPVersions.should be_an Array
7
+ Savon::SOAPVersions.should_not be_empty
10
8
  end
11
9
 
12
- describe "SOAPDateTimeFormat" do
13
- it "contains the xs:dateTime format" do
14
- Savon::SOAPDateTimeFormat.should be_a String
15
- Savon::SOAPDateTimeFormat.should_not be_empty
10
+ it "contains the xs:dateTime format" do
11
+ Savon::SOAPDateTimeFormat.should be_a String
12
+ Savon::SOAPDateTimeFormat.should_not be_empty
16
13
 
17
- UserFixture.datetime_object.strftime(Savon::SOAPDateTimeFormat).
18
- should == UserFixture.datetime_string
19
- end
14
+ UserFixture.datetime_object.strftime(Savon::SOAPDateTimeFormat).
15
+ should == UserFixture.datetime_string
20
16
  end
21
17
 
22
- describe "SOAPDateTimeRegexp" do
23
- it "contains a Regexp matching the xs:dateTime format" do
24
- Savon::SOAPDateTimeRegexp.should be_a Regexp
25
- (Savon::SOAPDateTimeRegexp === UserFixture.datetime_string).
26
- should be_true
27
- end
18
+ it "contains a Regexp matching the xs:dateTime format" do
19
+ Savon::SOAPDateTimeRegexp.should be_a Regexp
20
+ (Savon::SOAPDateTimeRegexp === UserFixture.datetime_string).
21
+ should be_true
28
22
  end
29
23
 
30
- end
24
+ end
@@ -1,146 +1,115 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Savon::SOAP do
4
- before { @soap = some_soap_instance }
5
-
6
- def some_soap_instance
7
- Savon::SOAP.new UserFixture.soap_actions[:find_user]
4
+ before do
5
+ @soap = Savon::SOAP.new
6
+ @soap.action = UserFixture.operations[:find_user][:action]
8
7
  end
9
8
 
10
- describe "SOAPNamespace" do
11
- it "contains the SOAP namespace for each supported SOAP version" do
12
- Savon::SOAPVersions.each do |soap_version|
13
- Savon::SOAP::SOAPNamespace[soap_version].should be_a String
14
- Savon::SOAP::SOAPNamespace[soap_version].should_not be_empty
15
- end
9
+ it "contains the SOAP namespace for each supported SOAP version" do
10
+ Savon::SOAPVersions.each do |soap_version|
11
+ Savon::SOAP::SOAPNamespace[soap_version].should be_a String
12
+ Savon::SOAP::SOAPNamespace[soap_version].should_not be_empty
16
13
  end
17
14
  end
18
15
 
19
- describe "ContentType" do
20
- it "contains the Content-Types for each supported SOAP version" do
21
- Savon::SOAPVersions.each do |soap_version|
22
- Savon::SOAP::ContentType[soap_version].should be_a String
23
- Savon::SOAP::ContentType[soap_version].should_not be_empty
24
- end
16
+ it "contains the Content-Types for each supported SOAP version" do
17
+ Savon::SOAPVersions.each do |soap_version|
18
+ Savon::SOAP::ContentType[soap_version].should be_a String
19
+ Savon::SOAP::ContentType[soap_version].should_not be_empty
25
20
  end
26
21
  end
27
22
 
28
- describe "@version" do
29
- it "defaults to 1" do
30
- Savon::SOAP.version.should == 1
31
- end
32
-
33
- it "has accessor methods" do
34
- [2, 1].each do |soap_version|
35
- Savon::SOAP.version = soap_version
36
- Savon::SOAP.version.should == soap_version
37
- end
38
- end
23
+ it "defaults to SOAP 1.1" do
24
+ Savon::SOAP.version.should == 1
39
25
  end
40
26
 
41
- describe "initialize" do
42
- it "expects a SOAP action map" do
43
- some_soap_instance
27
+ it "has both getter and setter for the SOAP version to use (global setting)" do
28
+ [2, 1].each do |soap_version|
29
+ Savon::SOAP.version = soap_version
30
+ Savon::SOAP.version.should == soap_version
44
31
  end
45
32
  end
46
33
 
47
- describe "wsse" do
48
- it "expects a Savon::WSSE" do
49
- @soap.wsse = Savon::WSSE.new
50
- end
34
+ it "has a setter for the Savon::WSSE" do
35
+ @soap.wsse = Savon::WSSE.new
51
36
  end
52
37
 
53
- describe "action" do
54
- it "is an accessor for the SOAP action" do
55
- @soap.action.should == UserFixture.soap_actions[:find_user][:name]
38
+ it "is has both getter and setter for the SOAP action" do
39
+ @soap.action.should == UserFixture.operations[:find_user][:action]
56
40
 
57
- action = "someAction"
58
- @soap.action = action
59
- @soap.action.should == action
60
- end
41
+ @soap.action = "someAction"
42
+ @soap.action.should == "someAction"
61
43
  end
62
44
 
63
- describe "input" do
64
- it "sets the name of the SOAP input node" do
65
- @soap.input = "FindUserRequest"
66
- end
45
+ it "has a setter for the SOAP input" do
46
+ @soap.input = "FindUserRequest"
67
47
  end
68
48
 
69
- describe "header" do
70
- it "is an accessor for the SOAP header" do
71
- @soap.header.should be_a Hash
72
- @soap.header.should be_empty
49
+ it "has both getter and setter for the SOAP header" do
50
+ @soap.header.should be_a Hash
51
+ @soap.header.should be_empty
73
52
 
74
- header = { "specialAuthKey" => "secret" }
75
- @soap.header = header
76
- @soap.header.should == header
77
- end
53
+ @soap.header = { "specialAuthKey" => "secret" }
54
+ @soap.header.should == { "specialAuthKey" => "secret" }
78
55
  end
79
56
 
80
- describe "body" do
81
- it "expects a SOAP-translatable Hash or an XML String" do
82
- @soap.body = { :id => 666 }
83
- @soap.body = "<id>666</id>"
84
- end
57
+ it "has a getter for the SOAP body, expecting a Hash or an XML String" do
58
+ @soap.body = { :id => 666 }
59
+ @soap.body = "<id>666</id>"
85
60
  end
86
61
 
87
- describe "namespaces" do
88
- it "defaults to a Hash with xmlns:env set to SOAP 1.1" do
89
- soap = some_soap_instance
90
- soap.namespaces.should == { "xmlns:env" => Savon::SOAP::SOAPNamespace[1] }
62
+ it "has a setter for specifying a Hash of namespaces" do
63
+ namespaces = { "xmlns:env" => "http://example.com" }
64
+ @soap.namespaces = namespaces
65
+ @soap.namespaces.should == namespaces
66
+ end
67
+
68
+ describe "has a getter for namespaces" do
69
+ it "which defaults to include the SOAP 1.1 namespace" do
70
+ @soap.namespaces.should == { "xmlns:env" => Savon::SOAP::SOAPNamespace[1] }
91
71
  end
92
72
 
93
- it "contains the xmlns:env for SOAP 1.2 if specified" do
94
- soap = some_soap_instance
95
- soap.version = 2
96
- soap.namespaces.should == { "xmlns:env" => Savon::SOAP::SOAPNamespace[2] }
73
+ it "which contains the SOAP 1.2 namespace if specified" do
74
+ @soap.version = 2
75
+ @soap.namespaces.should == { "xmlns:env" => Savon::SOAP::SOAPNamespace[2] }
97
76
  end
98
77
  end
99
78
 
100
- describe "version" do
101
- it "returns the SOAP version from options" do
102
- soap = some_soap_instance
103
- soap.version = 2
104
- soap.version.should == 2
105
- end
79
+ it "has a getter for the SOAP version to use which defaults to SOAP 1.1" do
80
+ @soap.version.should == Savon::SOAP.version
81
+ end
106
82
 
107
- it "returns the default SOAP version otherwise" do
108
- @soap.version.should == Savon::SOAP.version
109
- end
83
+ it "has a setter for specifying the SOAP version to use" do
84
+ @soap.version = 2
85
+ @soap.version.should == 2
110
86
  end
111
87
 
112
88
  describe "to_xml" do
113
- before { Savon::SOAP.version = 1 }
89
+ after { Savon::SOAP.version = 1 }
114
90
 
115
91
  it "returns the XML for a SOAP request" do
116
- soap = some_soap_instance
117
- soap.namespaces["xmlns:wsdl"] = "http://v1_0.ws.user.example.com"
118
- soap.body = { :id => 666 }
119
- soap.to_xml.should == soap_body
92
+ @soap.namespaces["xmlns:wsdl"] = "http://v1_0.ws.user.example.com"
93
+ @soap.body = { :id => 666 }
94
+
95
+ @soap.to_xml.should include 'xmlns:wsdl="http://v1_0.ws.user.example.com"'
96
+ @soap.to_xml.should include 'xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"'
97
+ @soap.to_xml.should include '<wsdl:findUser><id>666</id></wsdl:findUser>'
120
98
  end
121
99
 
122
100
  it "caches the XML, returning the same Object every time" do
123
101
  @soap.to_xml.object_id.should == @soap.to_xml.object_id
124
102
  end
125
103
 
126
- it "uses the SOAP namespace for the SOAP version passed in via options" do
127
- soap = some_soap_instance
128
- soap.version = 2
129
- soap.to_xml.should include Savon::SOAP::SOAPNamespace[2]
104
+ it "uses the SOAP namespace for the specified SOAP version" do
105
+ @soap.version = 2
106
+ @soap.to_xml.should include Savon::SOAP::SOAPNamespace[2]
130
107
  end
131
108
 
132
109
  it "uses the SOAP namespace for the default SOAP version otherwise" do
133
110
  Savon::SOAP.version = 2
134
111
  @soap.to_xml.should include Savon::SOAP::SOAPNamespace[2]
135
112
  end
136
-
137
- def soap_body
138
- "<env:Envelope xmlns:wsdl=\"http://v1_0.ws.user.example.com\" " <<
139
- "xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">" <<
140
- "<env:Header></env:Header>" <<
141
- "<env:Body><wsdl:findUser><id>666</id></wsdl:findUser></env:Body>" <<
142
- "</env:Envelope>"
143
- end
144
113
  end
145
114
 
146
115
  end