typhoeus 0.2.0 → 0.2.4

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.
Files changed (50) hide show
  1. data/CHANGELOG.markdown +26 -1
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +2 -0
  4. data/LICENSE +20 -0
  5. data/README.textile +44 -5
  6. data/Rakefile +8 -5
  7. data/VERSION +1 -1
  8. data/examples/file.rb +12 -0
  9. data/examples/times.rb +40 -0
  10. data/ext/typhoeus/.gitignore +2 -1
  11. data/ext/typhoeus/native.c +1 -0
  12. data/ext/typhoeus/native.h +1 -0
  13. data/ext/typhoeus/typhoeus_easy.c +32 -7
  14. data/ext/typhoeus/typhoeus_easy.h +1 -0
  15. data/ext/typhoeus/typhoeus_form.c +59 -0
  16. data/ext/typhoeus/typhoeus_form.h +13 -0
  17. data/ext/typhoeus/typhoeus_multi.c +15 -29
  18. data/lib/typhoeus/easy.rb +74 -48
  19. data/lib/typhoeus/form.rb +32 -0
  20. data/lib/typhoeus/hydra/connect_options.rb +19 -3
  21. data/lib/typhoeus/hydra.rb +40 -7
  22. data/lib/typhoeus/multi.rb +7 -5
  23. data/lib/typhoeus/remote.rb +1 -1
  24. data/lib/typhoeus/remote_proxy_object.rb +2 -0
  25. data/lib/typhoeus/request.rb +17 -14
  26. data/lib/typhoeus/response.rb +16 -1
  27. data/lib/typhoeus/utils.rb +38 -0
  28. data/lib/typhoeus.rb +1 -0
  29. data/spec/fixtures/placeholder.gif +0 -0
  30. data/spec/fixtures/placeholder.txt +1 -0
  31. data/spec/fixtures/placeholder.ukn +0 -0
  32. data/spec/servers/app.rb +10 -0
  33. data/spec/spec.opts +1 -0
  34. data/spec/spec_helper.rb +3 -0
  35. data/spec/typhoeus/easy_spec.rb +74 -7
  36. data/spec/typhoeus/filter_spec.rb +2 -2
  37. data/spec/typhoeus/form_spec.rb +107 -0
  38. data/spec/typhoeus/hydra_mock_spec.rb +1 -1
  39. data/spec/typhoeus/hydra_spec.rb +108 -38
  40. data/spec/typhoeus/multi_spec.rb +1 -1
  41. data/spec/typhoeus/normalized_header_hash_spec.rb +1 -1
  42. data/spec/typhoeus/remote_method_spec.rb +2 -2
  43. data/spec/typhoeus/remote_proxy_object_spec.rb +1 -1
  44. data/spec/typhoeus/remote_spec.rb +1 -1
  45. data/spec/typhoeus/request_spec.rb +50 -5
  46. data/spec/typhoeus/response_spec.rb +13 -1
  47. data/spec/typhoeus/utils_spec.rb +1 -1
  48. data/typhoeus.gemspec +93 -75
  49. metadata +70 -28
  50. data/.gitignore +0 -3
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Typhoeus::Easy do
4
4
  describe "#supports_zlib" do
@@ -17,6 +17,42 @@ describe Typhoeus::Easy do
17
17
  end
18
18
  end
19
19
 
20
+ describe "curl errors" do
21
+ it "should provide the CURLE_OPERATION_TIMEDOUT return code when a request times out" do
22
+ e = Typhoeus::Easy.new
23
+ e.url = "http://localhost:3001/?delay=1"
24
+ e.method = :get
25
+ e.timeout = 100
26
+ e.perform
27
+ e.curl_return_code.should == 28
28
+ e.curl_error_message.should == "Timeout was reached"
29
+ e.response_code.should == 0
30
+ end
31
+
32
+ it "should provide the CURLE_COULDNT_CONNECT return code when trying to connect to a non existent port" do
33
+ e = Typhoeus::Easy.new
34
+ e.url = "http://localhost:3999"
35
+ e.method = :get
36
+ e.connect_timeout = 100
37
+ e.perform
38
+ e.curl_return_code.should == 7
39
+ e.curl_error_message.should == "Couldn't connect to server"
40
+ e.response_code.should == 0
41
+ end
42
+
43
+ it "should not return an error message on a successful easy operation" do
44
+ easy = Typhoeus::Easy.new
45
+ easy.url = "http://localhost:3002"
46
+ easy.method = :get
47
+ easy.curl_error_message.should == nil
48
+ easy.perform
49
+ easy.response_code.should == 200
50
+ easy.curl_return_code.should == 0
51
+ easy.curl_error_message.should == "No error"
52
+ end
53
+
54
+ end
55
+
20
56
  describe "options" do
