httparty 0.16.4 → 0.20.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.

Potentially problematic release.


This version of httparty might be problematic. Click here for more details.

Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +23 -0
  3. data/.rubocop_todo.yml +1 -1
  4. data/Changelog.md +55 -0
  5. data/Gemfile +5 -0
  6. data/README.md +4 -4
  7. data/docs/README.md +70 -5
  8. data/examples/README.md +6 -0
  9. data/examples/aaws.rb +6 -2
  10. data/examples/idn.rb +10 -0
  11. data/examples/peer_cert.rb +9 -0
  12. data/httparty.gemspec +1 -2
  13. data/lib/httparty/connection_adapter.rb +41 -10
  14. data/lib/httparty/cookie_hash.rb +10 -8
  15. data/lib/httparty/decompressor.rb +92 -0
  16. data/lib/httparty/exceptions.rb +3 -1
  17. data/lib/httparty/hash_conversions.rb +4 -2
  18. data/lib/httparty/headers_processor.rb +32 -0
  19. data/lib/httparty/logger/apache_formatter.rb +4 -2
  20. data/lib/httparty/logger/curl_formatter.rb +6 -4
  21. data/lib/httparty/logger/logger.rb +2 -0
  22. data/lib/httparty/logger/logstash_formatter.rb +4 -2
  23. data/lib/httparty/module_inheritable_attributes.rb +3 -1
  24. data/lib/httparty/net_digest_auth.rb +9 -10
  25. data/lib/httparty/parser.rb +9 -5
  26. data/lib/httparty/request/body.rb +24 -10
  27. data/lib/httparty/request/multipart_boundary.rb +2 -0
  28. data/lib/httparty/request.rb +67 -96
  29. data/lib/httparty/response/headers.rb +2 -0
  30. data/lib/httparty/response.rb +24 -4
  31. data/lib/httparty/{fragment_with_response.rb → response_fragment.rb} +6 -5
  32. data/lib/httparty/text_encoder.rb +72 -0
  33. data/lib/httparty/utils.rb +2 -0
  34. data/lib/httparty/version.rb +3 -1
  35. data/lib/httparty.rb +58 -35
  36. metadata +12 -108
  37. data/.travis.yml +0 -11
  38. data/features/basic_authentication.feature +0 -20
  39. data/features/command_line.feature +0 -95
  40. data/features/deals_with_http_error_codes.feature +0 -26
  41. data/features/digest_authentication.feature +0 -30
  42. data/features/handles_compressed_responses.feature +0 -27
  43. data/features/handles_multiple_formats.feature +0 -57
  44. data/features/steps/env.rb +0 -27
  45. data/features/steps/httparty_response_steps.rb +0 -56
  46. data/features/steps/httparty_steps.rb +0 -43
  47. data/features/steps/mongrel_helper.rb +0 -127
  48. data/features/steps/remote_service_steps.rb +0 -92
  49. data/features/supports_read_timeout_option.feature +0 -13
  50. data/features/supports_redirection.feature +0 -22
  51. data/features/supports_timeout_option.feature +0 -13
  52. data/spec/fixtures/delicious.xml +0 -23
  53. data/spec/fixtures/empty.xml +0 -0
  54. data/spec/fixtures/example.html +0 -10
  55. data/spec/fixtures/ssl/generate.sh +0 -29
  56. data/spec/fixtures/ssl/generated/bogushost.crt +0 -13
  57. data/spec/fixtures/ssl/generated/ca.crt +0 -16
  58. data/spec/fixtures/ssl/generated/ca.key +0 -15
  59. data/spec/fixtures/ssl/generated/selfsigned.crt +0 -14
  60. data/spec/fixtures/ssl/generated/server.crt +0 -13
  61. data/spec/fixtures/ssl/generated/server.key +0 -15
  62. data/spec/fixtures/ssl/openssl-exts.cnf +0 -9
  63. data/spec/fixtures/tiny.gif +0 -0
  64. data/spec/fixtures/twitter.csv +0 -2
  65. data/spec/fixtures/twitter.json +0 -1
  66. data/spec/fixtures/twitter.xml +0 -403
  67. data/spec/fixtures/undefined_method_add_node_for_nil.xml +0 -2
  68. data/spec/httparty/connection_adapter_spec.rb +0 -502
  69. data/spec/httparty/cookie_hash_spec.rb +0 -100
  70. data/spec/httparty/exception_spec.rb +0 -45
  71. data/spec/httparty/fragment_with_response_spec.rb +0 -14
  72. data/spec/httparty/hash_conversions_spec.rb +0 -58
  73. data/spec/httparty/logger/apache_formatter_spec.rb +0 -40
  74. data/spec/httparty/logger/curl_formatter_spec.rb +0 -119
  75. data/spec/httparty/logger/logger_spec.rb +0 -43
  76. data/spec/httparty/logger/logstash_formatter_spec.rb +0 -44
  77. data/spec/httparty/net_digest_auth_spec.rb +0 -270
  78. data/spec/httparty/parser_spec.rb +0 -190
  79. data/spec/httparty/request/body_spec.rb +0 -165
  80. data/spec/httparty/request_spec.rb +0 -1367
  81. data/spec/httparty/response_spec.rb +0 -368
  82. data/spec/httparty/ssl_spec.rb +0 -74
  83. data/spec/httparty_spec.rb +0 -923
  84. data/spec/spec_helper.rb +0 -56
  85. data/spec/support/ssl_test_helper.rb +0 -47
  86. data/spec/support/ssl_test_server.rb +0 -80
  87. data/spec/support/stub_response.rb +0 -49
