savon_spec 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +5 -4
- data/lib/savon/spec/mock.rb +6 -0
- data/lib/savon/spec/version.rb +1 -1
- data/spec/savon/spec/mock_spec.rb +35 -24
- metadata +4 -4
data/README.md
CHANGED
@@ -39,6 +39,7 @@ By including the macros, you have access to the `savon` method in your specs. It
|
|
39
39
|
#expects(soap_action) # mocks SOAP request to a given SOAP action
|
40
40
|
#stubs(soap_action) # stubs SOAP requests to a given SOAP action
|
41
41
|
#with(soap_body) # expects Savon to send a given SOAP body
|
42
|
+
#raises_soap_fault # raises or acts like there was a SOAP fault
|
42
43
|
#returns(response) # returns the given response
|
43
44
|
|
44
45
|
### Fixtures
|
@@ -61,10 +62,10 @@ When used inside a Rails 3 application, Savon::Spec uses the command `Rails.root
|
|
61
62
|
|
62
63
|
The directories inside the fixture directory should map to SOAP actions and the XML fixtures inside those directories should describe the SOAP response. Please take a look at the following examples to better understand this convention.
|
63
64
|
|
64
|
-
|
65
|
-
|
65
|
+
An example
|
66
|
+
----------
|
66
67
|
|
67
|
-
|
68
|
+
user.rb
|
68
69
|
|
69
70
|
class User
|
70
71
|
|
@@ -83,7 +84,7 @@ Some examples
|
|
83
84
|
|
84
85
|
end
|
85
86
|
|
86
|
-
|
87
|
+
user_spec.rb
|
87
88
|
|
88
89
|
describe User do
|
89
90
|
|
data/lib/savon/spec/mock.rb
CHANGED
@@ -40,6 +40,12 @@ module Savon
|
|
40
40
|
self
|
41
41
|
end
|
42
42
|
|
43
|
+
# Sets up Savon to respond like there was a SOAP fault.
|
44
|
+
def raises_soap_fault
|
45
|
+
Savon::SOAP::Response.any_instance.expects(:soap_fault?).returns(true)
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
43
49
|
private
|
44
50
|
|
45
51
|
def setup(mock_method, soap_action)
|
data/lib/savon/spec/version.rb
CHANGED
@@ -21,17 +21,13 @@ describe Savon::Spec::Mock do
|
|
21
21
|
client.request :get_user
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should fail" do
|
34
|
-
end
|
24
|
+
it "should fail when no SOAP call was made" do
|
25
|
+
expect { verify_mocks_for_rspec }.to raise_error(
|
26
|
+
Mocha::ExpectationError,
|
27
|
+
/expected exactly once, not yet invoked: HTTPI.post/
|
28
|
+
)
|
29
|
+
|
30
|
+
teardown_mocks_for_rspec
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
@@ -44,18 +40,15 @@ describe Savon::Spec::Mock do
|
|
44
40
|
end
|
45
41
|
end
|
46
42
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
it "should fail" do
|
57
|
-
client.request :get_user
|
58
|
-
end
|
43
|
+
it "should fail when the SOAP body was not send" do
|
44
|
+
client.request(:get_user)
|
45
|
+
|
46
|
+
expect { verify_mocks_for_rspec }.to raise_error(
|
47
|
+
Mocha::ExpectationError,
|
48
|
+
/expected exactly once, not yet invoked: #<AnyInstance:Savon::SOAP::XML>.body=\(:id => 1\)/
|
49
|
+
)
|
50
|
+
|
51
|
+
teardown_mocks_for_rspec
|
59
52
|
end
|
60
53
|
end
|
61
54
|
|
@@ -67,7 +60,8 @@ describe Savon::Spec::Mock do
|
|
67
60
|
end
|
68
61
|
|
69
62
|
it "should not complain about requests not being executed" do
|
70
|
-
|
63
|
+
expect { verify_mocks_for_rspec }.to_not raise_error(Mocha::ExpectationError)
|
64
|
+
teardown_mocks_for_rspec
|
71
65
|
end
|
72
66
|
end
|
73
67
|
|
@@ -163,4 +157,21 @@ describe Savon::Spec::Mock do
|
|
163
157
|
end
|
164
158
|
end
|
165
159
|
|
160
|
+
describe "#with_soap_fault" do
|
161
|
+
before { savon.expects(:get_user).raises_soap_fault.returns }
|
162
|
+
|
163
|
+
it "should raise a SOAP fault" do
|
164
|
+
expect { client.request :get_user }.to raise_error(Savon::SOAP::Fault)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should just act like there was a SOAP fault if raising errors was disabled" do
|
168
|
+
Savon.raise_errors = false
|
169
|
+
|
170
|
+
response = client.request :get_user
|
171
|
+
response.should be_a_soap_fault
|
172
|
+
|
173
|
+
Savon.raise_errors = true # reset to default
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
166
177
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: savon_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Harrington
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-07 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|