manticore 0.4.2-java → 0.4.3-java

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.
@@ -8,44 +8,48 @@ describe Manticore::Client do
8
8
 
9
9
  let(:client) { Manticore::Client.new }
10
10
 
11
- it "should fetch a URL and return a response" do
12
- client.get(local_server).should be_a Manticore::Response
11
+ it "fetches a URL and return a response" do
12
+ expect(client.get(local_server)).to be_a Manticore::Response
13
13
  end
14
14
 
15
- it "should resolve redirections" do
15
+ it "resolves redirections" do
16
16
  response = client.get(local_server, headers: {"X-Redirect" => "/foobar"})
17
- response.code.should == 200
18
- response.final_url.should == URI(local_server("/foobar"))
17
+ expect(response.code).to eq 200
18
+ expect(response.final_url).to eq URI(local_server("/foobar"))
19
19
  end
20
20
 
21
- it "should accept custom headers" do
21
+ it "accepts custom headers" do
22
22
  response = client.get(local_server, headers: {"X-Custom-Header" => "Blaznotts"})
23
23
  json = JSON.load(response.body)
24
- json["headers"]["X-Custom-Header"].should == "Blaznotts"
24
+ expect(json["headers"]["X-Custom-Header"]).to eq "Blaznotts"
25
25
  end
26
26
 
27
- it "should enable compression" do
27
+ it "enables compression" do
28
28
  response = client.get(local_server)
29
29
  json = JSON.load(response.body)
30
- json["headers"].should have_key "Accept-Encoding"
31
- json["headers"]["Accept-Encoding"].should match("gzip")
30
+ expect(json["headers"]).to have_key "Accept-Encoding"
31
+ expect(json["headers"]["Accept-Encoding"]).to match "gzip"
32
32
  end
33
33
 
34
- it "should authenticate" do
35
- client.get(local_server("/auth")).code.should == 401
36
- client.get(local_server("/auth"), auth: {user: "user", pass: "pass"}).code.should == 200
34
+ it "authenticates" do
35
+ expect(client.get(local_server("/auth")).code).to eq 401
36
+ expect(client.get(local_server("/auth"), auth: {user: "user", pass: "pass"}).code).to eq 200
37
37
  end
38
38
 
39
- it "should proxy" do
39
+ it "authenticates with eager auth" do
40
+ expect(client.get(local_server("/auth"), auth: {user: "user", pass: "pass", eager: true}).code).to eq 200
41
+ end
42
+
43
+ it "proxies" do
40
44
  j = JSON.parse(client.get(local_server("/proxy"), proxy: "http://localhost:55442").body)
41
- j["server_port"].should == 55442
42
- j["uri"]["port"].should == 55441
45
+ expect(j["server_port"]).to eq 55442
46
+ expect(j["uri"]["port"]).to eq 55441
43
47
  end
44
48
 
45
49
  describe "with a custom user agent" do
46
50
  let(:client) { Manticore::Client.new user_agent: "test-agent/1.0" }
47
51
 
48
- it "should use the specified UA" do
52
+ it "uses the specified UA" do
49
53
  response = client.get(local_server("/"))
50
54
  json = JSON.load(response.body)
51
55
  expect(json["headers"]["User-Agent"]).to eq "test-agent/1.0"
@@ -56,7 +60,7 @@ describe Manticore::Client do
56
60
  context "when on" do
57
61
  let(:client) { Manticore::Client.new ssl: {verify: false} }
58
62
 
59
- it "should not break on SSL validation errors" do
63
+ it "does not break on SSL validation errors" do
60
64
  expect { client.get("https://localhost:55444/").body }.to_not raise_exception
61
65
  end
62
66
  end
@@ -64,7 +68,7 @@ describe Manticore::Client do
64
68
  context "when off" do
65
69
  let(:client) { Manticore::Client.new ssl: {verify: true} }
66
70
 
67
- it "should break on SSL validation errors" do
71
+ it "breaks on SSL validation errors" do
68
72
  expect { client.get("https://localhost:55444/").call }.to raise_exception(Manticore::ClientProtocolException)
69
73
  end
70
74
  end
