cobot_client 4.0.0 → 6.0.0

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.
@@ -1,133 +1,96 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe CobotClient::ApiClient do
4
- let(:api_client) { CobotClient::ApiClient.new('token-123') }
5
- let(:default_response) { double(:default_response, code: 200, body: '{}') }
6
-
7
- before(:each) do
8
- CobotClient::ApiClient.user_agent = 'test agent'
9
- CobotClient::ApiClient.retry_time = 0
10
- end
11
-
12
- context 'listing resources' do
13
- it 'calls rest client' do
14
- expect(RestClient).to receive(:get).with('https://co-up.cobot.me/api/resources',
15
- hash_including('Authorization' => 'Bearer token-123')) { default_response }
16
-
17
- api_client.get_resources 'co-up'
18
- end
19
-
20
- it 'returns the json' do
21
- allow(RestClient).to receive(:get) { double(:response, body: [{id: 'resource-1'}].to_json) }
22
-
23
- resources = api_client.get_resources 'co-up'
24
-
25
- expect(resources).to eql([{id: 'resource-1'}])
26
- end
27
- end
28
-
29
- context 'creating a booking' do
30
- it 'calls rest client' do
31
- expect(RestClient).to receive(:post).with(
32
- 'https://co-up.cobot.me/api/resources/res-1/bookings',
33
- {title: 'meeting'}.to_json,
34
- hash_including('Authorization' => 'Bearer token-123')) { default_response }
35
-
36
- api_client.create_booking 'co-up', 'res-1', title: 'meeting'
37
- end
38
-
39
- it 'returns the json' do
40
- allow(RestClient).to receive(:post) { double(:response,
41
- code: 201, body: {title: 'meeting'}.to_json) }
42
-
43
- booking = api_client.create_booking 'co-up', 'res-1', title: 'meeting'
44
-
45
- expect(booking).to eql({title: 'meeting'})
46
- end
47
- end
48
-
49
- context 'updating a booking' do
50
- it 'calls rest client' do
51
- expect(RestClient).to receive(:put).with('https://co-up.cobot.me/api/bookings/booking-1',
52
- {title: 'meeting'}.to_json,
53
- hash_including('Authorization' => 'Bearer token-123')) { default_response }
54
-
55
- api_client.update_booking 'co-up', 'booking-1', title: 'meeting'
56
- end
57
-
58
- it 'returns the json' do
59
- allow(RestClient).to receive(:put) { double(:response, code: 200,
60
- body: {title: 'meeting'}.to_json) }
6
+ let(:api_client) { described_class.new('token-123') }
7
+ let(:default_response) { {status: 200, body: '{}'} }
61
8
 
62
- booking = api_client.update_booking 'co-up', 'booking-1', title: 'meeting'
9
+ def cobot_client_response(code:, body: '')
10
+ net_http_response = Net::HTTPResponse.new('1.1', code.to_s, nil)
11
+ net_http_response.body = body
12
+ net_http_response.instance_variable_set(:@read, true)
63
13
 
64
- expect(booking).to eql({title: 'meeting'})
65
- end
14
+ CobotClient::Response.new(net_http_response)
66
15
  end
67
16
 
68
- context 'deleting a booking' do
69
- it 'calls rest client' do
70
- expect(RestClient).to receive(:delete).with('https://co-up.cobot.me/api/bookings/booking-1',
71
- hash_including('Authorization' => 'Bearer token-123')) { default_response }
72
-
73
- api_client.delete_booking 'co-up', 'booking-1'
74
- end
17
+ before do
18
+ described_class.user_agent = 'test agent'
19
+ described_class.retry_time = 0
75
20
  end
76
21
 
