rufus-verbs 0.10 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,85 +7,83 @@
7
7
  # Thu Jan 17 10:15:52 JST 2008
8
8
  #
9
9
 
10
- require 'timeout'
11
- require 'test/unit'
12
10
 
13
- require 'rufus/verbs'
11
+ require File.dirname(__FILE__) + '/base.rb'
14
12
 
15
13
 
16
14
  class ProxyTest < Test::Unit::TestCase
17
15
 
18
- include Rufus::Verbs
16
+ include Rufus::Verbs
19
17
 
20
18
 
21
- def test_0
19
+ def test_0
22
20
 
23
- uri = "http://rufus.rubyforge.org/rufus-verbs/index.html"
21
+ uri = "http://rufus.rubyforge.org/rufus-verbs/index.html"
24
22
 
25
- res0 = get(uri, :proxy => false)
23
+ res0 = get(uri, :proxy => false)
26
24
 
27
- assert_not_nil res0.body # just displaying the test dot
25
+ assert_not_nil res0.body # just displaying the test dot
28
26
 
29
- proxies = find_proxies
27
+ proxies = find_proxies
30
28
 
31
- res1 = nil
29
+ res1 = nil
32
30
 
33
- proxies.each do |proxy|
34
- begin
35
- Timeout::timeout 2 do
36
- res1 = get(uri, :proxy => proxy)
37
- end
38
- break if res1.code.to_i == 200
39
- rescue Exception => e
40
- puts "skipped proxy '#{proxy}'"
41
- end
31
+ proxies.each do |proxy|
32
+ begin
33
+ Timeout::timeout 2 do
34
+ res1 = get(uri, :proxy => proxy)
42
35
  end
36
+ break if res1.code.to_i == 200
37
+ rescue Exception => e
38
+ puts "skipped proxy '#{proxy}'"
39
+ end
40
+ end
43
41
 
44
- if res1.code.to_i != 200
45
- puts
46
- puts
47
- puts "sorry, couldn't find an open proxy, couldn't test the"
48
- puts "proxy feature of 'rufus-verbs'"
49
- puts
50
- puts
51
- return
52
- end
42
+ if res1.code.to_i != 200
43
+ puts
44
+ puts
45
+ puts "sorry, couldn't find an open proxy, couldn't test the"
46
+ puts "proxy feature of 'rufus-verbs'"
47
+ puts
48
+ puts
49
+ return
50
+ end
53
51
 
54
- assert_equal res0.body.length, res1.body.length
52
+ assert_equal res0.body.length, res1.body.length
55
53
 
56
- #p res0.to_hash
57
- #p res1.to_hash
54
+ #p res0.to_hash
55
+ #p res1.to_hash
58
56
 
59
- via1 = res1["via"]
57
+ via1 = res1["via"]
60
58
 
61
- unless via1
62
- puts
63
- puts
64
- puts "seems like no open proxy could be found... no via..."
65
- puts "can't test for now"
66
- puts
67
- puts
68
- return
69
- end
59
+ unless via1
60
+ puts
61
+ puts
62
+ puts "seems like no open proxy could be found... no via..."
63
+ puts "can't test for now"
64
+ puts
65
+ puts
66
+ return
67
+ end
70
68
 
71
- via1 = res1["via"].split(", ")[-1]
72
- # last proxy
69
+ via1 = res1["via"].split(", ")[-1]
70
+ # last proxy
73
71
 
74
- assert_no_match /wikimedia\.org/, via1
75
- # making sure that the proxy was not one of wikipedia
76
- end
72
+ assert_no_match /wikimedia\.org/, via1
73
+ # making sure that the proxy was not one of wikipedia
74
+ end
77
75
 
78
- protected
76
+ protected
79
77
 
80
- def find_proxies
78
+ def find_proxies
81
79
 
82
- res = get "http://freeproxy.ch/proxy.txt"
83
- lines = res.body.split "\n"
84
- lines[4..-1].collect do |line|
85
- l = line.split("\t")
86
- 'http://' + l[0]
87
- end
88
- end
80
+ res = get "http://freeproxy.ch/proxy.txt"
81
+ lines = res.body.split "\n"
82
+ lines[4..-1].collect do |line|
83
+ l = line.split("\t")
84
+ 'http://' + l[0]
85
+ end
86
+ end
89
87
 