@@ -75,7 +79,7 @@ describe Manticore::Client do
75
79
  context 'default' do
76
80
  let(:client) { Manticore::Client.new }
77
81
 
78
- it "should break on SSL validation errors" do
82
+ it "breaks on SSL validation errors" do
79
83
  expect { client.get("https://localhost:55444/").call }.to raise_exception(Manticore::ClientProtocolException)
80
84
  end
81
85
  end
@@ -83,7 +87,7 @@ describe Manticore::Client do
83
87
  context 'when on and no trust store is given' do
84
88
  let(:client) { Manticore::Client.new :ssl => {:verify => :strict} }
85
89
 
86
- it "should break on SSL validation errors" do
90
+ it "breaks on SSL validation errors" do
87
91
  expect { client.get("https://localhost:55444/").call }.to raise_exception(Manticore::ClientProtocolException)
88
92
  end
89
93
  end
@@ -91,7 +95,7 @@ describe Manticore::Client do
91
95
  context 'when on and custom trust store is given' do
92
96
  let(:client) { Manticore::Client.new :ssl => {verify: :strict, truststore: File.expand_path("../../ssl/truststore.jks", __FILE__), truststore_password: "test123"} }
93
97
 
94
- it "should verify the request and succeed" do
98
+ it "verifies the request and succeed" do
95
99
  expect { client.get("https://localhost:55444/").body }.to_not raise_exception
96
100
  end
97
101
  end
@@ -99,7 +103,7 @@ describe Manticore::Client do
99
103
  context "when the client specifies a protocol list" do
100
104
  let(:client) { Manticore::Client.new :ssl => {verify: :strict, truststore: File.expand_path("../../ssl/truststore.jks", __FILE__), truststore_password: "test123", protocols: ["TLSv1", "TLSv1.1", "TLSv1.2"]} }
101
105
 
102
- it "should verify the request and succeed" do
106
+ it "verifies the request and succeed" do
103
107
  expect { client.get("https://localhost:55444/").body }.to_not raise_exception
104
108
  end
105
109
  end
@@ -107,7 +111,7 @@ describe Manticore::Client do
107
111
  context 'when on and custom trust store is given with the wrong password' do
108
112
  let(:client) { Manticore::Client.new :ssl => {verify: :strict, truststore: File.expand_path("../../ssl/truststore.jks", __FILE__), truststore_password: "wrongpass"} }
109
113
 
110
- it "should fail to load the keystore" do
114
+ it "fails to load the keystore" do
111
115
  expect { client.get("https://localhost:55444/").body }.to raise_exception(Java::JavaIo::IOException)
112
116
  end
113
117
  end
@@ -115,7 +119,7 @@ describe Manticore::Client do
115
119
  context 'when ca_file is given' do
116
120
  let(:client) { Manticore::Client.new :ssl => {verify: :strict, ca_file: File.expand_path("../../ssl/root-ca.crt", __FILE__) } }
117
121
 
118
- it "should verify the request and succeed" do
122
+ it "verifies the request and succeed" do
119
123
  expect { client.get("https://localhost:55444/").body }.to_not raise_exception
120
124
  end
121
125
  end
@@ -130,7 +134,7 @@ describe Manticore::Client do
130
134
  })
131
135
  }
132
136
 
133
- it "should successfully auth requests" do
137
+ it "successfully auths requests" do
134
138
  expect(client.get("https://localhost:55445/").body).to match("hello")
135
139
  end
136
140
  end
@@ -138,7 +142,7 @@ describe Manticore::Client do
138
142
  context 'when off' do
139
143
  let(:client) { Manticore::Client.new :ssl => {:verify => :none} }
140
144
 
141
- it "should not break on SSL validation errors" do
145
+ it "does not break on SSL validation errors" do
142
146
  expect { client.get("https://localhost:55444/").body }.to_not raise_exception
143
147
  end
144
148
  end
@@ -156,7 +160,7 @@ describe Manticore::Client do
156
160
  Manticore::Client.new :ssl => options
157
161
  }
158
162
 
159
- it "should successfully auth requests" do
163
+ it "successfully auths requests" do
160
164
  expect(client.get("https://localhost:55445/").body).to match("hello")