21
57
  it "should not follow redirects if not instructed to" do
22
58
  e = Typhoeus::Easy.new
@@ -48,12 +84,11 @@ describe Typhoeus::Easy do
48
84
 
49
85
  it "should provide a timeout in milliseconds" do
50
86
  e = Typhoeus::Easy.new
51
- e.url = "http://localhost:3001"
87
+ e.url = "http://localhost:3001/?delay=1"
52
88
  e.method = :get
53
- e.timeout = 50
89
+ e.timeout = 10
54
90
  e.perform
55
- # this doesn't work on a mac for some reason
56
- # e.timed_out?.should == true
91
+ e.timed_out?.should == true
57
92
  end
58
93
 
59
94
  it "should allow the setting of the max redirects to follow" do
@@ -156,7 +191,7 @@ describe Typhoeus::Easy do
156
191
  :username => ['dbalatero', 'dbalatero2']
157
192
  }
158
193
 
159
- easy.url.should =~ /\?.*username=dbalatero&username=dbalatero2/
194
+ easy.url.should =~ /\?.*username%5B%5D=dbalatero&username%5B%5D=dbalatero2/
160
195
  end
161
196
  end
162
197
 
@@ -209,7 +244,39 @@ describe Typhoeus::Easy do
209
244
  easy.params = {:foo => "bar"}
210
245
  easy.perform
211
246
  easy.response_code.should == 200
212
- easy.response_body.should include("foo=bar")
247
+ easy.response_body.should =~ /foo=bar/
248
+ end
249
+
250
+ it "should use Content-Type: application/x-www-form-urlencoded for normal posts" do
251
+ easy = Typhoeus::Easy.new
252
+ easy.url = "http://localhost:3002/normal_post"
253
+ easy.method = :post
254
+ easy.params = { :a => 'b', :c => 'd',
255
+ :e => { :f => { :g => 'h' } } }
256
+ easy.perform
257
+
258
+ request = JSON.parse(easy.response_body)
259
+ request['CONTENT_TYPE'].should == 'application/x-www-form-urlencoded'
260
+ request['rack.request.form_vars'].should == 'a=b&c=d&e%5Bf%5D%5Bg%5D=h'
261
+ end
262
+
263
+ it "should handle a file upload, as multipart" do
264
+ easy = Typhoeus::Easy.new
265
+ easy.url = "http://localhost:3002/file"
266
+ easy.method = :post
267
+ easy.params = {:file => File.open(File.expand_path(File.dirname(__FILE__) + "/../fixtures/placeholder.txt"), "r")}
268
+ easy.perform
269
+ easy.response_code.should == 200
270
+ result = JSON.parse(easy.response_body)
271
+
272
+ { 'content-type' => 'text/plain',
273
+ 'filename' => 'placeholder.txt',
274
+ 'content' => 'This file is used to test uploading.'
275
+ }.each do |key, val|
276
+ result[key].should == val
277
+ end
278
+
279
+ result['request-content-type'].should =~ /multipart/
213
280
  end
214
281
  end
215
282
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Typhoeus::Filter do
4
4
  it "should take a method name and optionally take options" do