90
88
  end
91
89
 
@@ -7,34 +7,32 @@
7
7
  # Sun Jan 13 20:02:25 JST 2008
8
8
  #
9
9
 
10
- require 'test/unit'
11
- require 'testbase'
12
10
 
13
- require 'rufus/verbs'
11
+ require File.dirname(__FILE__) + '/base.rb'
14
12
 
15
13
 
16
14
  class RedirTest < Test::Unit::TestCase
17
- include TestBaseMixin
15
+ include TestBaseMixin
18
16
 
19
- include Rufus::Verbs
17
+ include Rufus::Verbs
20
18
 
21
19
 
22
- def test_0
20
+ def test_0
23
21
 
24
- expect 200, {}, get(:uri => "http://localhost:7777/things")
25
- end
22
+ expect 200, {}, get(:uri => "http://localhost:7777/things")
23
+ end
26
24
 
27
- #
28
- # testing the :no_redirections directive
29
- #
30
- def test_1
25
+ #
26
+ # testing the :no_redirections directive
27
+ #
28
+ def test_1
31
29
 
32
- res = get "http://localhost:7777/things", :no_redirections => true
33
- assert_equal 303, res.code.to_i
30
+ res = get "http://localhost:7777/things", :no_redirections => true
31
+ assert_equal 303, res.code.to_i
34
32
 
35
- res = get("http://localhost:7777/things", :noredir => true)
36
- assert_equal 303, res.code.to_i
33
+ res = get("http://localhost:7777/things", :noredir => true)
34
+ assert_equal 303, res.code.to_i
37
35
 
38
- expect 200, {}, get("http://localhost:7777/items", :noredir => true)
39
- end
36
+ expect 200, {}, get("http://localhost:7777/items", :noredir => true)
37
+ end
40
38
  end
@@ -7,121 +7,116 @@
7
7
  # Sun Jan 13 12:33:03 JST 2008
8
8
  #
9
9
 
10
- require 'rubygems'
11
-
12
- require 'test/unit'
13
- require 'testbase'
14
-
15
- require 'rufus/verbs'
10
+ require File.dirname(__FILE__) + '/base.rb'
16
11
 
17
12
 
18
13
  class SimpleTest < Test::Unit::TestCase
19
- include TestBaseMixin
20
-
21
- include Rufus::Verbs
14
+ include TestBaseMixin
22
15
 
16
+ include Rufus::Verbs
23
17
 
24
- def test_0
25
18
 
26
- #res = get :uri => "http://localhost:7777/items"
27
- #assert_equal 200, res.code.to_i
28
- #assert_equal "{}", res.body.strip
29
- expect 200, {}, get(:uri => "http://localhost:7777/items")
19
+ def test_0
30
20
 
31
- res = post :uri => "http://localhost:7777/items/0", :d => "Toto"
32
- assert_equal 201, res.code.to_i
33
- assert_equal "http://localhost:7777/items/0", res['Location']
21
+ #res = get :uri => "http://localhost:7777/items"
22
+ #assert_equal 200, res.code.to_i
23
+ #assert_equal "{}", res.body.strip
24
+ expect 200, {}, get(:uri => "http://localhost:7777/items")
34
25
 
35
- expect 200, { 0 => "Toto" }, get(:uri => "http://localhost:7777/items")
26
+ res = post :uri => "http://localhost:7777/items/0", :d => "Toto"
27
+ assert_equal 201, res.code.to_i
28
+ assert_equal "http://localhost:7777/items/0", res['Location']
36
29
 
37
- res = get :host => "localhost", :port => 7777, :path => "/items"
38
- assert_equal 200, res.code.to_i
39
- assert_equal ({ 0 => "Toto" }), eval(res.body)
30
+ expect 200, { 0 => "Toto" }, get(:uri => "http://localhost:7777/items")
40
31
 
41
- res = put :uri => "http://localhost:7777/items/0", :d => "Toto2"
42
- assert_equal 200, res.code.to_i
32
+ res = get :host => "localhost", :port => 7777, :path => "/items"
33
+ assert_equal 200, res.code.to_i
34
+ assert_equal ({ 0 => "Toto" }), eval(res.body)
43
35
 
