curb 0.8.4 → 0.9.11

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.
@@ -4,6 +4,82 @@ class FooNoToS
4
4
  end
5
5
 
6
6
  class TestCurbCurlEasy < Test::Unit::TestCase
7
+ def test_global_reset
8
+ Curl.get($TEST_URL)
9
+ # in a Timeout block you should reset the thread current handle
10
+ Curl.reset
11
+ end
12
+
13
+ def test_curlopt_stderr_with_file
14
+ # does not work with Tempfile directly
15
+ path = Tempfile.new('curb_test_curlopt_stderr').path
16
+ File.open(path, 'w') do |file|
17
+ easy = Curl::Easy.new(TestServlet.url)
18
+ easy.verbose = true
19
+ easy.setopt(Curl::CURLOPT_STDERR, file)
20
+ easy.perform
21
+ end
22
+ output = File.read(path)
23
+
24
+ assert_match('HTTP/1.1 200 OK ', output)
25
+ assert_match('Host: 127.0.0.1:9129', output)
26
+ end
27
+
28
+ def test_curlopt_stderr_with_io
29
+ path = Tempfile.new('curb_test_curlopt_stderr').path
30
+ fd = IO.sysopen(path, 'w')
31
+ io = IO.for_fd(fd)
32
+
33
+ easy = Curl::Easy.new(TestServlet.url)
34
+ easy.verbose = true
35
+ easy.setopt(Curl::CURLOPT_STDERR, io)
36
+ easy.perform
37
+
38
+
39
+ output = File.read(path)
40
+
41
+ assert_match(output, 'HTTP/1.1 200 OK')
42
+ assert_match(output, 'Host: 127.0.0.1:9129')
43
+ end
44
+
45
+ def test_curlopt_stderr_fails_with_tempdir
46
+ Tempfile.open('curb_test_curlopt_stderr') do |tempfile|
47
+ easy = Curl::Easy.new(TestServlet.url)
48
+
49
+ assert_raise(TypeError) do
50
+ easy.setopt(Curl::CURLOPT_STDERR, tempfile)
51
+ end
52
+ end
53
+ end
54
+
55
+ def test_curlopt_stderr_fails_with_stringio
56
+ stringio = StringIO.new
57
+ easy = Curl::Easy.new(TestServlet.url)
58
+
59
+ assert_raise(TypeError) do
60
+ easy.setopt(Curl::CURLOPT_STDERR, stringio)
61
+ end
62
+ end
63
+
64
+ def test_curlopt_stderr_fails_with_string
65
+ string = String.new
66
+ easy = Curl::Easy.new(TestServlet.url)
67
+
68
+ assert_raise(TypeError) do
69
+ easy.setopt(Curl::CURLOPT_STDERR, string)
70
+ end
71
+ end
72
+
73
+ def test_exception
74
+ begin
75
+ Curl.get('NOT_FOUND_URL')
76
+ rescue
77
+ assert true
78
+ rescue Exception
79
+ assert false, "We should raise StandardError"
80
+ end
81
+ end
82
+
7
83
  def test_threads
8
84
  t = []
9
85
  5.times do
@@ -11,18 +87,18 @@ class TestCurbCurlEasy < Test::Unit::TestCase
11
87
  5.times do
12
88
  c = Curl.get($TEST_URL)
13
89
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
14
- assert_equal "", c.header_str
90
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
15
91
  end
16
92
  end
17
93
  end
18
94
 
19
- t.each {|t| t.join }
95
+ t.each {|x| x.join }
20
96
  end
21
97
 
22
98
  def test_class_perform_01
23
99
  assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL)
24
100
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
25
- assert_equal "", c.header_str
101
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body)
26
102
  end
27
103
 
28
104
  def test_class_perform_02
@@ -30,12 +106,11 @@ class TestCurbCurlEasy < Test::Unit::TestCase
30
106
  assert_instance_of Curl::Easy, c = Curl::Easy.perform($TEST_URL) { |curl| curl.on_body { |d| data << d; d.length } }
31
107
 
32
108
  assert_nil c.body_str
33
- assert_equal "", c.header_str
34
109
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)
35
110
  end
36
111
 
37
112
  def test_class_perform_03
38
- assert_raise(Curl::Err::CouldntReadError) { c = Curl::Easy.perform($TEST_URL + "nonexistent") }
113
+ assert_raise(Curl::Err::CouldntReadError) { Curl::Easy.perform($TEST_URL + "nonexistent") }
39
114
  end