@@ -32,4 +32,4 @@ describe Typhoeus::Filter do
32
32
  filter.apply_filter?(:foo).should be_false
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -0,0 +1,107 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Typhoeus::Form do
4
+ describe "#process!" do
5
+ it "should generate a valid form object" do
6
+ form = Typhoeus::Form.new({
7
+ :name => "John Smith",
8
+ :age => "29"
9
+ })
10
+ form.should_receive(:formadd_param).with("name", "John Smith")
11
+ form.should_receive(:formadd_param).with("age", "29")
12
+ form.process!
13
+ end
14
+
15
+ it "should handle params that are a hash" do
16
+ form = Typhoeus::Form.new({
17
+ :attributes => {
18
+ :eyes => "brown",
19
+ :hair => "green",
20
+ :teeth => "white"
21
+ },
22
+ :name => "John Smith",
23
+ :age => "29"
24
+ })
25
+ form.should_receive(:formadd_param).with("attributes[eyes]", "brown")
26
+ form.should_receive(:formadd_param).with("attributes[hair]", "green")
27
+ form.should_receive(:formadd_param).with("attributes[teeth]", "white")
28
+ form.should_receive(:formadd_param).with("name", "John Smith")
29
+ form.should_receive(:formadd_param).with("age", "29")
30
+ form.process!
31
+ end
32
+
33
+ it "should params that have mutliple values" do
34
+ form = Typhoeus::Form.new({
35
+ :colors => ["brown", "green", "white"],
36
+ :name => "John Smith",
37
+ :age => "29"
38
+ })
39
+ form.should_receive(:formadd_param).with("colors[]", "brown")
40
+ form.should_receive(:formadd_param).with("colors[]", "green")
41
+ form.should_receive(:formadd_param).with("colors[]", "white")
42
+ form.should_receive(:formadd_param).with("name", "John Smith")
43
+ form.should_receive(:formadd_param).with("age", "29")
44
+ form.process!
45
+ end
46
+
47
+ context "when a File object is a param" do
48
+ it "should handle one file" do
49
+ form = Typhoeus::Form.new(
50
+ :file => File.open(File.expand_path(File.dirname(__FILE__) + "/../fixtures/placeholder.txt"), "r")
51
+ )
52
+ form.should_receive(:formadd_file).with("file", "placeholder.txt", "text/plain", anything)
53
+ form.process!
54
+ end
55
+
56
+ it "should handle more than one file" do
57
+ form = Typhoeus::Form.new(
58
+ :text_file => File.open(File.expand_path(File.dirname(__FILE__) + "/../fixtures/placeholder.txt"), "r"),
59
+ :gif_file => File.open(File.expand_path(File.dirname(__FILE__) + "/../fixtures/placeholder.gif"), "r")
60
+ )
61
+ form.should_receive(:formadd_file).with("gif_file", "placeholder.gif", "image/gif", anything)
62
+ form.should_receive(:formadd_file).with("text_file", "placeholder.txt", "text/plain", anything)
63
+ form.process!
64
+ end
65
+ it "should default to 'application/octet-stream' if no content type can be determined" do
66
+ pending
67
+ form = Typhoeus::Form.new(
68
+ :file => File.open(File.expand_path(File.dirname(__FILE__) + "/../fixtures/placeholder.txt"), "r")
69
+ )
70
+ form.should_receive(:formadd_file).with("file", "placeholder.ukn", "application/octet-stream", anything)
71
+ form.process!
72
+ end
73
+ end
74
+ end
75
+
76
+ describe "#to_s" do
77
+ it "should generate a valid query string" do
78
+ form = Typhoeus::Form.new({
79
+ :name => "John Smith",
80
+ :age => "29"
81
+ })
82
+ form.to_s.should == "age=29&name=John+Smith"
83
+ end
84
+
85
+ it "should handle params that are a hash" do
86
+ form = Typhoeus::Form.new({
87
+ :attributes => {
88
+ :eyes => "brown",
89
+ :hair => "green",
90
+ :teeth => "white"
91
+ },
92
+ :name => "John Smith",
93
+ :age => "29"
94
+ })
95
+ form.to_s.should == "age=29&attributes%5Beyes%5D=brown&attributes%5Bhair%5D=green&attributes%5Bteeth%5D=white&name=John+Smith"
96
+ end
97
+
98
+ it "should params that have mutliple values" do
99
+ form = Typhoeus::Form.new({
100
+ :colors => ["brown", "green", "white"],
101
+ :name => "John Smith",
102
+ :age => "29"
103
+ })
104
+ form.to_s.should == "age=29&colors%5B%5D=brown&colors%5B%5D=green&colors%5B%5D=white&name=John+Smith"
105
+ end
106
+ end
107
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Typhoeus::HydraMock do
4
4
  it "should mark all responses as mocks" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  # some of these tests assume that you have some local services running.