44
- expect 200, { 0 => "Toto2" }, get(:uri => "http://localhost:7777/items")
36
+ res = put :uri => "http://localhost:7777/items/0", :d => "Toto2"
37
+ assert_equal 200, res.code.to_i
45
38
 
46
- res = put :uri => "http://localhost:7777/items/0", :d => "Toto3", :fake_put => true
47
- assert_equal 200, res.code.to_i
39
+ expect 200, { 0 => "Toto2" }, get(:uri => "http://localhost:7777/items")
48
40
 
49
- expect 200, { 0 => "Toto3" }, get(:uri => "http://localhost:7777/items")
50
- end
41
+ res = put :uri => "http://localhost:7777/items/0", :d => "Toto3", :fake_put => true
42
+ assert_equal 200, res.code.to_i
51
43
 
52
- def test_0b
44
+ expect 200, { 0 => "Toto3" }, get(:uri => "http://localhost:7777/items")
45
+ end
53
46
 
54
- expect 200, {}, get(:uri => "http://localhost:7777/items")
47
+ def test_0b
55
48
 
56
- res = post :uri => "http://localhost:7777/items", :d => "Toto"
57
- assert_equal 201, res.code.to_i
58
- assert_equal "http://localhost:7777/items/0", res['Location']
49
+ expect 200, {}, get(:uri => "http://localhost:7777/items")
59
50
 
60
- expect 200, "\"Toto\"", get(:uri => "http://localhost:7777/items/0")
51
+ res = post :uri => "http://localhost:7777/items", :d => "Toto"
52
+ assert_equal 201, res.code.to_i
53
+ assert_equal "http://localhost:7777/items/0", res['Location']
61
54
 
62
- res = post :uri => "http://localhost:7777/items", :d => "Smurf"
63
- assert_equal 201, res.code.to_i
64
- assert_equal "http://localhost:7777/items/1", res['Location']
55
+ expect 200, "\"Toto\"", get(:uri => "http://localhost:7777/items/0")
65
56
 
66
- expect 200, "\"Smurf\"", get(:uri => "http://localhost:7777/items/1")
67
- end
57
+ res = post :uri => "http://localhost:7777/items", :d => "Smurf"
58
+ assert_equal 201, res.code.to_i
59
+ assert_equal "http://localhost:7777/items/1", res['Location']
68
60
 
69
- def test_1
61
+ expect 200, "\"Smurf\"", get(:uri => "http://localhost:7777/items/1")
62
+ end
70
63
 
71
- ep = EndPoint.new(:host => "localhost", :port => 7777)
72
- expect 200, {}, ep.get(:resource => "items")
64
+ def test_1
73
65
 
74
- res = ep.put :resource => "items", :id => 0 do
75
- "blockdata"
76
- end
77
- assert_equal 404, res.code.to_i
66
+ ep = EndPoint.new(:host => "localhost", :port => 7777)
67
+ expect 200, {}, ep.get(:resource => "items")
78
68
 
79
- res = ep.post :resource => "items", :id => 0 do
80
- "blockdata"
81
- end
82
- assert_equal 201, res.code.to_i
83
- assert_equal "http://localhost:7777/items/0", res['Location']
69
+ res = ep.put :resource => "items", :id => 0 do
70
+ "blockdata"
71
+ end
72
+ assert_equal 404, res.code.to_i
84
73
 
85
- expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
74
+ res = ep.post :resource => "items", :id => 0 do
75
+ "blockdata"
86
76
  end
77
+ assert_equal 201, res.code.to_i
78
+ assert_equal "http://localhost:7777/items/0", res['Location']
87
79
 
88
- def test_2
80
+ expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
81
+ end
89
82
 
90
- s = get(:uri => "http://localhost:7777/items", :body => true)
91
- assert_equal "{}", s.strip
92
- end
83
+ def test_2
93
84
 
94
- #
95
- # The "no-path" test
96
- #
97
- def test_3
85
+ s = get(:uri => "http://localhost:7777/items", :body => true)
86
+ assert_equal "{}", s.strip
87
+ end
98
88
 
99
- r = get "http://rufus.rubyforge.org"
100
- assert_kind_of Net::HTTPOK, r
101
- end
89
+ #
90
+ # The "no-path" test
91
+ #
92
+ def test_3
102
93
 