161
165
  end
162
166
  end
@@ -171,7 +175,7 @@ describe Manticore::Client do
171
175
  Manticore::Client.new :ssl => options
172
176
  }
173
177
 
174
- it "should fail the request" do
178
+ it "fails the request" do
175
179
  # oraclejdk7 throws a SocketException here, oraclejdk8/openjdk7 throw ClientProtocolException
176
180
  expect { client.get("https://localhost:55445/").body }.to raise_exception(Manticore::ManticoreException)
177
181
  end
@@ -189,17 +193,17 @@ describe Manticore::Client do
189
193
  end
190
194
 
191
195
  describe "lazy evaluation" do
192
- it "should not call synchronous requests by default" do
196
+ it "does not call synchronous requests by default" do
193
197
  req = client.get(local_server)
194
- req.should_not be_called
198
+ expect(req).to_not be_called
195
199
  end
196
200
 
197
201
  context "given a lazy request" do
198
202
  subject { client.get(local_server) }
199
203
 
200
204
  before do
201
- subject.should_not be_called
202
- subject.should_receive(:call).once.and_call_original
205
+ expect(subject).to_not be_called
206
+ expect(subject).to receive(:call).once.and_call_original
203
207
  end
204
208
 
205
209
  specify { expect { subject.body }.to change { subject.called? } }
@@ -210,29 +214,29 @@ describe Manticore::Client do
210
214
  specify { expect { subject.cookies }.to change { subject.called? } }
211
215
  end
212
216
 
213
- it "should automatically call synchronous requests that pass a handler block" do
217
+ it "automatically calls synchronous requests that pass a handler block" do
214
218
  req = client.get(local_server) {|r| }
215
- req.should be_called
219
+ expect(req).to be_called
216
220
  end
217
221
 
218
- it "should not call asynchronous requests even if a block is passed" do
222
+ it "does not call asynchronous requests even if a block is passed" do
219
223
  req = client.async.get(local_server) {|r| }
220
- req.should_not be_called
224
+ expect(req).to_not be_called
221
225
  end
222
226
 
223
- it "should not call asynchronous requests when on_success is passed" do
227
+ it "does not call asynchronous requests when on_success is passed" do
224
228
  req = client.async.get(local_server).on_success {|r| }
225
- req.should_not be_called
229
+ expect(req).to_not be_called
226
230
  end
227
231
 
228
- it "should call async requests on client execution" do
232
+ it "calls async requests on client execution" do
229
233
  req = client.async.get(local_server).on_success {|r| }
230
234
  expect { client.execute! }.to change { req.called? }.from(false).to(true)
231
235
  end
232
236
 
233
237
 
234
238
  describe "with a bad port number" do
235
- it "should return a Manticore::InvalidArgumentException" do
239
+ it "returns a Manticore::InvalidArgumentException" do
236
240
  failure = nil
237
241
  client.async.get(local_server("/", 65536)).
238
242
  on_failure {|f| failure = f }
@@ -242,7 +246,7 @@ describe Manticore::Client do
242
246
  end
243
247
 
244
248
  describe "mysterious failures" do
245
- it "should still return an error to on failure" do
249
+ it "still returns an error to on failure" do
246
250
  failure = nil
247
251
  # I'm not crazy about reaching into the client via instance_variable_get here, but it works.
248
252
  expect(client.instance_variable_get("@client")).to receive(:execute).and_raise(StandardError.new("Uh oh"))
@@ -257,66 +261,66 @@ describe Manticore::Client do
257
261
  context "when client-wide cookie management is disabled" do
258
262
  let(:client) { Manticore::Client.new cookies: false }
259
263
 
260
- it "should persist cookies across multiple redirects from a single request" do
264
+ it "persists cookies across multiple redirects from a single request" do
261
265
  response = client.get(local_server("/cookies/1/2"))
262
- response.final_url.to_s.should == local_server("/cookies/2/2")
263
- response.cookies["x"].should be_nil
264
- response.headers["set-cookie"].should match(/1/)
266
+ expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
267
+ expect(response.cookies["x"]).to be_nil
268
+ expect(response.headers["set-cookie"]).to match(/1/)
265
269
  end