40
115
 
41
116
  def test_new_01
@@ -125,7 +200,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
125
200
  c = Curl::Easy.new($TEST_URL)
126
201
  assert_equal true, c.http_get
127
202
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
128
- assert_equal "", c.header_str
129
203
  end
130
204
 
131
205
  def test_get_02
@@ -137,7 +211,6 @@ class TestCurbCurlEasy < Test::Unit::TestCase
137
211
  assert_equal true, c.http_get
138
212
 
139
213
  assert_nil c.body_str
140
- assert_equal "", c.header_str
141
214
  assert_match(/^# DO NOT REMOVE THIS COMMENT/, data)
142
215
  end
143
216
 
@@ -320,19 +393,71 @@ class TestCurbCurlEasy < Test::Unit::TestCase
320
393
  c.max_redirects = nil
321
394
  assert_nil c.max_redirects
322
395
  end
323
-
396
+
397
+ def test_timeout_with_floats
398
+ c = Curl::Easy.new($TEST_URL)
399
+
400
+ c.timeout = 1.5
401
+ assert_equal 1500, c.timeout_ms
402
+ assert_equal 1.5, c.timeout
403
+ end
404
+
405
+ def test_timeout_with_negative
406
+ c = Curl::Easy.new($TEST_URL)
407
+
408
+ c.timeout = -1.5
409
+ assert_equal 0, c.timeout
410
+ assert_equal 0, c.timeout_ms
411
+
412
+ c.timeout = -4.8
413
+ assert_equal 0, c.timeout
414
+ assert_equal 0, c.timeout_ms
415
+ end
416
+
324
417
  def test_timeout_01
325
418
  c = Curl::Easy.new($TEST_URL)
326
-
327
- assert_nil c.timeout
328
-
419
+
420
+ assert_equal 0, c.timeout
421
+
329
422
  c.timeout = 3
330
423
  assert_equal 3, c.timeout
331
-
332
- c.timeout = nil
333
- assert_nil c.timeout
424
+
425
+ c.timeout = 0
426
+ assert_equal 0, c.timeout
334
427
  end
335
-
428
+
429
+ def test_timeout_ms_01
430
+ c = Curl::Easy.new($TEST_URL)
431
+
432
+ assert_equal 0, c.timeout_ms
433
+
434
+ c.timeout_ms = 100
435
+ assert_equal 100, c.timeout_ms
436
+
437
+ c.timeout_ms = nil
438
+ assert_equal 0, c.timeout_ms
439
+ end
440
+
441
+ def test_timeout_ms_with_floats
442
+ c = Curl::Easy.new($TEST_URL)
443
+
444
+ c.timeout_ms = 55.5
445
+ assert_equal 55, c.timeout_ms
446
+ assert_equal 0.055, c.timeout
447
+ end
448
+
449
+ def test_timeout_ms_with_negative
450
+ c = Curl::Easy.new($TEST_URL)
451
+
452
+ c.timeout_ms = -1.5
453
+ assert_equal 0, c.timeout
454
+ assert_equal 0, c.timeout_ms
455
+
456
+ c.timeout_ms = -4.8
457
+ assert_equal 0, c.timeout
458
+ assert_equal 0, c.timeout_ms
459
+ end
460
+
336
461
  def test_connect_timeout_01
337
462
  c = Curl::Easy.new($TEST_URL)
338
463
 
@@ -344,7 +469,19 @@ class TestCurbCurlEasy < Test::Unit::TestCase
344
469
  c.connect_timeout = nil
345
470
  assert_nil c.connect_timeout
346
471
  end
347
-
472
+
473
+ def test_connect_timeout_ms_01
474
+ c = Curl::Easy.new($TEST_URL)
475
+
476
+ assert_nil c.connect_timeout_ms
477
+
478
+ c.connect_timeout_ms = 100
479
+ assert_equal 100, c.connect_timeout_ms
480
+
481
+ c.connect_timeout_ms = nil
482
+ assert_nil c.connect_timeout_ms
483
+ end
484
+
348
485
  def test_ftp_response_timeout_01
349
486
  c = Curl::Easy.new($TEST_URL)
350
487
 
@@ -562,6 +699,15 @@ class TestCurbCurlEasy < Test::Unit::TestCase
562
699
  assert_equal "some.file", c.cookiejar
563
700
  end
564
701
 
702
+ def test_cookielist
703
+ c = Curl::Easy.new TestServlet.url
704
+ c.enable_cookies = true
705
+ c.post_body = URI.encode_www_form('c' => 'somename=somevalue')
706
+ assert_nil c.cookielist
707
+ c.perform
708
+ assert_match(/somevalue/, c.cookielist.join(''))
709
+ end
710
+
565
711
  def test_on_success
566
712
  curl = Curl::Easy.new($TEST_URL)
567
713
  on_success_called = false
@@ -624,7 +770,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
624
770
  retries = 0
625
771
  begin
626
772
  count = 0
627
- curl = Curl::Easy.send("http_#{method}", TestServlet.url) do|c|
773
+ Curl::Easy.send("http_#{method}", TestServlet.url) do|c|
628
774
  count += 1
629
775
  assert_equal Curl::Easy, c.class
630
776
  end
@@ -642,12 +788,12 @@ class TestCurbCurlEasy < Test::Unit::TestCase
642
788
  curl = Curl::Easy.new(TestServlet.url)
643
789
  curl.multipart_form_post = true
644
790
  fields = [
645
- Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README'))),
646
- Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))
791
+ Curl::PostField.file('foo', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))),
792
+ Curl::PostField.file('bar', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
647
793
  ]
