httparty 0.16.2 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +5 -5
  2. data/.editorconfig +18 -0
  3. data/.github/workflows/ci.yml +26 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop_todo.yml +1 -1
  6. data/Changelog.md +78 -0
  7. data/Gemfile +7 -0
  8. data/Guardfile +3 -2
  9. data/README.md +5 -5
  10. data/docs/README.md +90 -5
  11. data/examples/README.md +28 -11
  12. data/examples/aaws.rb +6 -2
  13. data/examples/body_stream.rb +14 -0
  14. data/examples/idn.rb +10 -0
  15. data/examples/microsoft_graph.rb +52 -0
  16. data/examples/multipart.rb +22 -0
  17. data/examples/peer_cert.rb +9 -0
  18. data/examples/stream_download.rb +8 -2
  19. data/httparty.gemspec +3 -3
  20. data/lib/httparty/connection_adapter.rb +59 -16
  21. data/lib/httparty/cookie_hash.rb +10 -8
  22. data/lib/httparty/decompressor.rb +102 -0
  23. data/lib/httparty/exceptions.rb +3 -1
  24. data/lib/httparty/hash_conversions.rb +10 -4
  25. data/lib/httparty/headers_processor.rb +32 -0
  26. data/lib/httparty/logger/apache_formatter.rb +31 -6
  27. data/lib/httparty/logger/curl_formatter.rb +9 -7
  28. data/lib/httparty/logger/logger.rb +5 -1
  29. data/lib/httparty/logger/logstash_formatter.rb +61 -0
  30. data/lib/httparty/module_inheritable_attributes.rb +6 -4
  31. data/lib/httparty/net_digest_auth.rb +15 -15
  32. data/lib/httparty/parser.rb +9 -5
  33. data/lib/httparty/request/body.rb +53 -27
  34. data/lib/httparty/request/multipart_boundary.rb +2 -0
  35. data/lib/httparty/request.rb +79 -96
  36. data/lib/httparty/response/headers.rb +4 -2
  37. data/lib/httparty/response.rb +51 -8
  38. data/lib/httparty/response_fragment.rb +21 -0
  39. data/lib/httparty/text_encoder.rb +72 -0
  40. data/lib/httparty/utils.rb +13 -0
  41. data/lib/httparty/version.rb +3 -1
  42. data/lib/httparty.rb +70 -25
  43. data/website/css/common.css +1 -1
  44. metadata +35 -107
  45. data/.simplecov +0 -1
  46. data/.travis.yml +0 -10
  47. data/features/basic_authentication.feature +0 -20
  48. data/features/command_line.feature +0 -95
  49. data/features/deals_with_http_error_codes.feature +0 -26
  50. data/features/digest_authentication.feature +0 -30
  51. data/features/handles_compressed_responses.feature +0 -27
  52. data/features/handles_multiple_formats.feature +0 -57
  53. data/features/steps/env.rb +0 -27
  54. data/features/steps/httparty_response_steps.rb +0 -56
  55. data/features/steps/httparty_steps.rb +0 -43
  56. data/features/steps/mongrel_helper.rb +0 -127
  57. data/features/steps/remote_service_steps.rb +0 -92
  58. data/features/supports_read_timeout_option.feature +0 -13
  59. data/features/supports_redirection.feature +0 -22
  60. data/features/supports_timeout_option.feature +0 -13
  61. data/spec/fixtures/delicious.xml +0 -23
  62. data/spec/fixtures/empty.xml +0 -0
  63. data/spec/fixtures/google.html +0 -3
  64. data/spec/fixtures/ssl/generate.sh +0 -29
  65. data/spec/fixtures/ssl/generated/bogushost.crt +0 -13
  66. data/spec/fixtures/ssl/generated/ca.crt +0 -16
  67. data/spec/fixtures/ssl/generated/ca.key +0 -15
  68. data/spec/fixtures/ssl/generated/selfsigned.crt +0 -14
  69. data/spec/fixtures/ssl/generated/server.crt +0 -13
  70. data/spec/fixtures/ssl/generated/server.key +0 -15
  71. data/spec/fixtures/ssl/openssl-exts.cnf +0 -9
  72. data/spec/fixtures/tiny.gif +0 -0
  73. data/spec/fixtures/twitter.csv +0 -2
  74. data/spec/fixtures/twitter.json +0 -1
  75. data/spec/fixtures/twitter.xml +0 -403
  76. data/spec/fixtures/undefined_method_add_node_for_nil.xml +0 -2
  77. data/spec/httparty/connection_adapter_spec.rb +0 -498
  78. data/spec/httparty/cookie_hash_spec.rb +0 -100
  79. data/spec/httparty/exception_spec.rb +0 -45
  80. data/spec/httparty/hash_conversions_spec.rb +0 -56
  81. data/spec/httparty/logger/apache_formatter_spec.rb +0 -41
  82. data/spec/httparty/logger/curl_formatter_spec.rb +0 -119
  83. data/spec/httparty/logger/logger_spec.rb +0 -38
  84. data/spec/httparty/net_digest_auth_spec.rb +0 -270
  85. data/spec/httparty/parser_spec.rb +0 -190
  86. data/spec/httparty/request/body_spec.rb +0 -60
  87. data/spec/httparty/request_spec.rb +0 -1312
  88. data/spec/httparty/response_spec.rb +0 -347
  89. data/spec/httparty/ssl_spec.rb +0 -74
  90. data/spec/httparty_spec.rb +0 -896
  91. data/spec/spec_helper.rb +0 -51
  92. data/spec/support/ssl_test_helper.rb +0 -47
  93. data/spec/support/ssl_test_server.rb +0 -80
  94. data/spec/support/stub_response.rb +0 -49