266
270
 
267
- it "should not persist cookies between requests" do
271
+ it "does not persist cookies between requests" do
268
272
  response = client.get(local_server("/cookies/1/2"))
269
- response.final_url.to_s.should == local_server("/cookies/2/2")
270
- response.cookies["x"].should be_nil
271
- response.headers["set-cookie"].should match(/1/)
273
+ expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
274
+ expect(response.cookies["x"]).to be_nil
275
+ expect(response.headers["set-cookie"]).to match(/1/)
272
276
 
273
277
  response = client.get(local_server("/cookies/1/2"))
274
- response.final_url.to_s.should == local_server("/cookies/2/2")
275
- response.cookies["x"].should be_nil
276
- response.headers["set-cookie"].should match(/1/)
278
+ expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
279
+ expect(response.cookies["x"]).to be_nil
280
+ expect(response.headers["set-cookie"]).to match(/1/)
277
281
  end
278
282
  end
279
283
 
280
284
  context "when client-wide cookie management is set to per-request" do
281
285
  let(:client) { Manticore::Client.new cookies: :per_request }
282
286
 
283
- it "should persist cookies across multiple redirects from a single request" do
287
+ it "persists cookies across multiple redirects from a single request" do
284
288
  response = client.get(local_server("/cookies/1/2"))
285
- response.final_url.to_s.should == local_server("/cookies/2/2")
286
- response.headers["set-cookie"].should match(/2/)
287
- response.cookies["x"].first.value.should == "2"
289
+ expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
290
+ expect(response.headers["set-cookie"]).to match(/2/)
291
+ expect(response.cookies["x"].first.value).to eq "2"
288
292
  end
289
293
 
290
- it "should not persist cookies between requests" do
294
+ it "does not persist cookies between requests" do
291
295
  response = client.get(local_server("/cookies/1/2"))
292
- response.final_url.to_s.should == local_server("/cookies/2/2")
293
- response.headers["set-cookie"].should match(/2/)
294
- response.cookies["x"].first.value.should == "2"
296
+ expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
297
+ expect(response.headers["set-cookie"]).to match(/2/)
298
+ expect(response.cookies["x"].first.value).to eq "2"
295
299
 
296
300
  response = client.get(local_server("/cookies/1/2"))
297
- response.final_url.to_s.should == local_server("/cookies/2/2")
298
- response.headers["set-cookie"].should match(/2/)
299
- response.cookies["x"].first.value.should == "2"
301
+ expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
302
+ expect(response.headers["set-cookie"]).to match(/2/)
303
+ expect(response.cookies["x"].first.value).to eq "2"
300
304
  end
301
305
  end
302
306
 
303
307
  context "when client-wide cookie management is enabled" do
304
308
  let(:client) { Manticore::Client.new cookies: true }
305
309
 
306
- it "should persist cookies across multiple redirects from a single request" do
310
+ it "persists cookies across multiple redirects from a single request" do
307
311
  response = client.get(local_server("/cookies/1/2"))
308
- response.final_url.to_s.should == local_server("/cookies/2/2")
309
- response.cookies["x"].first.value.should == "2"
312
+ expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
313
+ expect(response.cookies["x"].first.value).to eq "2"
310
314
  end
311
315
 
312
- it "should persist cookies between requests" do
316
+ it "persists cookies between requests" do
313
317
  response = client.get(local_server("/cookies/1/2"))
314
- response.final_url.to_s.should == local_server("/cookies/2/2")
315
- response.cookies["x"].first.value.should == "2"
318
+ expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
319
+ expect(response.cookies["x"].first.value).to eq "2"
316
320
 
317
321
  response = client.get(local_server("/cookies/1/2"))
318
- response.final_url.to_s.should == local_server("/cookies/2/2")
319
- response.cookies["x"].first.value.should == "4"
322
+ expect(response.final_url.to_s).to eq local_server("/cookies/2/2")
323
+ expect(response.cookies["x"].first.value).to eq "4"
320
324
  end
321
325
  end
322
326
 
@@ -327,138 +331,138 @@ describe Manticore::Client do
327
331
  end