648
794
  curl.http_post(fields)
649
- assert_match /HTTP POST file upload/, curl.body_str
650
- assert_match /Content-Disposition: form-data/, curl.body_str
795
+ assert_match(/HTTP POST file upload/, curl.body_str)
796
+ assert_match(/Content-Disposition: form-data/, curl.body_str)
651
797
  end
652
798
 
653
799
  def test_post_with_body_remote
@@ -671,10 +817,10 @@ class TestCurbCurlEasy < Test::Unit::TestCase
671
817
  def test_post_multipart_file_remote
672
818
  curl = Curl::Easy.new(TestServlet.url)
673
819
  curl.multipart_form_post = true
674
- pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README')))
820
+ pf = Curl::PostField.file('readme', File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown')))
675
821
  curl.http_post(pf)
676
- assert_match /HTTP POST file upload/, curl.body_str
677
- assert_match /Content-Disposition: form-data/, curl.body_str
822
+ assert_match(/HTTP POST file upload/, curl.body_str)
823
+ assert_match(/Content-Disposition: form-data/, curl.body_str)
678
824
  end
679
825
 
680
826
  def test_delete_remote
@@ -696,7 +842,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
696
842
  redirect = curl.header_str.match(/Location: (.*)/)
697
843
 
698
844
  assert_equal '', curl.body_str
699
- assert_match '/nonexistent', redirect[1]
845
+ assert_match('/nonexistent', redirect[1])
700
846
  end
701
847
 
702
848
  def test_head_accessor
@@ -707,7 +853,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
707
853
  redirect = curl.header_str.match(/Location: (.*)/)
708
854
 
709
855
  assert_equal '', curl.body_str
710
- assert_match '/nonexistent', redirect[1]
856
+ assert_match('/nonexistent', redirect[1])
711
857
  curl.head = false
712
858
  curl.perform
713
859
  assert_equal 'GET', curl.body_str
@@ -717,9 +863,11 @@ class TestCurbCurlEasy < Test::Unit::TestCase
717
863
  curl = Curl::Easy.new(TestServlet.url)
718
864
  curl.headers['Content-Type'] = 'application/json'
719
865
  assert curl.http_put("message")
720
- assert_match /^PUT/, curl.body_str
721
- assert_match /message$/, curl.body_str
722
- assert_match /application\/json/, curl.header_str
866
+ assert_match(/^PUT/, curl.body_str)
867
+ assert_match(/message$/, curl.body_str)
868
+ assert_match(/message$/, curl.body)
869
+ assert_match(/application\/json/, curl.header_str)
870
+ assert_match(/application\/json/, curl.head)
723
871
  end
724
872
 
725
873
  def test_put_data
@@ -728,8 +876,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
728
876
 
729
877
  curl.perform
730
878
 
731
- assert_match /^PUT/, curl.body_str
732
- assert_match /message$/, curl.body_str
879
+ assert_match(/^PUT/, curl.body_str)
880
+ assert_match(/message$/, curl.body_str)
733
881
  end
734
882
 
735
883
  # https://github.com/taf2/curb/issues/101
@@ -739,8 +887,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
739
887
 
740
888
  curl.perform
741
889
 
742
- assert_match /^PUT/, curl.body_str
743
- assert_match "a\0b", curl.body_str
890
+ assert_match(/^PUT/, curl.body_str)
891
+ assert_match("a\0b", curl.body_str)
744
892
  end
745
893
 
746
894
  def test_put_nil_data_no_crash
@@ -755,7 +903,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
755
903
  File.open(__FILE__,'rb') do|f|
756
904
  assert curl.http_put(f)
757
905
  end
758
- assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
906
+ assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str.tr("\r", '')
759
907
  end
760
908
 
761
909
  def test_put_class_method
@@ -765,7 +913,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
765
913
  assert_equal Curl::Easy, c.class
766
914
  end
767
915
  assert_equal 1, count
768
- assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str
916
+ assert_equal "PUT\n#{File.read(__FILE__)}", curl.body_str.tr("\r", '')
769
917
  end
770
918
 
771
919
  # Generate a self-signed cert with
@@ -774,7 +922,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
774
922
  def test_cert
775
923
  curl = Curl::Easy.new(TestServlet.url)
776
924
  curl.cert= File.join(File.dirname(__FILE__),"cert.pem")
777
- assert_match /cert.pem$/,curl.cert
925
+ assert_match(/cert.pem$/,curl.cert)
778
926
  end
779
927
 
780
928
  def test_cert_with_password
@@ -782,7 +930,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
782
930
  path = File.join(File.dirname(__FILE__),"cert.pem")
783
931
  curl.certpassword = 'password'
784
932
  curl.cert = path
785
- assert_match /cert.pem$/,curl.cert
933
+ assert_match(/cert.pem$/,curl.cert)
786
934
  end
787
935
 
788
936
  def test_cert_type
@@ -803,7 +951,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
803
951
  def test_ca_cert
804
952
  curl = Curl::Easy.new(TestServlet.url)
805
953
  curl.cacert= File.join(File.dirname(__FILE__),"cacert.pem")
806
- assert_match /cacert.pem$/, curl.cacert
954
+ assert_match(/cacert.pem$/, curl.cacert)
807
955
  end
808
956
 
809
957
  def test_user_agent
@@ -850,7 +998,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
850
998
  end
851
999
 
852
1000
  def test_post_streaming
853
- readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README'))
1001
+ readme = File.expand_path(File.join(File.dirname(__FILE__),'..','README.markdown'))
854
1002
 
855
1003
  pf = Curl::PostField.file("filename", readme)
856
1004
 
@@ -861,7 +1009,7 @@ class TestCurbCurlEasy < Test::Unit::TestCase
861
1009
  easy.http_post(pf)
862
1010
 
863
1011
  assert_not_equal(0,easy.body_str.size)
864
- assert_equal(easy.body_str,File.read(readme))
1012
+ assert_equal(easy.body_str.tr("\r", ''), File.read(readme))
865
1013
  end
866
1014
 
867
1015
 
@@ -957,8 +1105,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
957
1105
  curl.headers['Accept'] = '*/*'
958
1106
  curl.headers['Authorization'] = 'Foo Bar Biz Baz'
959
1107
  curl.http_put(rd)
960
- assert_match /^PUT/, curl.body_str
961
- assert_match /hello$/, curl.body_str
1108
+ assert_match(/^PUT/, curl.body_str)
1109
+ assert_match(/hello$/, curl.body_str)
962
1110
  curl.header_str
963
1111
  curl.body_str
964
1112
  end
@@ -1017,6 +1165,13 @@ class TestCurbCurlEasy < Test::Unit::TestCase
1017
1165
  end
1018
1166
  end
1019
1167
 
1168
+ def test_set_unsupported_options
1169
+ curl = Curl::Easy.new
1170
+ assert_raises TypeError do
1171
+ curl.set(99999, 1)
1172
+ end
1173
+ end
1174
+
1020
1175
  include TestServerMethods
1021
1176
 
1022
1177
  def setup
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
2
+
3
+ class TestCurbCurlEasyResolve < Test::Unit::TestCase
4
+ def setup
5
+ @easy = Curl::Easy.new
6
+ end
7
+
8
+ def test_resolve
9
+ @easy.resolve = [ "example.com:80:127.0.0.1" ]
10
+ assert_equal @easy.resolve, [ "example.com:80:127.0.0.1" ]
11
+ end
12
+
13
+ def test_empty_resolve
14
+ assert_equal @easy.resolve, nil
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
2
+
3
+ class TestCurbCurlMaxFileSize < Test::Unit::TestCase
4
+ def setup
5
+ @easy = Curl::Easy.new
6
+ end
7
+
8
+ def test_maxfilesize
9
+ @easy.set(Curl::CURLOPT_MAXFILESIZE, 5000000)
10
+ end
11
+
12
+ end
@@ -6,6 +6,70 @@ class TestCurbCurlMulti < Test::Unit::TestCase
6
6
  ObjectSpace.garbage_collect
7
7
  end
8
8
 
9
+ # for https://github.com/taf2/curb/issues/277
10
+ # must connect to an external
11
+ def test_connection_keepalive
12
+ # 0123456 default & reserved RubyVM. It will probably include 7 from Dir.glob
13
+ lsof=`/usr/bin/which lsof`.strip
14
+ open_fds = lambda do
15
+ `#{lsof} -p #{Process.pid} | egrep "TCP|UDP" | wc -l`.strip.to_i
16
+ end
17
+ before_open = open_fds.call
18
+ assert !Curl::Multi.autoclose
19
+ multi = Curl::Multi.new
20
+ multi.max_connects = 1 # limit to 1 connection within the multi handle
21
+
22
+ did_complete = false
23
+ 5.times do |n|
24
+ # NOTE: we use google here because connecting to our TEST_URL as a local host address appears to not register correctly with lsof as a socket... if anyone knows a better way would be great to not have an external dependency here in the test
25
+ easy = Curl::Easy.new("http://google.com/") do |curl|
26
+ curl.timeout = 5 # ensure we don't hang for ever connecting to an external host
27
+ curl.on_complete {
28
+ did_complete = true
29
+ }
30
+ end
31
+ multi.add(easy)
32
+ end
33
+
34
+ multi.perform
35
+ assert did_complete
36
+ after_open = open_fds.call
37
+ assert_equal (after_open - before_open), 1, "with max connections set to 1 at this point the connection to google should still be open"
38
+ multi.close
39
+
40
+ after_open = open_fds.call
41
+ assert_equal (after_open - before_open), 0, "after closing the multi handle all connections should be closed"
42
+
43
+ Curl::Multi.autoclose = true
44
+ multi = Curl::Multi.new
45
+ did_complete = false
46
+ 5.times do |n|
47
+ # NOTE: we use google here because connecting to our TEST_URL as a local host address appears to not register correctly with lsof as a socket... if anyone knows a better way would be great to not have an external dependency here in the test
48
+ easy = Curl::Easy.new("http://google.com/") do |curl|
49
+ curl.timeout = 5 # ensure we don't hang for ever connecting to an external host
50
+ curl.on_complete {
51
+ did_complete = true
52
+ }
53
+ end
54
+ multi.add(easy)
55
+ end
56
+
57
+ multi.perform
58
+ assert did_complete
59
+ after_open = open_fds.call
60
+ assert_equal (after_open - before_open), 0, "auto close the connections"
61
+ ensure
62
+ Curl::Multi.autoclose = false # restore default
63
+ end
64
+
65
+ def test_connection_autoclose
66
+ assert !Curl::Multi.autoclose
67
+ Curl::Multi.autoclose = true
68
+ assert Curl::Multi.autoclose
69
+ ensure
70
+ Curl::Multi.autoclose = false # restore default
71
+ end
72
+
9
73
  def test_new_multi_01
10
74
  d1 = ""
11
75
  c1 = Curl::Easy.new($TEST_URL) do |curl|
@@ -109,8 +173,12 @@ class TestCurbCurlMulti < Test::Unit::TestCase
109
173
 
110
174
  assert(m.idle?, 'A new Curl::Multi handle should be idle')
111
175
 
176
+ assert_nil e.multi
177
+
112
178
  m.add(e)
113
179
 
180
+ assert_not_nil e.multi
181
+
114
182
  assert((not m.idle?), 'A Curl::Multi handle with a request should not be idle')
115
183
 
116
184
  m.perform
@@ -121,7 +189,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
121
189
  def test_requests
122
190
  m = Curl::Multi.new
123
191
 
124
- assert_equal([], m.requests, 'A new Curl::Multi handle should have no requests')
192
+ assert_equal(0, m.requests.length, 'A new Curl::Multi handle should have no requests')
125
193
 
126
194
  10.times do
127
195
  m.add(Curl::Easy.new($TEST_URL))
@@ -131,7 +199,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
131
199
 
132
200
  m.perform
133
201
 
134
- assert_equal([], m.requests, 'A new Curl::Multi handle should have no requests after a perform')
202
+ assert_equal(0, m.requests.length, 'A new Curl::Multi handle should have no requests after a perform')
135
203
  end
136
204
 
137
205
  def test_cancel
@@ -144,7 +212,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
144
212
 
145
213
  m.cancel!
146
214
 
147
- assert_equal([], m.requests, 'A new Curl::Multi handle should have no requests after being canceled')
215
+ assert_equal(0, m.requests.size, 'A new Curl::Multi handle should have no requests after being canceled')
148
216
  end
149
217
 
150
218
  def test_with_success
@@ -188,7 +256,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
188
256
  c1.on_success do|c|
189
257
  success_called1 = true
190
258
  #puts "success 1 called: #{c.body_str.inspect}"
191
- #assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
259
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
192
260
  end
193
261
 
194
262
  c1.on_failure do|c,rc|
@@ -327,7 +395,6 @@ class TestCurbCurlMulti < Test::Unit::TestCase
327
395
  Curl::Multi.download(urls,{},{},downloads) do|curl,download_path|
328
396
  assert_equal 200, curl.response_code
329
397
  assert File.exist?(download_path)
330
- store = file_info[File.basename(download_path)]
331
398
  assert_equal file_info[File.basename(download_path)][:size], File.size(download_path), "incomplete download: #{download_path}"
332
399
  end
333
400
  ensure
@@ -342,7 +409,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
342
409
  ]