@@ -1,498 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '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
- {http_proxyaddr: '1.2.3.4', http_proxyport: 8080,
316
- http_proxyuser: 'user', http_proxypass: 'pass'}
317
- end
318
-
319
- describe '#proxy_user' do
320
- subject { super().proxy_user }
321
- it { is_expected.to eq('user') }
322
- end
323
-
324
- describe '#proxy_pass' do
325
- subject { super().proxy_pass }
326
- it { is_expected.to eq('pass') }
327
- end
328
- end
329
- end
330
-
331
- context 'when providing nil as proxy address' do
332
- let(:uri) { URI 'http://noproxytest.com' }
333
- let(:options) { {http_proxyaddr: nil} }
334
-
335
- it { is_expected.not_to be_a_proxy }
336
-
337
- it "does pass nil proxy parameters to the connection, this forces to not use a proxy" do
338
- http = Net::HTTP.new("noproxytest.com")
339
- expect(Net::HTTP).to receive(:new).once.with("noproxytest.com", 80, nil, nil, nil, nil).and_return(http)
340
- adapter.connection
341
- end
342
- end
343
-
344
- context 'when not providing a proxy address' do
345
- let(:uri) { URI 'http://proxytest.com' }
346
-
347
- it "does not pass any proxy parameters to the connection" do
348
- http = Net::HTTP.new("proxytest.com")
349
- expect(Net::HTTP).to receive(:new).once.with("proxytest.com", 80).and_return(http)
350
- adapter.connection
351
- end
352
- end
353
-
354
- context 'when providing a local bind address and port' do
355
- let(:options) { {local_host: "127.0.0.1", local_port: 12345 } }
356
-
357
- describe '#local_host' do
358
- subject { super().local_host }
359
- it { is_expected.to eq('127.0.0.1') }
360
- end
361
-
362
- describe '#local_port' do
363
- subject { super().local_port }
364
- it { is_expected.to eq(12345) }
365
- end
366
- end if RUBY_VERSION >= '2.0'
367
-
368
- context "when providing PEM certificates" do
369
- let(:pem) { :pem_contents }
370
- let(:options) { {pem: pem, pem_password: "password"} }
371
-
372
- context "when scheme is https" do
373
- let(:uri) { URI 'https://google.com' }
374
- let(:cert) { double("OpenSSL::X509::Certificate") }
375
- let(:key) { double("OpenSSL::PKey::RSA") }
376
-
377
- before do
378
- expect(OpenSSL::X509::Certificate).to receive(:new).with(pem).and_return(cert)
379
- expect(OpenSSL::PKey::RSA).to receive(:new).with(pem, "password").and_return(key)
380
- end
381
-
382
- it "uses the provided PEM certificate" do
383
- expect(subject.cert).to eq(cert)
384
- expect(subject.key).to eq(key)
385
- end
386
-
387
- it "will verify the certificate" do
388
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
389
- end
390
-
391
- context "when options include verify=false" do
392
- let(:options) { {pem: pem, pem_password: "password", verify: false} }
393
-
394
- it "should not verify the certificate" do
395
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
396
- end
397
- end
398
- context "when options include verify_peer=false" do
399
- let(:options) { {pem: pem, pem_password: "password", verify_peer: false} }
400
-
401
- it "should not verify the certificate" do
402
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
403
- end
404
- end
405
- end
406
-
407
- context "when scheme is not https" do
408
- let(:uri) { URI 'http://google.com' }
409
- let(:http) { Net::HTTP.new(uri) }
410
-
411
- before do
412
- allow(Net::HTTP).to receive_messages(new: http)
413
- expect(OpenSSL::X509::Certificate).not_to receive(:new).with(pem)
414
- expect(OpenSSL::PKey::RSA).not_to receive(:new).with(pem, "password")
415
- expect(http).not_to receive(:cert=)
416
- expect(http).not_to receive(:key=)
417
- end
418
-
419
- it "has no PEM certificate " do
420
- expect(subject.cert).to be_nil
421
- expect(subject.key).to be_nil
422
- end
423
- end
424
- end
425
-
426
- context "when providing PKCS12 certificates" do
427
- let(:p12) { :p12_contents }
428
- let(:options) { {p12: p12, p12_password: "password"} }
429
-
430
- context "when scheme is https" do
431
- let(:uri) { URI 'https://google.com' }
432
- let(:pkcs12) { double("OpenSSL::PKCS12", certificate: cert, key: key) }
433
- let(:cert) { double("OpenSSL::X509::Certificate") }
434
- let(:key) { double("OpenSSL::PKey::RSA") }
435
-
436
- before do
437
- expect(OpenSSL::PKCS12).to receive(:new).with(p12, "password").and_return(pkcs12)
438
- end
439
-
440
- it "uses the provided P12 certificate " do
441
- expect(subject.cert).to eq(cert)
442
- expect(subject.key).to eq(key)
443
- end
444
-
445
- it "will verify the certificate" do
446
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_PEER)
447
- end
448
-
449
- context "when options include verify=false" do
450
- let(:options) { {p12: p12, p12_password: "password", verify: false} }
451
-
452
- it "should not verify the certificate" do
453
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
454
- end
455
- end
456
- context "when options include verify_peer=false" do
457
- let(:options) { {p12: p12, p12_password: "password", verify_peer: false} }
458
-
459
- it "should not verify the certificate" do
460
- expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
461
- end
462
- end
463
- end
464
-
465
- context "when scheme is not https" do
466
- let(:uri) { URI 'http://google.com' }
467
- let(:http) { Net::HTTP.new(uri) }
468
-
469
- before do
470
- allow(Net::HTTP).to receive_messages(new: http)
471
- expect(OpenSSL::PKCS12).not_to receive(:new).with(p12, "password")
472
- expect(http).not_to receive(:cert=)
473
- expect(http).not_to receive(:key=)
474
- end
475
-
476
- it "has no PKCS12 certificate " do
477
- expect(subject.cert).to be_nil
478
- expect(subject.key).to be_nil
479
- end
480
- end
481
- end
482
-
483
- context "when uri port is not defined" do
484
- context "falls back to 80 port on http" do
485
- let(:uri) { URI 'http://foobar.com' }
486
- before { allow(uri).to receive(:port).and_return(nil) }
487
- it { expect(subject.port).to be 80 }
488
- end
489
-
490
- context "falls back to 443 port on https" do
491
- let(:uri) { URI 'https://foobar.com' }
492
- before { allow(uri).to receive(:port).and_return(nil) }
493
- it { expect(subject.port).to be 443 }
494
- end
495
- end
496
- end
497
- end
498
- end
@@ -1,100 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '../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 File.expand_path(File.join(File.dirname(__FILE__), '..', '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,56 +0,0 @@
1
- RSpec.describe HTTParty::HashConversions do
2
- describe ".to_params" do
3
- it "creates a params string from a hash" do
4
- hash = {
5
- name: "bob",
6
- address: {
7
- street: '111 ruby ave.',
8
- city: 'ruby central',
9
- phones: ['111-111-1111', '222-222-2222']
10
- }
11
- }
12
- expect(HTTParty::HashConversions.to_params(hash)).to eq("name=bob&address[street]=111%20ruby%20ave.&address[city]=ruby%20central&address[phones][]=111-111-1111&address[phones][]=222-222-2222")
13
- end
14
-
15
- context "nested params" do
16
- it 'creates a params string from a hash' do
17
- hash = { marketing_event: { marketed_resources: [ {type:"product", id: 57474842640 } ] } }
18
- expect(HTTParty::HashConversions.to_params(hash)).to eq("marketing_event[marketed_resources][][type]=product&marketing_event[marketed_resources][][id]=57474842640")
19
- end
20
- end
21
- end
22
-
23
- describe ".normalize_param" do
24
- context "value is an array" do
25
- it "creates a params string" do
26
- expect(
27
- HTTParty::HashConversions.normalize_param(:people, ["Bob Jones", "Mike Smith"])
28
- ).to eq("people[]=Bob%20Jones&people[]=Mike%20Smith&")
29
- end
30
- end
31
-
32
- context "value is an empty array" do
33
- it "creates a params string" do
34
- expect(
35
- HTTParty::HashConversions.normalize_param(:people, [])
36
- ).to eq("people[]=&")
37
- end
38
- end
39
-
40
- context "value is hash" do
41
- it "creates a params string" do
42
- expect(
43
- HTTParty::HashConversions.normalize_param(:person, { name: "Bob Jones" })
44
- ).to eq("person[name]=Bob%20Jones&")
45
- end
46
- end
47
-
48
- context "value is a string" do
49
- it "creates a params string" do
50
- expect(
51
- HTTParty::HashConversions.normalize_param(:name, "Bob Jones")
52
- ).to eq("name=Bob%20Jones&")
53
- end
54
- end
55
- end
56
- end