4
4
  # ruby spec/servers/app.rb -p 3000
@@ -46,6 +46,47 @@ describe Typhoeus::Hydra do
46
46
  second.response.body.should include("second")
47
47
  end
48
48
 
49
+ it "should store the curl return codes on the reponses" do
50
+ hydra = Typhoeus::Hydra.new
51
+ first = Typhoeus::Request.new("http://localhost:3001/?delay=1", :timeout => 100)
52
+ second = Typhoeus::Request.new("http://localhost:3999", :connect_timout => 100)
53
+ hydra.queue first
54
+ hydra.queue second
55
+ hydra.run
56
+ first.response.curl_return_code == 28
57
+ second.response.curl_return_code == 7
58
+ end
59
+
60
+ it "aborts a batch of requests" do
61
+ urls = [
62
+ 'http://localhost:3000',
63
+ 'http://localhost:3001',
64
+ 'http://localhost:3002'
65
+ ]
66
+
67
+ # this will make testing easier
68
+ hydra = Typhoeus::Hydra.new( :max_concurrency => 1 )
69
+ completed = 0
70
+
71
+ 10.times {
72
+ |i|
73
+
74
+ req = Typhoeus::Request.new( urls[ i % urls.size], :params => { :cnt => i } )
75
+ req.on_complete {
76
+ |res|
77
+ completed += 1
78
+ hydra.abort if completed == 5
79
+ }
80
+
81
+ hydra.queue( req )
82
+ }
83
+
84
+ hydra.run
85
+
86
+ # technically this should be '== 6' but I don't trust it...
87
+ completed.should < 10
88
+ end
89
+
49
90
  it "has a cache_setter proc" do
50
91
  hydra = Typhoeus::Hydra.new
51
92
  hydra.cache_setter do |request|
@@ -390,37 +431,77 @@ describe Typhoeus::Hydra::ConnectOptions do
390
431
  @klass = Typhoeus::Hydra
391
432
  end
392
433
 
434
+ let!(:old_net_connect) { @klass.allow_net_connect }
435
+ let!(:old_ignore_localhost) { @klass.ignore_localhost }
436
+ let(:hydra) { @klass.new }
437
+
438
+ after(:each) do
439
+ @klass.allow_net_connect = old_net_connect
440
+ @klass.ignore_localhost = old_ignore_localhost
441
+ end
442
+
443
+ def request_for(host)
444
+ Typhoeus::Request.new("http://#{host}:3000")
445
+ end
446
+
393
447
  describe "#ignore_localhost" do
394
- it "should allow localhost requests over the wire if true" do
395
- begin
396
- old_net_connect = @klass.allow_net_connect
397
- old_ignore_localhost = @klass.ignore_localhost
448
+ context "when set to true" do
449
+ before(:each) { @klass.ignore_localhost = true }
450
+
451
+ [true, false].each do |val|
452
+ it "allows localhost requests when allow_net_connect is #{val}" do
453
+ @klass.allow_net_connect = val
454
+ expect { hydra.queue(request_for('localhost')) }.to_not raise_error
455
+ end
456
+ end
457
+ end
458
+
459
+ context "when set to false" do
460
+ before(:each) { @klass.ignore_localhost = false }
461
+
462
+ it "allows localhost requests when allow_net_connect is true" do
463
+ @klass.allow_net_connect = true
464
+ expect { hydra.queue(request_for('localhost')) }.to_not raise_error
465
+ end
466
+
467
+ it "does not allow localhost requests when allow_net_connect is false" do
398
468
  @klass.allow_net_connect = false