343
410
  Curl::Multi.post(urls, {:follow_location => true, :multipart_form_post => true}, {:pipeline => true}) do|easy|
344
411
  str = easy.body_str
345
- assert_match /POST/, str
412
+ assert_match(/POST/, str)
346
413
  fields = {}
347
414
  str.gsub(/POST\n/,'').split('&').map{|sv| k, v = sv.split('='); fields[k] = v }
348
415
  expected = urls.find{|s| s[:url] == easy.last_effective_url }
@@ -357,8 +424,8 @@ class TestCurbCurlMulti < Test::Unit::TestCase
357
424
  { :url => TestServlet.url, :method => :put, :put_data => "message",
358
425
  :headers => {'Content-Type' => 'application/json' } }]
359
426
  Curl::Multi.put(urls, {}, {:pipeline => true}) do|easy|
360
- assert_match /PUT/, easy.body_str
361
- assert_match /message/, easy.body_str
427
+ assert_match(/PUT/, easy.body_str)
428
+ assert_match(/message/, easy.body_str)
362
429
  end
363
430
  end
364
431
 
@@ -375,11 +442,11 @@ class TestCurbCurlMulti < Test::Unit::TestCase
375
442
  assert_equal nil, code
376
443
  case method
377
444
  when :post
378
- assert_match /POST/, easy.body_str
445
+ assert_match(/POST/, easy.body_str)
379
446
  when :get
