forked from savonrb/savon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsavon_spec.rb
128 lines (101 loc) · 3.89 KB
/
savon_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require 'spec_helper'
describe Savon do
subject(:client) { Savon.new(wsdl, http_mock) }
let(:wsdl) { fixture('wsdl/amazon') }
let(:service_name) { 'AmazonFPS' }
let(:port_name) { 'AmazonFPSPort' }
let(:operation_name) { 'Pay' }
describe '.http_adapter' do
it 'returns the default HTTP client to use' do
expect(Savon.http_adapter).to eq(Savon::HTTPClient)
end
it 'can be changed to use a custom adapter' do
adapter = mock('http-adapter')
Savon.http_adapter = adapter
expect(Savon.http_adapter).to eq(adapter)
adapter.expects(:new).returns(adapter)
adapter.expects(:client).returns('http-client')
client = Savon.new(wsdl)
expect(client.http).to eq('http-client')
# reset global state!
Savon.http_adapter = nil
end
end
describe '.new' do
it 'expects a local or remote WSDL document' do
Savon::WSDL.expects(:new).with(wsdl, instance_of(Savon.http_adapter)).returns(:wasabi)
Savon.new(wsdl)
end
it 'also accepts a custom HTTP adapter to replace the default' do
http = :my_http_adapter
Savon::WSDL.expects(:new).with(wsdl, http).returns(:wasabi)
Savon.new(wsdl, http)
end
end
describe '#wsdl' do
it 'returns the WSDL' do
expect(client.wsdl).to be_an_instance_of(Savon::WSDL)
end
end
describe '#http' do
it 'returns the HTTP adapter\'s client to configure' do
client = Savon.new(wsdl)
expect(client.http).to be_an_instance_of(HTTPClient)
end
end
describe '#services' do
it 'returns the services and ports defined by the WSDL' do
expect(client.services).to eq(
'AmazonFPS' => {
ports: {
'AmazonFPSPort' => {
type: 'http://schemas.xmlsoap.org/wsdl/soap/',
location: 'https://fps.amazonaws.com'
}
}
}
)
end
end
describe '#operations' do
it 'returns an Array of operations for a service and port' do
operations = client.operations(service_name, port_name)
expect(operations.count).to eq(25)
expect(operations).to include('GetAccountBalance', 'GetTransaction', 'SettleDebt')
end
it 'also accepts symbols for the service and port name' do
operations = client.operations(:AmazonFPS, :AmazonFPSPort)
expect(operations.count).to eq(25)
end
it 'raises if the service could not be found' do
expect { client.operations(:UnknownService, :UnknownPort) }.
to raise_error(ArgumentError, /Unknown service "UnknownService"/)
end
it 'raises if the port could not be found' do
expect { client.operations(service_name, :UnknownPort) }.
to raise_error(ArgumentError, /Unknown service "AmazonFPS" or port "UnknownPort"/)
end
end
describe '#operation' do
it 'returns an Operation by service, port and operation name' do
operation = client.operation(service_name, port_name, operation_name)
expect(operation).to be_a(Savon::Operation)
end
it 'also accepts symbols for the service, port and operation name' do
operation = client.operation(:AmazonFPS, :AmazonFPSPort, :Pay)
expect(operation).to be_a(Savon::Operation)
end
it 'raises if the service could not be found' do
expect { client.operation(:UnknownService, :UnknownPort, :UnknownOperation) }.
to raise_error(ArgumentError, /Unknown service "UnknownService"/)
end
it 'raises if the port could not be found' do
expect { client.operation(service_name, :UnknownPort, :UnknownOperation) }.
to raise_error(ArgumentError, /Unknown service "AmazonFPS" or port "UnknownPort"/)
end
it 'raises if the operation could not be found' do
expect { client.operation(service_name, port_name, :UnknownOperation) }.
to raise_error(ArgumentError, /Unknown operation "UnknownOperation" for service "AmazonFPS" and port "AmazonFPSPort"/)
end
end
end