328
332
  }
329
333
 
330
- it "should disable compression" do
334
+ it "disables compression" do
331
335
  response = client.get(local_server)
332
336
  json = JSON.load(response.body)
333
- json["headers"]["Accept-Encoding"].should be_nil
337
+ expect(json["headers"]["Accept-Encoding"]).to be_nil
334
338
  end
335
339
  end
336
340
 
337
341
  context "when no response charset is specified" do
338
342
  let(:content_type) { "text/plain" }
339
343
 
340
- it "should decode response bodies according to the content-type header" do
341
- client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name.should == "ISO-8859-1"
344
+ it "decodes response bodies according to the content-type header" do
345
+ expect(client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name).to eq "ISO-8859-1"
342
346
  end
343
347
  end
344
348
 
345
349
  context "when an invalid response charset is specified" do
346
350
  let(:content_type) { "text/plain; charset=bogus" }
347
351
 
348
- it "should decode the content as UTF-8" do
349
- client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name.should == "ISO-8859-1"
352
+ it "decodes the content as UTF-8" do
353
+ expect(client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name).to eq "ISO-8859-1"
350
354
  end
351
355
  end
352
356
 
353
357
  context "when the response charset is UTF-8" do
354
358
  let(:content_type) { "text/plain; charset=utf-8" }
355
359
 
356
- it "should decode response bodies according to the content-type header" do
357
- client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name.should == "UTF-8"
360
+ it "decodes response bodies according to the content-type header" do
361
+ expect(client.get(local_server, headers: {"X-Content-Type" => content_type}).body.encoding.name).to eq "UTF-8"
358
362
  end
359
363
  end
360
364
 
361
365
  describe "#get" do
362
- it "should work" do
366
+ it "works" do
363
367
  response = client.get(local_server)
364
- JSON.load(response.body)["method"].should == "GET"
368
+ expect(JSON.load(response.body)["method"]).to eq "GET"
365
369
  end
366
370
 
367
371
  it "send a query" do
368
372
  response = client.get local_server, query: {foo: "bar"}
369
- CGI.parse(JSON.load(response.body)["uri"]["query"])["foo"].should == ["bar"]
373
+ expect(CGI.parse(JSON.load(response.body)["uri"]["query"])["foo"]).to eq ["bar"]
370
374
  end
371
375
 
372
- it "should send a body" do
376
+ it "sends a body" do
373
377
  response = client.get(local_server, body: "This is a post body")
374
- JSON.load(response.body)["body"].should == "This is a post body"
378
+ expect(JSON.load(response.body)["body"]).to eq "This is a post body"
375
379
  end
376
380
  end
377
381
 
378
382
  describe "#post" do
379
- it "should work" do
383
+ it "works" do
380
384
  response = client.post(local_server)
381
- JSON.load(response.body)["method"].should == "POST"
385
+ expect(JSON.load(response.body)["method"]).to eq "POST"
382
386
  end
383
387
 
384
- it "should send a body" do
388
+ it "sends a body" do
385
389
  response = client.post(local_server, body: "This is a post body")
386
- JSON.load(response.body)["body"].should == "This is a post body"
390
+ expect(JSON.load(response.body)["body"]).to eq "This is a post body"
387
391
  end
388
392
 
389
- it "should send a UTF-8 body" do
393
+ it "sends a UTF-8 body" do
390
394
  response = client.post(local_server, body: "This is a post body ∑")
391
- JSON.load(response.body)["body"].should == "This is a post body ∑"
395
+ expect(JSON.load(response.body)["body"]).to eq "This is a post body ∑"
392
396
  end
393
397
 
394
- it "should send params" do
398
+ it "sends params" do
395
399
  response = client.post(local_server, params: {key: "value"})
396
- CGI.unescape(JSON.load(response.body)["body"]).should == "key=value"
400
+ expect(CGI.unescape(JSON.load(response.body)["body"])).to eq "key=value"
397
401
  end
398
402
 
399
- it "should send non-ASCII params" do
403
+ it "sends non-ASCII params" do
400
404
  response = client.post(local_server, params: {"∑" => "√"})