399
- @klass.ignore_localhost = true
469
+ expect { hydra.queue(request_for('localhost')) }.to raise_error(Typhoeus::Hydra::NetConnectNotAllowedError)
470
+ end
471
+ end
472
+ end
400
473
 
401
- req = Typhoeus::Request.new("http://localhost:3000")
402
- hydra = @klass.new
474
+ describe "#ignore_hosts" do
475
+ context 'when allow_net_connect is set to false' do
476
+ before(:each) do
477
+ @klass.ignore_localhost = false
478
+ @klass.allow_net_connect = false
479
+ end
403
480
 
404
- lambda {
405
- hydra.queue(req)
406
- }.should_not raise_error
407
- ensure
408
- @klass.allow_net_connect = old_net_connect
409
- @klass.ignore_localhost = old_ignore_localhost
481
+ Typhoeus::Request::LOCALHOST_ALIASES.each do |disallowed_host|
482
+ ignore_hosts = Typhoeus::Request::LOCALHOST_ALIASES - [disallowed_host]
483
+
484
+ context "when set to #{ignore_hosts.join(' and ')}" do
485
+ before(:each) { @klass.ignore_hosts = ignore_hosts }
486
+
487
+ it "does not allow a request to #{disallowed_host}" do
488
+ expect { hydra.queue(request_for(disallowed_host)) }.to raise_error(Typhoeus::Hydra::NetConnectNotAllowedError)
489
+ end
490
+
491
+ ignore_hosts.each do |host|
492
+ it "allows a request to #{host}" do
493
+ expect { hydra.queue(request_for(host)) }.to_not raise_error
494
+ end
495
+ end
496
+ end
410
497
  end
411
498
  end
412
499
  end
413
500
 
414
501
  describe "#allow_net_connect" do
415
502
  it "should be settable" do
416
- begin
417
- # make sure to not mess up other specs.
418
- old = @klass.allow_net_connect
419
- @klass.allow_net_connect = true
420
- @klass.allow_net_connect.should be_true
421
- ensure
422
- @klass.allow_net_connect = old
423
- end
503
+ @klass.allow_net_connect = true
504
+ @klass.allow_net_connect.should be_true
424
505
  end
425
506
 
426
507
  it "should default to true" do
@@ -428,23 +509,12 @@ describe Typhoeus::Hydra::ConnectOptions do
428
509
  end
429
510
 
430
511
  it "should raise an error if we queue a request while its false" do
431
- begin
432
- request = Typhoeus::Request.new("http://localhost:3000")
433
- old_net_connect = @klass.allow_net_connect
434
- old_ignore_localhost = @klass.ignore_localhost
512
+ @klass.allow_net_connect = false
513
+ @klass.ignore_localhost = false
435
514
 
436
- @klass.allow_net_connect = false
437
- @klass.ignore_localhost = false
438
-
439
- hydra = Typhoeus::Hydra.new
440
-
441
- lambda {
442
- hydra.queue(request)
443
- }.should raise_error(Typhoeus::Hydra::NetConnectNotAllowedError)
444
- ensure
445
- @klass.allow_net_connect = old_net_connect
446
- @klass.ignore_localhost = old_ignore_localhost
447
- end
515
+ expect {
516
+ hydra.queue(request_for('example.com'))
517
+ }.to raise_error(Typhoeus::Hydra::NetConnectNotAllowedError)
448
518
  end
449
519
  end
450
520
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Typhoeus::Easy do
4
4
  it "should save easy handles that get added" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Typhoeus::NormalizedHeaderHash do
4
4
  before(:all) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Typhoeus::RemoteMethod do
4
4
  it "should take options" do
@@ -138,4 +138,4 @@ describe Typhoeus::RemoteMethod do
138
138
  Typhoeus::RemoteMethod.new(:cache_responses => 30).cache_ttl.should == 30
139
139
  end
140
140
  end
141
- end
141
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Typhoeus::RemoteProxyObject do
4
4
  before(:each) do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Typhoeus do
4
4
  it "should be deprecated" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Typhoeus::Request do
4
4
  describe "#inspect" do
@@ -25,7 +25,7 @@ describe Typhoeus::Request do
25
25
  it "should dump the method" do
