httparty 0.15.4 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

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