401
- CGI.unescape(JSON.load(response.body)["body"]).should == "∑=√"
405
+ expect(CGI.unescape(JSON.load(response.body)["body"])).to eq "∑=√"
402
406
  end
403
407
 
404
- it "should send an arbitrary entity" do
408
+ it "sends an arbitrary entity" do
405
409
  f = open(__FILE__, "r").to_inputstream
406
410
  multipart_entity = MultipartEntityBuilder.create.add_text_body("foo", "bar").add_binary_body("whatever", f , ContentType::TEXT_PLAIN, __FILE__)
407
411
  response = client.post(local_server, entity: multipart_entity.build)
408
- response.body.should match("should send an arbitrary entity")
412
+ expect(response.body).to match "sends an arbitrary entity"
409
413
  end
410
414
  end
411
415
 
412
416
  describe "#put" do
413
- it "should work" do
417
+ it "works" do
414
418
  response = client.put(local_server)
415
- JSON.load(response.body)["method"].should == "PUT"
419
+ expect(JSON.load(response.body)["method"]).to eq "PUT"
416
420
  end
417
421
 
418
- it "should send a body" do
422
+ it "sends a body" do
419
423
  response = client.put(local_server, body: "This is a put body")
420
- JSON.load(response.body)["body"].should == "This is a put body"
424
+ expect(JSON.load(response.body)["body"]).to eq "This is a put body"
421
425
  end
422
426
 
423
- it "should send params" do
427
+ it "sends params" do
424
428
  response = client.put(local_server, params: {key: "value"})
425
- JSON.load(response.body)["body"].should == "key=value"
429
+ expect(JSON.load(response.body)["body"]).to eq "key=value"
426
430
  end
427
431
  end
428
432
 
429
433
  describe "#head" do
430
- it "should work" do
434
+ it "works" do
431
435
  response = client.head(local_server)
432
- JSON.load(response.body).should be_nil
436
+ expect(JSON.load(response.body)).to be_nil
433
437
  end
434
438
  end
435
439
 
436
440
  describe "#options" do
437
- it "should work" do
441
+ it "works" do
438
442
  response = client.options(local_server)
439
- JSON.load(response.body)["method"].should == "OPTIONS"
443
+ expect(JSON.load(response.body)["method"]).to eq "OPTIONS"
440
444
  end
441
445
  end
442
446
 
443
447
  describe "#patch" do
444
- it "should work" do
448
+ it "works" do
445
449
  response = client.patch(local_server)
446
- JSON.load(response.body)["method"].should == "PATCH"
450
+ expect(JSON.load(response.body)["method"]).to eq "PATCH"
447
451
  end
448
452
 
449
- it "should send a body" do
453
+ it "sends a body" do
450
454
  response = client.patch(local_server, body: "This is a patch body")
451
- JSON.load(response.body)["body"].should == "This is a patch body"
455
+ expect(JSON.load(response.body)["body"]).to eq "This is a patch body"
452
456
  end
453
457
 
454
- it "should send params" do
458
+ it "sends params" do
455
459
  response = client.patch(local_server, params: {key: "value"})
456
- JSON.load(response.body)["body"].should == "key=value"
460
+ expect(JSON.load(response.body)["body"]).to eq "key=value"
457
461
  end
458
462
  end
459
463
 
460
464
  describe "#execute!" do
461
- it "should perform multiple concurrent requests" do
465
+ it "performs multiple concurrent requests" do
462
466
  futures = [55441, 55442].map do |port|
463
467
  client.async.get("http://localhost:#{port}/?sleep=1").
464
468
  on_success do |response|
@@ -468,72 +472,72 @@ describe Manticore::Client do
468
472
 
469
473
  client.execute!
470
474
  values = futures.map(&:callback_result)
471
- (values[0] - values[1]).abs.should < 0.25
475
+ expect((values[0] - values[1]).abs).to be < 0.25
472
476
  end
473
477
 
474
- it "should return the results of the handler blocks" do
478
+ it "returns the results of the handler blocks" do
475
479
  [55441, 55442].each do |port|
476
480
  client.async.get("http://localhost:#{port}/").