77
- context '#put' do
78
- it 'calls rest client' do
79
- expect(RestClient).to receive(:put).with(
80
- 'https://co-up.cobot.me/api/invoices',
81
- {id: '1'}.to_json,
82
- 'Content-Type' => 'application/json',
83
- 'User-Agent' => 'test agent',
84
- 'Authorization' => 'Bearer token-123') { default_response }
22
+ describe '#put' do
23
+ it 'accepts a subdomain' do
24
+ request = stub_request(:put, 'https://co-up.cobot.me/api/invoices')
25
+ .with(
26
+ body: {id: '1'}.to_json,
27
+ headers: {
28
+ 'Content-Type' => 'application/json',
29
+ 'User-Agent' => 'test agent',
30
+ 'Authorization' => 'Bearer token-123'
31
+ }
32
+ )
33
+ .and_return(default_response)
85
34
 
86
35
  api_client.put 'co-up', '/invoices', {id: '1'}
36
+
37
+ expect(request).to have_been_made.once
87
38
  end
88
39
 
89
40
  it 'passes an array as body' do
90
- expect(RestClient).to receive(:put).with(
91
- 'https://co-up.cobot.me/api/invoices',
92
- [{id: '1'}].to_json,
93
- 'Content-Type' => 'application/json',
94
- 'User-Agent' => 'test agent',
95
- 'Authorization' => 'Bearer token-123') { default_response }
41
+ request = stub_request(:put, 'https://co-up.cobot.me/api/invoices')
42
+ .with(
43
+ body: [{id: '1'}].to_json,
44
+ headers: {
45
+ 'Content-Type' => 'application/json',
46
+ 'User-Agent' => 'test agent',
47
+ 'Authorization' => 'Bearer token-123'
48
+ }
49
+ )
50
+ .and_return(default_response)
96
51
 
97
52
  api_client.put 'co-up', '/invoices', [{id: '1'}]
53
+
54
+ expect(request).to have_been_made.once
98
55
  end
99
56
 
100
57
  it 'accepts a url' do
101
- expect(RestClient).to receive(:put).with(
102
- 'https://co-up.cobot.me/api/invoices',
103
- {id: '1'}.to_json,
104
- 'Content-Type' => 'application/json',
105
- 'User-Agent' => 'test agent',
106
- 'Authorization' => 'Bearer token-123') { default_response }
58
+ request = stub_request(:put, 'https://co-up.cobot.me/api/invoices')
59
+ .with(
60
+ body: {id: '1'}.to_json,
61
+ headers: {
62
+ 'Content-Type' => 'application/json',
63
+ 'User-Agent' => 'test agent',
64
+ 'Authorization' => 'Bearer token-123'
65
+ }
66
+ )
67
+ .and_return(default_response)
107
68
 
108
69
  api_client.put 'https://co-up.cobot.me/api/invoices', {id: '1'}
70
+
71
+ expect(request).to have_been_made.once
109
72
  end
110
73
 
111
74
  it 'returns the response json' do
112
- allow(RestClient).to receive(:put) { double(:response, code: 200, body: [{number: 1}].to_json) }
75
+ allow_any_instance_of(CobotClient::Request).to receive(:submit) { cobot_client_response(code: 200, body: [{number: 1}].to_json) }
113
76
 
114
77
  expect(api_client.put('co-up', '/invoices', {})).to eql([{number: 1}])
115
78
  end
116
79
 
117
80
  it 'returns nil when the status code is 204' do
118
- allow(RestClient).to receive(:put) { double(:response, body: '', code: 204) }
81
+ allow_any_instance_of(CobotClient::Request).to receive(:submit) { cobot_client_response(body: '', code: 204) }
119
82
 
120
83
  expect(api_client.put('co-up', '/invoices', {})).to be_nil
121
84
  end
122
85
 
123
86
  it 'retries a 502 error' do
124
- @times = 0
125
- allow(RestClient).to receive(:put) do
126
- if @times < 3
127
- @times += 1
128
- fail RestClient::BadGateway
87
+ times = 0
88
+ allow_any_instance_of(CobotClient::Request).to receive(:submit) do
89
+ if times < 3
90
+ times += 1
91
+ cobot_client_response(code: 502)
129
92
  else