380
- assert_match /GET/, easy.body_str
447
+ assert_match(/GET/, easy.body_str)
381
448
  when :put
382
- assert_match /PUT/, easy.body_str
449
+ assert_match(/PUT/, easy.body_str)
383
450
  end
384
451
  #puts "#{easy.body_str.inspect}, #{method.inspect}, #{code.inspect}"
385
452
  end
@@ -395,11 +462,11 @@ class TestCurbCurlMulti < Test::Unit::TestCase
395
462
  assert_equal nil, code
396
463
  case method
397
464
  when :post
398
- assert_match /POST/, easy.body_str
465
+ assert_match(/POST/, easy.body_str)
399
466
  when :get
400
- assert_match /GET/, easy.body_str
467
+ assert_match(/GET/, easy.body_str)
401
468
  when :put
402
- assert_match /PUT/, easy.body_str
469
+ assert_match(/PUT/, easy.body_str)
403
470
  end
404
471
  end
405
472
  end
@@ -466,7 +533,7 @@ class TestCurbCurlMulti < Test::Unit::TestCase
466
533
  m.add(c)
467
534
  m.add(c)
468
535
  rescue => e
469
- assert_equal Curl::Err::MultiBadEasyHandle, e.class
536
+ assert Curl::Err::MultiBadEasyHandle == e.class || Curl::Err::MultiAddedAlready == e.class
470
537
  end
471
538
 
472
539
  def test_multi_default_timeout
@@ -481,5 +548,4 @@ class TestCurbCurlMulti < Test::Unit::TestCase
481
548
  def setup
482
549
  server_setup
483
550
  end
484
-
485
551
  end