103
- #
104
- # HEAD
105
- #
106
- def test_4
94
+ r = get "http://rufus.rubyforge.org"
95
+ assert_kind_of Net::HTTPOK, r
96
+ end
107
97
 
108
- res = head "http://localhost:7777/items"
109
- assert_equal 200, res.code.to_i
110
- assert_nil res.body
111
- end
98
+ #
99
+ # HEAD
100
+ #
101
+ def test_4
112
102
 
113
- #
114
- # OPTIONS
115
- #
116
- def test_5
103
+ res = head "http://localhost:7777/items"
104
+ assert_equal 200, res.code.to_i
105
+ assert_nil res.body
106
+ end
117
107
 
118
- r = options "http://localhost:7777/items"
119
- assert_equal [ :delete, :get, :head, :options, :post, :put], r
120
- end
108
+ #
109
+ # OPTIONS
110
+ #
111
+ def test_5
121
112
 
122
- def test_6
113
+ r = options "http://localhost:7777/items"
114
+ assert_equal [ :delete, :get, :head, :options, :post, :put], r
115
+ end
123
116
 
124
- r = Rufus::Verbs::options "http://localhost:7777/items"
125
- assert_equal [ :delete, :get, :head, :options, :post, :put], r
126
- end
117
+ def test_6
118
+
119
+ r = Rufus::Verbs::options "http://localhost:7777/items"
120
+ assert_equal [ :delete, :get, :head, :options, :post, :put], r
121
+ end
127
122
  end
@@ -1,28 +1,24 @@
1
1
 
2
- require 'rubygems'
3
-
4
-
5
- require 'dryrun_test'
6
- require 'iconditional_test'
7
-
8
- require 'simple_test'
9
-
10
- require 'auth0_test'
11
- require 'auth1_test'
12
-
13
- require 'redir_test'
14
- require 'block_test'
15
- require 'https_test'
16
- require 'proxy_test'
17
-
18
- require 'conditional_test'
19
- require 'cookie0_test'
20
- require 'cookie1_test'
21
-
22
- require 'escape_test'
23
-
24
- require 'uri_test'
25
- require 'fopen_test'
26
-
27
- require 'timeout_test'
2
+ #require 'dryrun_test'
3
+ #require 'iconditional_test'
4
+ #require 'simple_test'
5
+ #require 'auth0_test'
6
+ #require 'auth1_test'
7
+ #require 'redir_test'
8
+ #require 'block_test'
9
+ #require 'https_test'
10
+ #require 'proxy_test'
11
+ #require 'conditional_test'
12
+ #require 'cookie0_test'
13
+ #require 'cookie1_test'
14
+ #require 'escape_test'
15
+ #require 'uri_test'
16
+ #require 'fopen_test'
17
+ #require 'timeout_test'
18
+
19
+ dirpath = File.dirname(__FILE__)
20
+
21
+ tests = Dir.new(dirpath).entries.select { |e| e.match(/\_test\.rb$/) }.sort
22
+
23
+ tests.each { |t| load "#{dirpath}/#{t}" }
28
24
 
@@ -7,32 +7,28 @@
7
7
  # Mon May 26 17:04:25 JST 2008
8
8
  #
9
9
 
10
- require 'rubygems'
11
-
12
- require 'test/unit'
13
- require 'testbase'
14
-
15
- require 'rufus/verbs'
10
+ require File.dirname(__FILE__) + '/base.rb'
16
11
 
17
12
 
18
13
  class TimeoutTest < Test::Unit::TestCase
19
- include TestBaseMixin
20
-
21
- include Rufus::Verbs
14
+ include TestBaseMixin
22
15
 
16
+ include Rufus::Verbs
23
17
 
24
- def test_0
25
18
 
26
- error = nil
27
- t = Time.now
19
+ def test_0
28
20
 
29
- begin
30
- get :uri => "http://localhost:7777/lost", :to => 1
31
- rescue Timeout::Error => e
32
- error = e
33
- end
21
+ error = nil
22
+ t = Time.now
34
23
 
35
- assert_not_nil error
36
- assert (Time.now - t < 2)
24
+ begin
25
+ get :uri => "http://localhost:7777/lost", :to => 1
26
+ rescue Timeout::Error => e
27
+ error = e
37
28
  end
29
+
30
+ assert_not_nil error
31
+ assert (Time.now - t < 2)
32
+ end
38
33
  end
34
+