130
- double(code: 200, body: {success: true}.to_json)
93
+ cobot_client_response(code: 200, body: {success: true}.to_json)
131
94
  end
132
95
  end
133
96
 
@@ -135,49 +98,61 @@ describe CobotClient::ApiClient do
135
98
  end
136
99
  end
137
100
 
138
- context '#patch' do
139
- it 'calls rest client' do
140
- expect(RestClient).to receive(:patch).with(
141
- 'https://co-up.cobot.me/api/invoices',
142
- {id: '1'}.to_json,
143
- 'Content-Type' => 'application/json',
144
- 'User-Agent' => 'test agent',
145
- 'Authorization' => 'Bearer token-123') { default_response }
101
+ describe '#patch' do
102
+ it 'accepts a subdomain' do
103
+ request = stub_request(:patch, 'https://co-up.cobot.me/api/invoices')
104
+ .with(
105
+ body: {id: '1'}.to_json,
106
+ headers: {
107
+ 'Content-Type' => 'application/json',
108
+ 'User-Agent' => 'test agent',
109
+ 'Authorization' => 'Bearer token-123'
110
+ }
111
+ )
112
+ .and_return(default_response)
146
113
 
147
114
  api_client.patch 'co-up', '/invoices', {id: '1'}
115
+
116
+ expect(request).to have_been_made.once
148
117
  end
149
118
 
150
119
  it 'accepts a url' do
151
- expect(RestClient).to receive(:patch).with(
152
- 'https://co-up.cobot.me/api/invoices',
153
- {id: '1'}.to_json,
154
- 'Content-Type' => 'application/json',
155
- 'User-Agent' => 'test agent',
156
- 'Authorization' => 'Bearer token-123') { default_response }
120
+ request = stub_request(:patch, 'https://co-up.cobot.me/api/invoices')
121
+ .with(
122
+ body: {id: '1'}.to_json,
123
+ headers: {
124
+ 'Content-Type' => 'application/json',
125
+ 'User-Agent' => 'test agent',
126
+ 'Authorization' => 'Bearer token-123'
127
+ }
128
+ )
129
+ .and_return(default_response)
157
130
 
158
131
  api_client.patch 'https://co-up.cobot.me/api/invoices', {id: '1'}
132
+
133
+ expect(request).to have_been_made.once
159
134
  end
160
135
 
161
136
  it 'returns the response json' do
162
- allow(RestClient).to receive(:patch) { double(:response, code: 200, body: [{number: 1}].to_json) }
137
+ allow_any_instance_of(CobotClient::Request).to receive(:submit) { cobot_client_response(code: 200, body: [{number: 1}].to_json) }
163
138
 
164
139
  expect(api_client.patch('co-up', '/invoices', {})).to eql([{number: 1}])
165
140
  end
166
141
 
167
142
  it 'returns nil when the status code is 204' do
168
- allow(RestClient).to receive(:patch) { double(:response, body: '', code: 204) }
143
+ allow_any_instance_of(CobotClient::Request).to receive(:submit) { cobot_client_response(body: '', code: 204) }
169
144
 
170
145
  expect(api_client.patch('co-up', '/invoices', {})).to be_nil
171
146
  end
172
147
 
173
148
  it 'retries a 502 error' do
174
- @times = 0
175
- allow(RestClient).to receive(:patch) do
176
- if @times < 3
177
- @times += 1
178
- fail RestClient::BadGateway
149
+ times = 0
150
+ allow_any_instance_of(CobotClient::Request).to receive(:submit) do
151
+ if times < 3
152
+ times += 1
153
+ cobot_client_response(code: 502)
179
154
  else
180
- double(code: 200, body: {success: true}.to_json)
155
+ cobot_client_response(code: 200, body: {success: true}.to_json)
181
156
  end
182
157
  end
183
158
 
@@ -185,127 +160,162 @@ describe CobotClient::ApiClient do
185
160
  end