26
26
  @request.inspect.should =~ /:get/
27
27
  end
28
-
28
+
29
29
  it "should dump out headers" do
30
30
  @request.inspect.should =~ /"Content-Type"\s*=>\s*"text\/html"/
31
31
  end
@@ -74,7 +74,23 @@ describe Typhoeus::Request do
74
74
  :params => {
75
75
  :a => ['789','2434']
76
76
  })
77
- request.params_string.should == "a[]=789&a[]=2434"
77
+ request.params_string.should == "a%5B%5D=789&a%5B%5D=2434"
78
+ end
79
+
80
+ it "should nest arrays in hashes" do
81
+ request = Typhoeus::Request.new('http://google.com',
82
+ :params => {
83
+ :a => { :b => { :c => ['d','e'] } }
84
+ })
85
+ request.params_string.should == "a%5Bb%5D%5Bc%5D%5B%5D=d&a%5Bb%5D%5Bc%5D%5B%5D=e"
86
+ end
87
+
88
+ it "should translate nested params correctly" do
89
+ request = Typhoeus::Request.new('http://google.com',
90
+ :params => {
91
+ :a => { :b => { :c => 'd' } }
92
+ })
93
+ request.params_string.should == "a%5Bb%5D%5Bc%5D=d"
78
94
  end
79
95
  end
80
96
 
@@ -86,11 +102,11 @@ describe Typhoeus::Request do
86
102
  end
87
103
 
88
104
  it "can run a POST synchronously" do
89
- response = Typhoeus::Request.post("http://localhost:3000", :params => {:q => "hi"}, :headers => {:foo => "bar"})
105
+ response = Typhoeus::Request.post("http://localhost:3000", :params => {:q => { :a => "hi" } }, :headers => {:foo => "bar"})
90
106
  response.code.should == 200
91
107
  json = JSON.parse(response.body)
92
108
  json["REQUEST_METHOD"].should == "POST"
93
- json["rack.request.query_hash"]["q"].should == "hi"
109
+ json["rack.request.query_hash"]["q"]["a"].should == "hi"
94
110
  end
95
111
 
96
112
  it "can run a PUT synchronously" do
@@ -213,6 +229,35 @@ describe Typhoeus::Request do
213
229
  good.should be_true
214
230
  end
215
231
 
232
+ describe "time info" do
233
+ it "should have time" do
234
+ response = Typhoeus::Request.get("http://localhost:3000")
235
+ response.time.should > 0
236
+ end
237
+
238
+ it "should have connect time" do
239
+ response = Typhoeus::Request.get("http://localhost:3000")
240
+ response.connect_time.should > 0
241
+ end
242
+
243
+ it "should have app connect time" do
244
+ response = Typhoeus::Request.get("http://localhost:3000")
245
+ response.app_connect_time.should > 0
246
+ end
247
+
248
+ it "should have start transfer time" do
249
+ response = Typhoeus::Request.get("http://localhost:3000")
250
+ response.start_transfer_time.should > 0
251
+ end
252
+
253
+ it "should have pre-transfer time" do
254
+ response = Typhoeus::Request.get("http://localhost:3000")
255
+ response.pretransfer_time.should > 0
256
+ end
257
+
258
+ end
259
+
260
+
216
261
  describe "authentication" do
217
262
 
218
263
  it "should allow to set username and password" do
@@ -1,6 +1,18 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Typhoeus::Response do
4
+ describe "timed_out?" do
5
+ it "should return true if curl return code is 28" do
6
+ response = Typhoeus::Response.new(:curl_return_code => 28)
7
+ response.should be_timed_out
8
+ end
9
+
10
+ it "should return false for not 28" do
11
+ response = Typhoeus::Response.new(:curl_return_code => 14)
12
+ response.should_not be_timed_out
13
+ end
14
+ end
15
+
4
16
  describe "initialize" do
5
17
  it "should store headers_hash" do
6
18
  response = Typhoeus::Response.new(:headers_hash => {})
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Typhoeus::Utils do
4
4
  # Taken from Rack 1.2.1