477
481
  on_success {|response, request| "Result" }
478
482
  end
479
483
 
480
- client.execute!.map(&:callback_result).should == ["Result", "Result"]
484
+ expect(client.execute!.map(&:callback_result)).to eq ["Result", "Result"]
481
485
  end
482
486
  end
483
487
 
484
488
  describe "#clear_pending" do
485
- it "should remove pending requests" do
489
+ it "removes pending requests" do
486
490
  ran = false
487
491
  client.async.get("http://google.com").on_success {|r| ran = true }
488
492
  client.clear_pending
489
- client.execute!.should be_empty
490
- ran.should be false
493
+ expect(client.execute!).to be_empty
494
+ expect(ran).to be false
491
495
  end
492
496
  end
493
497
 
494
498
  describe "#stub" do
495
- it "should respond with a stubbed response until it is unstubbed" do
499
+ it "responds with a stubbed response until it is unstubbed" do
496
500
  client.stub(local_server, body: "body", code: 200)
497
501
 
498
502
  called = false
499
503
  2.times {
500
504
  client.get(local_server) do |response|
501
505
  called = true
502
- response.should be_a Manticore::StubbedResponse
503
- response.body.should == "body"
504
- response.code.should == 200
506
+ expect(response).to be_a Manticore::StubbedResponse
507
+ expect(response.body).to eq "body"
508
+ expect(response.code).to eq 200
505
509
  end
506
510
  }
507
511
 
508
- called.should be true
512
+ expect(called).to be true
509
513
 
510
514
  client.clear_stubs!
511
515
  client.get(local_server) do |response|
512
- response.should be_a Manticore::Response
513
- response.body.should match(/Manticore/)
514
- response.code.should == 200
516
+ expect(response).to be_a Manticore::Response
517
+ expect(response.body).to match /Manticore/
518
+ expect(response.code).to eq 200
515
519
  end
516
520
  end
517
521
 
518
522
  context 'stubbing' do
519
523
  it "only the provided URLs" do
520
524
  client.stub local_server, body: "body"
521
- client.async.get(local_server).on_success {|r| r.should be_a Manticore::StubbedResponse }
522
- client.async.get(local_server("/other")).on_success {|r| r.should_not be_a Manticore::StubbedResponse }
525
+ client.async.get(local_server).on_success {|r| expect(r).to be_a Manticore::StubbedResponse }
526
+ client.async.get(local_server("/other")).on_success {|r| expect(r).to_not be_a Manticore::StubbedResponse }
523
527
  client.execute!
524
528
  end
525
529
 
526
530
  it "by regex matching" do