186
161
  end
187
162
 
188
- context '#post' do
189
- it 'calls rest client' do
190
- expect(RestClient).to receive(:post).with(
191
- 'https://co-up.cobot.me/api/invoices',
192
- {id: '1'}.to_json,
193
- 'Content-Type' => 'application/json',
194
- 'User-Agent' => 'test agent',
195
- 'Authorization' => 'Bearer token-123') { default_response }
163
+ describe '#post' do
164
+ it 'accepts a subdomain' do
165
+ request = stub_request(:post, 'https://co-up.cobot.me/api/invoices')
166
+ .with(
167
+ body: {id: '1'}.to_json,
168
+ headers: {
169
+ 'Content-Type' => 'application/json',
170
+ 'User-Agent' => 'test agent',
171
+ 'Authorization' => 'Bearer token-123'
172
+ }
173
+ )
174
+ .and_return(default_response)
196
175
 
197
176
  api_client.post 'co-up', '/invoices', {id: '1'}
177
+
178
+ expect(request).to have_been_made.once
198
179
  end
199
180
 
200
181
  it 'accepts a url' do
201
- expect(RestClient).to receive(:post).with(
202
- 'https://co-up.cobot.me/api/invoices',
203
- {id: '1'}.to_json,
204
- 'Content-Type' => 'application/json',
205
- 'User-Agent' => 'test agent',
206
- 'Authorization' => 'Bearer token-123') { default_response }
182
+ request = stub_request(:post, 'https://co-up.cobot.me/api/invoices')
183
+ .with(
184
+ body: {id: '1'}.to_json,
185
+ headers: {
186
+ 'Content-Type' => 'application/json',
187
+ 'User-Agent' => 'test agent',
188
+ 'Authorization' => 'Bearer token-123'
189
+ }
190
+ )
191
+ .and_return(default_response)
207
192
 
208
193
  api_client.post 'https://co-up.cobot.me/api/invoices', {id: '1'}
194
+
195
+ expect(request).to have_been_made.once
209
196
  end
210
197
 
211
198
  it 'returns the response json' do
212
- allow(RestClient).to receive(:post) { double(:response,
213
- code: 201, body: [{number: 1}].to_json) }
199
+ allow_any_instance_of(CobotClient::Request).to receive(:submit) {
200
+ cobot_client_response(code: 201, body: [{number: 1}].to_json)
201
+ }
214
202
 
215
203
  expect(api_client.post('co-up', '/invoices', {})).to eql([{number: 1}])
216
204
  end
217
205
 
218
206
  it 'returns nil when the status code is 204' do
219
- allow(RestClient).to receive(:post) { double(:response, code: 204,
220
- body: '') }
207
+ allow_any_instance_of(CobotClient::Request).to receive(:submit) {
208
+ cobot_client_response(code: 204, body: '')
209
+ }
221
210
 
222
211
  expect(api_client.post('co-up', '/invoices', {})).to be_nil
223
212
  end
224
213
  end
225
214
 