@@ -1,502 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe HTTParty::ConnectionAdapter do
4
- describe "initialization" do
5
- let(:uri) { URI 'http://www.google.com' }
6
- it "takes a URI as input" do
7
- HTTParty::ConnectionAdapter.new(uri)
8
- end
9
-
10
- it "raises an ArgumentError if the uri is nil" do
11
- expect { HTTParty::ConnectionAdapter.new(nil) }.to raise_error ArgumentError
12
- end
13
-
14
- it "raises an ArgumentError if the uri is a String" do
15
- expect { HTTParty::ConnectionAdapter.new('http://www.google.com') }.to raise_error ArgumentError
16
- end
17
-
18
- it "sets the uri" do
19
- adapter = HTTParty::ConnectionAdapter.new(uri)
20
- expect(adapter.uri).to be uri
21
- end
22
-
23
- it "also accepts an optional options hash" do
24
- HTTParty::ConnectionAdapter.new(uri, {})
25
- end
26
-
27
- it "sets the options" do
28
- options = {foo: :bar}
29
- adapter = HTTParty::ConnectionAdapter.new(uri, options)
30
- expect(adapter.options.keys).to include(:verify, :verify_peer, :foo)
31
- end
32
- end
33
-
34
- describe ".call" do
35
- let(:uri) { URI 'http://www.google.com' }
36
- let(:options) { { foo: :bar } }
37
-
38
- it "generates an HTTParty::ConnectionAdapter instance with the given uri and options" do
39
- expect(HTTParty::ConnectionAdapter).to receive(:new).with(uri, options).and_return(double(connection: nil))
40
- HTTParty::ConnectionAdapter.call(uri, options)
41
- end
42
-
43
- it "calls #connection on the connection adapter" do
44
- adapter = double('Adapter')
45
- connection = double('Connection')
46
- expect(adapter).to receive(:connection).and_return(connection)
47
- allow(HTTParty::ConnectionAdapter).to receive_messages(new: adapter)
48
- expect(HTTParty::ConnectionAdapter.call(uri, options)).to be connection
49
- end
50
- end
51
-
52
- describe '#connection' do
53
- let(:uri) { URI 'http://www.google.com' }
54
- let(:options) { Hash.new }
55
- let(:adapter) { HTTParty::ConnectionAdapter.new(uri, options) }
56
-
57
- describe "the resulting connection" do
58
- subject { adapter.connection }
59
- it { is_expected.to be_an_instance_of Net::HTTP }
60
-
61
- context "using port 80" do
62
- let(:uri) { URI 'http://foobar.com' }
63
- it { is_expected.not_to use_ssl }
64
- end
65
-
66
- context "when dealing with ssl" do
67
- let(:uri) { URI 'https://foobar.com' }
68
-
69
- context "uses the system cert_store, by default" do
70
- let!(:system_cert_store) do
71
- system_cert_store = double('default_cert_store')
72
- expect(system_cert_store).to receive(:set_default_paths)
73
- expect(OpenSSL::X509::Store).to receive(:new).and_return(system_cert_store)
74
- system_cert_store
75
- end
76
- it { is_expected.to use_cert_store(system_cert_store) }
77
- end
78
-
79
- context "should use the specified cert store, when one is given" do
80
- let(:custom_cert_store) { double('custom_cert_store') }
81
- let(:options) { {cert_store: custom_cert_store} }
82
- it { is_expected.to use_cert_store(custom_cert_store) }
83
- end
84
-
85
- context "using port 443 for ssl" do
86
- let(:uri) { URI 'https://api.foo.com/v1:443' }
87
- it { is_expected.to use_ssl }
88
- end
89
-
90
- context "https scheme with default port" do
91
- it { is_expected.to use_ssl }
92
- end
93
-
94
- context "https scheme with non-standard port" do
95
- let(:uri) { URI 'https://foobar.com:123456' }
96
- it { is_expected.to use_ssl }
97
- end
98
-
99
- context "when ssl version is set" do
100
- let(:options) { {ssl_version: :TLSv1} }
101
-
102
- it "sets ssl version" do
103
- expect(subject.ssl_version).to eq(:TLSv1)
104
- end
105
- end if RUBY_VERSION > '1.9'
106
- end
107
-
108
- context "when dealing with IPv6" do
109
- let(:uri) { URI 'http://[fd00::1]' }
110
-
111
- it "strips brackets from the address" do
112
- expect(subject.address).to eq('fd00::1')
113
- end
114
- end
115
-
116
- context "specifying ciphers" do
117
- let(:options) { {ciphers: 'RC4-SHA' } }
118
-
119
- it "should set the ciphers on the connection" do
120
- expect(subject.ciphers).to eq('RC4-SHA')
121
- end
122
- end if RUBY_VERSION > '1.9'
123
-
124
- context "when timeout is not set" do
125
- it "doesn't set the timeout" do
126
- http = double(
127
- "http",
128
- :null_object => true,
129
- :use_ssl= => false,
130
- :use_ssl? => false
131
- )
132
- expect(http).not_to receive(:open_timeout=)
133
- expect(http).not_to receive(:read_timeout=)
134
- allow(Net::HTTP).to receive_messages(new: http)
135
-
136
- adapter.connection
137
- end
138
- end
139
-
140
- context "when setting timeout" do
141
- context "to 5 seconds" do
142
- let(:options) { {timeout: 5} }
143
-
144
- describe '#open_timeout' do
145
- subject { super().open_timeout }
146
- it { is_expected.to eq(5) }
147
- end
148
-
149
- describe '#read_timeout' do
150
- subject { super().read_timeout }
151
- it { is_expected.to eq(5) }
152
- end
153
- end
154
-
155
- context "and timeout is a string" do
156
- let(:options) { {timeout: "five seconds"} }
157
-
158
- it "doesn't set the timeout" do
159
- http = double(
160
- "http",
161
- :null_object => true,
162
- :use_ssl= => false,
163
- :use_ssl? => false
164
- )
165
- expect(http).not_to receive(:open_timeout=)
166
- expect(http).not_to receive(:read_timeout=)
167
- allow(Net::HTTP).to receive_messages(new: http)
168
-
169
- adapter.connection
170
- end
171
- end
172
- end
173
-
174
- context "when timeout is not set and read_timeout is set to 6 seconds" do
175
- let(:options) { {read_timeout: 6} }
176
-
177
- describe '#read_timeout' do
178
- subject { super().read_timeout }
179
- it { is_expected.to eq(6) }
180
- end
181
-
182
- it "should not set the open_timeout" do
183
- http = double(
184
- "http",
185
- :null_object => true,
186
- :use_ssl= => false,
187
- :use_ssl? => false,
188
- :read_timeout= => 0
189
- )
190
- expect(http).not_to receive(:open_timeout=)
191
- allow(Net::HTTP).to receive_messages(new: http)
192
- adapter.connection
193
- end
194
- end
195
-
196
- context "when timeout is set and read_timeout is set to 6 seconds" do
197
- let(:options) { {timeout: 5, read_timeout: 6} }
198
-
199
- describe '#open_timeout' do
200
- subject { super().open_timeout }
201
- it { is_expected.to eq(5) }
202
- end
203
-
204
- describe '#read_timeout' do
205
- subject { super().read_timeout }
206
- it { is_expected.to eq(6) }
207
- end
208
-
209
- it "should override the timeout option" do
210
- http = double(
211
- "http",
212
- :null_object => true,
213
- :use_ssl= => false,
214
- :use_ssl? => false,
215
- :read_timeout= => 0,
216
- :open_timeout= => 0
217
- )
218
- expect(http).to receive(:open_timeout=)
219
- expect(http).to receive(:read_timeout=).twice
220
- allow(Net::HTTP).to receive_messages(new: http)
221
- adapter.connection
222
- end
223
- end
224
-
225
- context "when timeout is not set and open_timeout is set to 7 seconds" do
226
- let(:options) { {open_timeout: 7} }
227
-
228
- describe '#open_timeout' do
229
- subject { super().open_timeout }
230
- it { is_expected.to eq(7) }
231
- end
232
-
233
- it "should not set the read_timeout" do
234
- http = double(
235
- "http",
236
- :null_object => true,
237
- :use_ssl= => false,
238
- :use_ssl? => false,
239
- :open_timeout= => 0
240
- )
241
- expect(http).not_to receive(:read_timeout=)
242
- allow(Net::HTTP).to receive_messages(new: http)
243
- adapter.connection
244
- end
245
- end
246
-
247
- context "when timeout is set and open_timeout is set to 7 seconds" do
248
- let(:options) { {timeout: 5, open_timeout: 7} }
249
-
250
- describe '#open_timeout' do
251
- subject { super().open_timeout }
252
- it { is_expected.to eq(7) }
253
- end
254
-
255
- describe '#read_timeout' do
256
- subject { super().read_timeout }
257
- it { is_expected.to eq(5) }
258
- end
259
-
260
- it "should override the timeout option" do
261
- http = double(
262
- "http",
263
- :null_object => true,
264
- :use_ssl= => false,
265
- :use_ssl? => false,
266
- :read_timeout= => 0,
267
- :open_timeout= => 0
268
- )
269
- expect(http).to receive(:open_timeout=).twice
270
- expect(http).to receive(:read_timeout=)
271
- allow(Net::HTTP).to receive_messages(new: http)
272
- adapter.connection
273
- end
274
- end
275
-
276
- context "when debug_output" do
277
- let(:http) { Net::HTTP.new(uri) }
278
- before do
279
- allow(Net::HTTP).to receive_messages(new: http)
280
- end
281
-
282
- context "is set to $stderr" do
283
- let(:options) { {debug_output: $stderr} }
284
- it "has debug output set" do
285
- expect(http).to receive(:set_debug_output).with($stderr)
286
- adapter.connection
287
- end
288
- end
289
-
290
- context "is not provided" do
291
- it "does not set_debug_output" do
292
- expect(http).not_to receive(:set_debug_output)
293
- adapter.connection
294
- end
295
- end
296
- end
297
-
298
- context 'when providing proxy address and port' do
299
- let(:options) { {http_proxyaddr: '1.2.3.4', http_proxyport: 8080} }
300
-
301
- it { is_expected.to be_a_proxy }
302
-
303
- describe '#proxy_address' do
304
- subject { super().proxy_address }
305
- it { is_expected.to eq('1.2.3.4') }
306
- end
307
-
308
- describe '#proxy_port' do
309
- subject { super().proxy_port }
310
- it { is_expected.to eq(8080) }
311
- end
312
-
313
- context 'as well as proxy user and password' do
314
- let(:options) do
315
- {
316
- http_proxyaddr: '1.2.3.4',
317
- http_proxyport: 8080,
318
- http_proxyuser: 'user',
319
- http_proxypass: 'pass'
320
- }
321
- end
322
-
323
- describe '#proxy_user' do
324
- subject { super().proxy_user }
325
- it { is_expected.to eq('user') }
326
- end
327
-
328
- describe '#proxy_pass' do
329
- subject { super().proxy_pass }
330
- it { is_expected.to eq('pass') }
331
- end
332
- end
333
- end
334
-
335
- context 'when providing nil as proxy address' do
336
- let(:uri) { URI 'http://noproxytest.com' }
337
- let(:options) { {http_proxyaddr: nil} }
338
-
339
- it { is_expected.not_to be_a_proxy }
340
-
341
- it "does pass nil proxy parameters to the connection, this forces to not use a proxy" do
342
- http = Net::HTTP.new("noproxytest.com")
343
- expect(Net::HTTP).to receive(:new).once.with("noproxytest.com", 80, nil, nil, nil, nil).and_return(http)
344
- adapter.connection
345
- end
346
- end
347
-
348
- context 'when not providing a proxy address' do
349
- let(:uri) { URI 'http://proxytest.com' }
350
-
351
- it "does not pass any proxy parameters to the connection" do
352
- http = Net::HTTP.new("proxytest.com")
353
- expect(Net::HTTP).to receive(:new).once.with("proxytest.com", 80).and_return(http)
354
- adapter.connection
355
- end
356
- end
357
-
358
- context 'when providing a local bind address and port' do
359
- let(:options) { {local_host: "127.0.0.1", local_port: 12345 } }
360
-
361
- describe '#local_host' do
362
- subject { super().local_host }
363
- it { is_expected.to eq('127.0.0.1') }
364
- end
365
-
366
- describe '#local_port' do
367
- subject { super().local_port }
368
- it { is_expected.to eq(12345) }
369
- end
370
- end if RUBY_VERSION >= '2.0'
371
-
372
- context "when providing PEM certificates" do
373
- let(:pem) { :pem_contents }
374
- let(:options) { {pem: pem, pem_password: "password"} }
375
-
376
- context "when scheme is https" do
377
- let(:uri) { URI 'https://google.com' }
378
- let(:cert) { double("OpenSSL::X509::Certificate") }
379
- let(:key) { double("OpenSSL::PKey::RSA") }
380
-
381
- before do
382
- expect(OpenSSL::X509::Certificate).to receive(:new).with(pem).and_return(cert)
383
- expect(OpenSSL::PKey::RSA).to receive(:new).with(pem, "password").and_return(key)
384
- end
385
-
386
- it "uses the provided PEM certificate" do
387
- expect(subject.cert).to eq(cert)
388
- expect(subject.key).to eq(key)
389
- end
390
-
391
- it "will verify the certificate" do
392
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
393
- end
394
-
395
- context "when options include verify=false" do
396
- let(:options) { {pem: pem, pem_password: "password", verify: false} }
397
-
398
- it "should not verify the certificate" do
399
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
400
- end
401
- end
402
- context "when options include verify_peer=false" do
403
- let(:options) { {pem: pem, pem_password: "password", verify_peer: false} }
404
-
405
- it "should not verify the certificate" do
406
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
407
- end
408
- end
409
- end
410
-
411
- context "when scheme is not https" do
412
- let(:uri) { URI 'http://google.com' }
413
- let(:http) { Net::HTTP.new(uri) }
414
-
415
- before do
416
- allow(Net::HTTP).to receive_messages(new: http)
417
- expect(OpenSSL::X509::Certificate).not_to receive(:new).with(pem)
418
- expect(OpenSSL::PKey::RSA).not_to receive(:new).with(pem, "password")
419
- expect(http).not_to receive(:cert=)
420
- expect(http).not_to receive(:key=)
421
- end
422
-
423
- it "has no PEM certificate " do
424
- expect(subject.cert).to be_nil
425
- expect(subject.key).to be_nil
426
- end
427
- end
428
- end
429
-
430
- context "when providing PKCS12 certificates" do
431
- let(:p12) { :p12_contents }
432
- let(:options) { {p12: p12, p12_password: "password"} }
433
-
434
- context "when scheme is https" do
435
- let(:uri) { URI 'https://google.com' }
436
- let(:pkcs12) { double("OpenSSL::PKCS12", certificate: cert, key: key) }
437
- let(:cert) { double("OpenSSL::X509::Certificate") }
438
- let(:key) { double("OpenSSL::PKey::RSA") }
439
-
440
- before do
441
- expect(OpenSSL::PKCS12).to receive(:new).with(p12, "password").and_return(pkcs12)
442
- end
443
-
444
- it "uses the provided P12 certificate " do
445
- expect(subject.cert).to eq(cert)
446
- expect(subject.key).to eq(key)
447
- end
448
-
449
- it "will verify the certificate" do
450
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
451
- end
452
-
453
- context "when options include verify=false" do
454
- let(:options) { {p12: p12, p12_password: "password", verify: false} }
455
-
456
- it "should not verify the certificate" do
457
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
458
- end
459
- end
460
- context "when options include verify_peer=false" do
461
- let(:options) { {p12: p12, p12_password: "password", verify_peer: false} }
462
-
463
- it "should not verify the certificate" do
464
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
465
- end
466
- end
467
- end
468
-
469
- context "when scheme is not https" do
470
- let(:uri) { URI 'http://google.com' }
471
- let(:http) { Net::HTTP.new(uri) }
472
-
473
- before do
474
- allow(Net::HTTP).to receive_messages(new: http)
475
- expect(OpenSSL::PKCS12).not_to receive(:new).with(p12, "password")
476
- expect(http).not_to receive(:cert=)
477
- expect(http).not_to receive(:key=)
478
- end
479
-
480
- it "has no PKCS12 certificate " do
481
- expect(subject.cert).to be_nil
482
- expect(subject.key).to be_nil
483
- end
484
- end
485
- end
486
-
487
- context "when uri port is not defined" do
488
- context "falls back to 80 port on http" do
489
- let(:uri) { URI 'http://foobar.com' }
490
- before { allow(uri).to receive(:port).and_return(nil) }
491
- it { expect(subject.port).to be 80 }
492
- end
493
-
494
- context "falls back to 443 port on https" do
495
- let(:uri) { URI 'https://foobar.com' }
496
- before { allow(uri).to receive(:port).and_return(nil) }
497
- it { expect(subject.port).to be 443 }
498
- end
499
- end
500
- end
501
- end
502
- end
@@ -1,100 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe HTTParty::CookieHash do
4
- before(:each) do
5
- @cookie_hash = HTTParty::CookieHash.new
6
- end
7
-
8
- describe "#add_cookies" do
9
- describe "with a hash" do
10
- it "should add new key/value pairs to the hash" do
11
- @cookie_hash.add_cookies(foo: "bar")
12
- @cookie_hash.add_cookies(rofl: "copter")
13
- expect(@cookie_hash.length).to eql(2)
14
- end
15
-
16
- it "should overwrite any existing key" do
17
- @cookie_hash.add_cookies(foo: "bar")
18
- @cookie_hash.add_cookies(foo: "copter")
19
- expect(@cookie_hash.length).to eql(1)
20
- expect(@cookie_hash[:foo]).to eql("copter")
21
- end
22
- end
23
-
24
- describe "with a string" do
25
- it "should add new key/value pairs to the hash" do
26
- @cookie_hash.add_cookies("first=one; second=two; third")
27
- expect(@cookie_hash[:first]).to eq('one')
28
- expect(@cookie_hash[:second]).to eq('two')
29
- expect(@cookie_hash[:third]).to eq(nil)
30
- end
31
-
32
- it "should overwrite any existing key" do
33
- @cookie_hash[:foo] = 'bar'
34
- @cookie_hash.add_cookies("foo=tar")
35
- expect(@cookie_hash.length).to eql(1)
36
- expect(@cookie_hash[:foo]).to eql("tar")
37
- end
38
-
39
- it "should handle '=' within cookie value" do
40
- @cookie_hash.add_cookies("first=one=1; second=two=2==")
41
- expect(@cookie_hash.keys).to include(:first, :second)
42
- expect(@cookie_hash[:first]).to eq('one=1')
43
- expect(@cookie_hash[:second]).to eq('two=2==')
44
- end
45
- end
46
-
47
- describe 'with other class' do
48
- it "should error" do
49
- expect {
50
- @cookie_hash.add_cookies([])
51
- }.to raise_error(RuntimeError)
52
- end
53
- end
54
- end
55
-
56
- # The regexen are required because Hashes aren't ordered, so a test against
57
- # a hardcoded string was randomly failing.
58
- describe "#to_cookie_string" do
59
- before(:each) do
60
- @cookie_hash.add_cookies(foo: "bar")
61
- @cookie_hash.add_cookies(rofl: "copter")
62
- @s = @cookie_hash.to_cookie_string
63
- end
64
-
65
- it "should format the key/value pairs, delimited by semi-colons" do
66
- expect(@s).to match(/foo=bar/)
67
- expect(@s).to match(/rofl=copter/)
68
- expect(@s).to match(/^\w+=\w+; \w+=\w+$/)
69
- end
70
-
71
- it "should not include client side only cookies" do
72
- @cookie_hash.add_cookies(path: "/")
73
- @s = @cookie_hash.to_cookie_string
74
- expect(@s).not_to match(/path=\//)
75
- end
76
-
77
- it "should not include client side only cookies even when attributes use camal case" do
78
- @cookie_hash.add_cookies(Path: "/")
79
- @s = @cookie_hash.to_cookie_string
80
- expect(@s).not_to match(/Path=\//)
81
- end
82
-
83
- it "should not mutate the hash" do
84
- original_hash = {
85
- "session" => "91e25e8b-6e32-418d-c72f-2d18adf041cd",
86
- "Max-Age" => "15552000",
87
- "cart" => "91e25e8b-6e32-418d-c72f-2d18adf041cd",
88
- "httponly" => nil,
89
- "Path" => "/",
90
- "secure" => nil,
91
- }
92
-
93
- cookie_hash = HTTParty::CookieHash[original_hash]
94
-
95
- cookie_hash.to_cookie_string
96
-
97
- expect(cookie_hash).to eq(original_hash)
98
- end
99
- end
100
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe HTTParty::Error do
4
- subject { described_class }
5
-
6
- describe '#ancestors' do
7
- subject { super().ancestors }
8
- it { is_expected.to include(StandardError) }
9
- end
10
-
11
- describe HTTParty::UnsupportedFormat do
12
- describe '#ancestors' do
13
- subject { super().ancestors }
14
- it { is_expected.to include(HTTParty::Error) }
15
- end
16
- end
17
-
18
- describe HTTParty::UnsupportedURIScheme do
19
- describe '#ancestors' do
20
- subject { super().ancestors }
21
- it { is_expected.to include(HTTParty::Error) }
22
- end
23
- end
24
-
25
- describe HTTParty::ResponseError do
26
- describe '#ancestors' do
27
- subject { super().ancestors }
28
- it { is_expected.to include(HTTParty::Error) }
29
- end
30
- end
31
-
32
- describe HTTParty::RedirectionTooDeep do
33
- describe '#ancestors' do
34
- subject { super().ancestors }
35
- it { is_expected.to include(HTTParty::ResponseError) }
36
- end
37
- end
38
-
39
- describe HTTParty::DuplicateLocationHeader do
40
- describe '#ancestors' do
41
- subject { super().ancestors }
42
- it { is_expected.to include(HTTParty::ResponseError) }
43
- end
44
- end
45
- end
@@ -1,14 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
2
-
3
- RSpec.describe HTTParty::FragmentWithResponse do
4
- it "access to fragment" do
5
- fragment = HTTParty::FragmentWithResponse.new("chunk", nil)
6
- expect(fragment).to eq("chunk")
7
- end
8
- it "has access to delegators" do
9
- response = double(code: '200')
10
- fragment = HTTParty::FragmentWithResponse.new("chunk", response)
11
- expect(fragment.code).to eq(200)
12
- expect(fragment.http_response).to eq response
13
- end
14
- end