527
531
  client.stub %r{#{local_server("/foo")}}, body: "body"
528
- client.async.get(local_server("/foo")).on_success {|r| r.should be_a Manticore::StubbedResponse }
529
- client.async.get(local_server("/bar")).on_success {|r| r.should_not be_a Manticore::StubbedResponse }
532
+ client.async.get(local_server("/foo")).on_success {|r| expect(r).to be_a Manticore::StubbedResponse }
533
+ client.async.get(local_server("/bar")).on_success {|r| expect(r).to_not be_a Manticore::StubbedResponse }
530
534
  client.execute!
531
535
  end
532
536
 
533
537
  it "strictly matches string stubs" do
534
538
  client.stub local_server("/foo"), body: "body"
535
- client.async.get(local_server("/foo")).on_success {|r| r.should be_a Manticore::StubbedResponse }
536
- client.async.get(local_server("/other")).on_success {|r| r.should_not be_a Manticore::StubbedResponse }
539
+ client.async.get(local_server("/foo")).on_success {|r| expect(r).to be_a Manticore::StubbedResponse }
540
+ client.async.get(local_server("/other")).on_success {|r| expect(r).to_not be_a Manticore::StubbedResponse }
537
541
  client.execute!
538
542
  end
539
543
 
@@ -559,17 +563,17 @@ describe Manticore::Client do
559
563
 
560
564
 
561
565
  context "with keepalive" do
562
- it "should add the Connection: Keep-Alive header for http/1.0" do
566
+ it "adds the Connection: Keep-Alive header for http/1.0" do
563
567
  expect( client.get(url).request["Connection"] ).to eq "Keep-Alive"
564
568
  end
565
569
 
566
570
  let(:client) { Manticore::Client.new keepalive: true, pool_max: 1 }
567
571
 
568
- it "should keep the connection open after a request" do
572
+ it "keeps the connection open after a request" do
569
573
  skip
570
574
  response = client.get(url).call
571
575
  get_connection(client, url) do |conn|
572
- conn.is_open.should be true
576
+ expect(conn.is_open).to be true
573
577
  end
574
578
  end
575
579
  end
@@ -577,11 +581,11 @@ describe Manticore::Client do
577
581
  context "without keepalive" do
578
582
  let(:client) { Manticore::Client.new keepalive: false, pool_max: 1 }
579
583
 
580
- it "should not add the Connection: Keep-Alive header for http/1.0" do
584
+ it "does not add the Connection: Keep-Alive header for http/1.0" do
581
585
  expect( client.get(url).request["Connection"] ).to be_nil
582
586
  end
583
587
 
584
- it "should close the connection after a request" do
588
+ it "closes the connection after a request" do
585
589
  skip
586
590
  response = client.get(url).call
587
591
  puts `netstat -apn`
@@ -613,7 +617,7 @@ describe Manticore::Client do
613
617
 
614
618
  let(:client) { Manticore::Client.new keepalive: true, pool_max: 1 }
615
619
 
616
- it "should retry 3 times by default" do
620
+ it "retries 3 times by default" do
617
621
  # The first time, reply with keepalive, then close the connection
618
622
  # The second connection should succeed
619
623
 
@@ -622,14 +626,14 @@ describe Manticore::Client do
622
626
  expect { request1.call }.to_not raise_exception
623
627
  expect { request2.call }.to_not raise_exception
624
628
 
625
- request1.times_retried.should == 0
626
- request2.times_retried.should == 1
629
+ expect(request1.times_retried).to eq 0
630
+ expect(request2.times_retried).to eq 1
627
631
  end
628
632
 
629
633
  context "when the max retry is restrictive" do
630
634
  let(:client) { Manticore::Client.new keepalive: true, pool_max: 1, automatic_retries: 0 }
631
635
 
632
- it "should retry 0 times and fail on the second request" do
636
+ it "retries 0 times and fail on the second request" do
633
637
  # The first time, reply with keepalive, then close the connection
634
638
  # The second connection should succeed
635
639
  expect { client.get("http://localhost:4567/").call }.to_not raise_exception
@@ -640,7 +644,7 @@ describe Manticore::Client do
640
644
  context "when keepalive is off" do
641
645
  let(:client) { Manticore::Client.new keepalive: false, pool_max: 1 }
642
646
 
643
- it "should succeed without any retries" do
647
+ it "succeeds without any retries" do
644
648
  # The first time, reply with keepalive, then close the connection
645
649
  # The second connection should succeed
646
650
  request1 = client.get("http://localhost:4567/")
@@ -648,8 +652,8 @@ describe Manticore::Client do
648
652
  expect { request1.call }.to_not raise_exception
649
653
  expect { request2.call }.to_not raise_exception
650
654
 
651
- request1.times_retried.should == 0
652
- request2.times_retried.should == 0
655
+ expect(request1.times_retried).to eq 0
656
+ expect(request2.times_retried).to eq 0
653
657
  end
654
658
  end
655
659
 
@@ -662,11 +666,11 @@ describe Manticore::Client do
662
666
  describe "with connection timeouts" do
663
667
  let(:client) { Manticore::Client.new request_timeout: 1, connect_timeout: 1, socket_timeout: 1 }
664
668
 
665
- it "should time out" do
669
+ it "times out" do
666
670
  expect { client.get(local_server "/?sleep=2").body }.to raise_exception(Manticore::SocketTimeout)
667
671
  end
668
672
 
669
- it "should time out when custom request options are passed" do
673
+ it "times out when custom request options are passed" do
670
674
  expect { client.get(local_server("/?sleep=2"), max_redirects: 5).body }.to raise_exception(Manticore::SocketTimeout)
671
675
  end
672
676
  end