226
- context '#get' do
227
- it 'calls rest client' do
228
- expect(RestClient).to receive(:get).with('https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12',
229
- 'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
215
+ describe '#get' do
216
+ it 'accepts a subdomain' do
217
+ request = stub_request(:get, 'https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12')
218
+ .with(headers:
219
+ {
220
+ 'User-Agent' => 'test agent',
221
+ 'Authorization' => 'Bearer token-123'
222
+ })
223
+ .and_return(default_response)
230
224
 
231
225
  api_client.get 'co-up', '/invoices', {from: '2013-10-6', to: '2013-10-12'}
226
+
227
+ expect(request).to have_been_made.once
232
228
  end
233
229
 
234
230
  it 'accepts a url' do
235
- expect(RestClient).to receive(:get).with('https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12',
236
- 'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
231
+ request = stub_request(:get, 'https://co-up.cobot.me/api/invoices?from=2013-10-6&to=2013-10-12')
232
+ .with(headers:
233
+ {
234
+ 'User-Agent' => 'test agent',
235
+ 'Authorization' => 'Bearer token-123'
236
+ })
237
+ .and_return(default_response)
237
238
 
238
239
  api_client.get 'https://co-up.cobot.me/api/invoices', {from: '2013-10-6', to: '2013-10-12'}
240
+
241
+ expect(request).to have_been_made.once
239
242
  end
240
243
 
241
244
  it 'returns the response json' do
242
- allow(RestClient).to receive(:get) { double(:response, body: [{number: 1}].to_json) }
245
+ allow_any_instance_of(CobotClient::Request).to receive(:submit) { cobot_client_response(code: 200, body: [{number: 1}].to_json) }
243
246
 
244
247
  expect(api_client.get('co-up', '/invoices')).to eql([{number: 1}])
245
248
  end
246
249
 
247
- it 'converts a rest-client error into a cobot error' do
248
- allow(RestClient).to receive(:get).and_raise(RestClient::NotFound)
250
+ it 'converts a net/http error into a cobot error' do
251
+ allow_any_instance_of(CobotClient::Request).to receive(:submit).and_raise(Timeout::Error.new)
249
252
 
250
253
  expect do
251
254
  api_client.get('co-up', '/invoices')
252
- end.to raise_error(CobotClient::NotFound)
255
+ end.to raise_error(CobotClient::ConnectionError)
253
256
  end
254
257
 
255
- it 'retries a RestClient::RequestTimeout' do
256
- count = 0
257
- allow(RestClient).to receive(:get) do
258
- if count == 0
259
- count += 1
260
- fail RestClient::RequestTimeout
261
- else
262
- double(:response, body: '{}')
263
- end
264
- end
265
-
266
- expect(RestClient).to receive(:get).exactly(2).times
258
+ it 'retries a Net::ReadTimeout' do
259
+ stub_request(:get, 'https://co-up.cobot.me/api/invoices')
260
+ .to_raise(Net::ReadTimeout.new)
261
+ .to_return(status: 200, body: '{}')
267
262
 
268
263
  api_client.get('co-up', '/invoices')
264
+
265
+ expect(a_request(:get, 'https://co-up.cobot.me/api/invoices')).to have_been_made.twice
269
266
  end
270
267
 
271
- it 'converts a RestClient::RequestTimeout into a CobotClient::RequestTimeout' do
272
- allow(RestClient).to receive(:get).and_raise(RestClient::RequestTimeout)
268
+ it 'converts a Net::ReadTimeout into a CobotClient::ConnectionError' do
269
+ allow_any_instance_of(CobotClient::Request).to receive(:submit).and_raise(Net::ReadTimeout.new)
273
270
 
274
271
  expect do
275
272
  api_client.get('co-up', '/invoices')
276
- end.to raise_error(CobotClient::RequestTimeout)
273
+ end.to raise_error(CobotClient::ConnectionError, /^Net::ReadTimeout: /)
277
274
  end
278
275
 
279
276
  it 'includes the response, http code and http body in the exception' do
280
- response = double(:response, code: 404, body: 'boom')
281
- error = RestClient::NotFound.new(response)
282
- allow(RestClient).to receive(:get).and_raise(error)
277
+ response = cobot_client_response(code: 404, body: 'boom')
278
+ error = response.to_error
279
+ allow_any_instance_of(CobotClient::Request).to receive(:submit).and_raise(error)
283
280
 
284
281
  begin
285
282
  api_client.get('co-up', '/invoices')
286
- rescue CobotClient::NotFound => e
283
+ rescue CobotClient::ResponseError => e
284
+ expect(e).to be_a(CobotClient::NotFound)
287
285
  expect(e.response).to eql(response)
288
- expect(e.http_code).to eql(404)
286
+ expect(e.http_code).to be(404)
289
287
  expect(e.http_body).to eql('boom')
290
288
  end
291
289
  end
292
290
  end
293
291
 
294
- context '#delete' do
295
- it 'calls rest client' do
296
- expect(RestClient).to receive(:delete).with(
297
- 'https://co-up.cobot.me/api/invoices/1',
298
- 'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
292
+ describe '#delete' do
293
+ it 'accepts a subdomain' do
294
+ request = stub_request(:delete, 'https://co-up.cobot.me/api/invoices/1')
295
+ .with(
296
+ headers: {
297
+ 'User-Agent' => 'test agent',
298
+ 'Authorization' => 'Bearer token-123'
299
+ }
300
+ ).and_return(default_response)
299
301
 
300
302
  api_client.delete 'co-up', '/invoices/1'
303
+
304
+ expect(request).to have_been_made.once
301
305
  end
302
306
 
303
307
  it 'accepts a url' do
304
- expect(RestClient).to receive(:delete).with(
305
- 'https://co-up.cobot.me/api/invoices/1',
306
- 'User-Agent' => 'test agent', 'Authorization' => 'Bearer token-123') { default_response }
308
+ request = stub_request(:delete, 'https://co-up.cobot.me/api/invoices/1')
309
+ .with(
310
+ headers: {
311
+ 'User-Agent' => 'test agent',
312
+ 'Authorization' => 'Bearer token-123'
313
+ }
314
+ ).and_return(default_response)
307
315
 
308
316
  api_client.delete 'https://co-up.cobot.me/api/invoices/1'
317
+
318
+ expect(request).to have_been_made.once
309
319
  end
310
320
  end
311
321
  end
@@ -1,36 +1,58 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe CobotClient::NavigationLinkService, '#install_links' do
4
- let(:service) { CobotClient::NavigationLinkService.new(api_client, 'co-up') }
5
- let(:api_client) { instance_double(CobotClient::ApiClient) }
5
+ describe CobotClient::NavigationLinkService do
6
+ let(:service) { described_class.new(api_client, 'co-up') }
7
+ let(:api_client) { CobotClient::ApiClient.new('access_token') }
6
8
 
7
9
  context 'when there are links already' do
8
10
  let(:existing_link) do
9
- instance_double(CobotClient::NavigationLink, label: 'existing link',
10
- section: 'admin/setup', iframe_url: 'http://example.com/1').as_null_object
11
+ CobotClient::NavigationLink.new(
12
+ label: 'existing link',
13
+ section: 'admin/setup',
14
+ iframe_url: 'http://example.com/1'
15
+ )
11
16
  end
12
17
  let(:new_link) do
13
- instance_double(CobotClient::NavigationLink, label: 'new link',
14
- section: 'admin/setup', iframe_url: 'http://example.com/2').as_null_object
18
+ CobotClient::NavigationLink.new(
19
+ label: 'new link',
20
+ section: 'admin/setup',
21
+ iframe_url: 'http://example.com/2'
22
+ )
15
23
  end
16
24
 
17
- before(:each) do
25
+ before do
18
26
  allow(api_client).to receive(:get)
19
27
  .with('co-up', '/navigation_links')
20
- .and_return([{label: 'existing link',
21
- section: 'admin/setup', iframe_url: 'http://example.com/1'}])
28
+ .and_return(
29
+ [
30
+ {
31
+ label: 'existing link',
32
+ section: 'admin/setup',
33
+ iframe_url: 'http://example.com/1'
34
+ }
35
+ ]
36
+ )
22
37
  end
23
38
 
24
39
  it 'installs the missing links' do
25
40
  expect(api_client).to receive(:post)
26
- .with('co-up', '/navigation_links', hash_including(label: 'new link',
27
- section: 'admin/setup', iframe_url: 'http://example.com/2')) { {} }
41
+ .with(
42
+ 'co-up',
43
+ '/navigation_links',
44
+ hash_including(
45
+ label: 'new link',
46
+ section: 'admin/setup',
47
+ iframe_url: 'http://example.com/2'
48
+ )
49
+ ).and_return({})
28
50
 
29
51
  service.install_links [existing_link, new_link]
30
52
  end
31
53
 
32
54
  it 'returns all the links' do
33
- allow(api_client).to receive(:post) { {label: 'new link'} }
55
+ allow(api_client).to receive(:post).and_return({label: 'new link'})
34
56
 
35
57
  expect(service.install_links([existing_link, new_link]).map(&:label)).to eql(['existing link', 'new link'])
36
58
  end
@@ -38,28 +60,31 @@ describe CobotClient::NavigationLinkService, '#install_links' do
38
60
 
39
61
  context 'when there are no links installed' do
40
62
  let(:link) do
41
- instance_double(CobotClient::NavigationLink,
42
- section: 'admin/manage', label: 'test link', iframe_url: '/test',
43
- user_editable: true)
63
+ CobotClient::NavigationLink.new(
64
+ section: 'admin/manage',
65
+ label: 'test link',
66
+ iframe_url: '/test',
67
+ user_editable: true
68
+ )
44
69
  end
45
70
 
46
- before(:each) do
47
- allow(api_client).to receive(:get).with('co-up', '/navigation_links') { [] }
71
+ before do
72
+ allow(api_client).to receive(:get).with('co-up', '/navigation_links').and_return([])
48
73
  end
49
74
 
50
75
  it 'installs the links' do
51
76
  expect(api_client).to receive(:post)
52
77
  .with('co-up', '/navigation_links',
53
- section: 'admin/manage',
54
- label: 'test link',
55
- iframe_url: '/test',
56
- user_editable: true) { {} }
78
+ section: 'admin/manage',
79
+ label: 'test link',
80
+ iframe_url: '/test',
81
+ user_editable: true).and_return({})
57
82
 
58
83
  service.install_links [link]
59
84
  end
60
85
 
61
86
  it 'returns the links created' do
62
- allow(api_client).to receive(:post) { {label: 'test link'} }
87
+ allow(api_client).to receive(:post).and_return({label: 'test link'})
63
88
 
64
89
  expect(service.install_links([link]).map(&:label)).to eql(['test link'])
65
90
  end
@@ -1,18 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe CobotClient::UrlHelper, 'cobot_url' do
5
+ describe CobotClient::UrlHelper do
4
6
  let(:helper) do
5
7
  Object.new.tap do |o|
6
- o.extend CobotClient::UrlHelper
8
+ o.extend described_class
7
9
  end
8
10
  end
9
11
 
10
- after(:each) do
11
- CobotClient::UrlHelper.site = 'https://www.cobot.me'
12
+ after do
13
+ described_class.site = 'https://www.cobot.me'
12
14
  end
13
15
 
14
16
  it 'lets me change the site' do
15
- CobotClient::UrlHelper.site = 'https://www.cobot.com'
17
+ described_class.site = 'https://www.cobot.com'
16
18
 
17
19
  expect(helper.cobot_url).to eql('https://www.cobot.com/')
18
20
  end
@@ -21,7 +23,7 @@ describe CobotClient::UrlHelper, 'cobot_url' do
21
23
  expect(helper.cobot_url).to eql('https://www.cobot.me/')
22
24
  end
23
25
 
24
- it 'returns a url with a sudomain' do
26
+ it 'returns a url with a subdomain' do
25
27
  expect(helper.cobot_url('co-up')).to eql('https://co-up.cobot.me/')
26
28
  end
27
29
 
data/spec/spec_helper.rb CHANGED
@@ -1 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['RBS_TEST_LOGLEVEL'] ||= 'error'
4
+ ENV['RBS_TEST_TARGET'] ||= 'CobotClient*'
5
+
6
+ require 'rbs/test/setup'
7
+
1
8
  require_relative '../lib/cobot_client'
9
+
10
+ require 'webmock/rspec'
11
+ WebMock.disable_net_connect!