rufus-verbs 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+
2
+ #
3
+ # Testing rufus-verbs
4
+ #
5
+ # jmettraux@gmail.com
6
+ #
7
+ # Thu Jan 17 10:15:52 JST 2008
8
+ #
9
+
10
+ require 'timeout'
11
+ require 'test/unit'
12
+
13
+ require 'rufus/verbs'
14
+
15
+
16
+ class ProxyTest < Test::Unit::TestCase
17
+
18
+ include Rufus::Verbs
19
+
20
+
21
+ def test_0
22
+
23
+ res0 = get(
24
+ "http://en.wikipedia.org/wiki/Ruby_%28programming_language%29",
25
+ :proxy => false)
26
+
27
+ assert_not_nil res0.body # just displaying the test dot
28
+
29
+ proxies = find_proxies
30
+
31
+ res1 = nil
32
+
33
+ proxies.each do |proxy|
34
+ begin
35
+ Timeout::timeout 2 do
36
+ res1 = get(
37
+ "http://en.wikipedia.org/wiki/"+
38
+ "Ruby_%28programming_language%29",
39
+ :proxy => proxy)
40
+ end
41
+ break if res1.code.to_i == 200
42
+ rescue Exception => e
43
+ puts "skipped proxy '#{proxy}'"
44
+ end
45
+ end
46
+
47
+ if res1.code.to_i != 200
48
+ puts
49
+ puts
50
+ puts "sorry, couldn't find an open proxy, couldn't test the"
51
+ puts "proxy feature of 'rufus-verbs'"
52
+ puts
53
+ puts
54
+ return
55
+ end
56
+
57
+ assert_equal res0.body.length, res1.body.length
58
+
59
+ #p res0.to_hash
60
+ #p res1.to_hash
61
+
62
+ via1 = res1["via"].split(", ")[-1]
63
+ # last proxy
64
+
65
+ assert_no_match /wikimedia\.org/, via1
66
+ # making sure that the proxy was not one of wikipedia
67
+ end
68
+
69
+ protected
70
+
71
+ def find_proxies
72
+
73
+ res = get "http://freeproxy.ch/proxy.txt"
74
+ lines = res.body.split "\n"
75
+ lines[4..-1].collect do |line|
76
+ l = line.split("\t")
77
+ 'http://' + l[0]
78
+ end
79
+ end
80
+
81
+ end
82
+
@@ -0,0 +1,26 @@
1
+
2
+ #
3
+ # Testing rufus-verbs
4
+ #
5
+ # jmettraux@gmail.com
6
+ #
7
+ # Sun Jan 13 20:02:25 JST 2008
8
+ #
9
+
10
+ require 'test/unit'
11
+ require 'testbase'
12
+
13
+ require 'rufus/verbs'
14
+
15
+
16
+ class RedirTest < Test::Unit::TestCase
17
+ include TestBaseMixin
18
+
19
+ include Rufus::Verbs
20
+
21
+
22
+ def test_0
23
+
24
+ expect 200, {}, get(:uri => "http://localhost:7777/things")
25
+ end
26
+ end
@@ -0,0 +1,74 @@
1
+
2
+ #
3
+ # Testing rufus-verbs
4
+ #
5
+ # jmettraux@gmail.com
6
+ #
7
+ # Sun Jan 13 12:33:03 JST 2008
8
+ #
9
+
10
+ require 'test/unit'
11
+ require 'testbase'
12
+
13
+ require 'rufus/verbs'
14
+
15
+
16
+ class SimpleTest < Test::Unit::TestCase
17
+ include TestBaseMixin
18
+
19
+ include Rufus::Verbs
20
+
21
+
22
+ def test_0
23
+
24
+ #res = get :uri => "http://localhost:7777/items"
25
+ #assert_equal 200, res.code.to_i
26
+ #assert_equal "{}", res.body.strip
27
+ expect 200, {}, get(:uri => "http://localhost:7777/items")
28
+
29
+ res = post :uri => "http://localhost:7777/items/0", :d => "Toto"
30
+ assert_equal 201, res.code.to_i
31
+ assert_equal "http://localhost:7777/items/0", res['Location']
32
+
33
+ expect 200, { 0 => "Toto" }, get(:uri => "http://localhost:7777/items")
34
+
35
+ res = get :host => "localhost", :port => 7777, :path => "/items"
36
+ assert_equal 200, res.code.to_i
37
+ assert_equal ({ 0 => "Toto" }), eval(res.body)
38
+
39
+ res = put :uri => "http://localhost:7777/items/0", :d => "Toto2"
40
+ assert_equal 200, res.code.to_i
41
+
42
+ expect 200, { 0 => "Toto2" }, get(:uri => "http://localhost:7777/items")
43
+
44
+ res = put :uri => "http://localhost:7777/items/0", :d => "Toto3", :fake_put => true
45
+ assert_equal 200, res.code.to_i
46
+
47
+ expect 200, { 0 => "Toto3" }, get(:uri => "http://localhost:7777/items")
48
+ end
49
+
50
+ def test_1
51
+
52
+ ep = EndPoint.new(:host => "localhost", :port => 7777)
53
+ expect 200, {}, ep.get(:resource => "items")
54
+
55
+ res = ep.put :resource => "items", :id => 0 do
56
+ "blockdata"
57
+ end
58
+ assert_equal 404, res.code.to_i
59
+
60
+ res = ep.post :resource => "items", :id => 0 do
61
+ "blockdata"
62
+ end
63
+ assert_equal 201, res.code.to_i
64
+ assert_equal "http://localhost:7777/items/0", res['Location']
65
+
66
+ expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
67
+ end
68
+
69
+ def test_2
70
+
71
+ s = get(:uri => "http://localhost:7777/items", :body => true)
72
+ assert_equal "{}", s.strip
73
+ end
74
+ end
data/test/test.rb ADDED
@@ -0,0 +1,12 @@
1
+
2
+ require 'dryrun_test'
3
+ require 'iconditional_test'
4
+ require 'simple_test'
5
+ require 'auth_test'
6
+ require 'redir_test'
7
+ require 'block_test'
8
+ require 'https_test'
9
+ require 'proxy_test'
10
+
11
+ require 'conditional_test'
12
+
data/test/testbase.rb ADDED
@@ -0,0 +1,47 @@
1
+
2
+ #
3
+ # Testing rufus-verbs
4
+ #
5
+ # jmettraux@gmail.com
6
+ #
7
+ # Sun Jan 13 18:02:50 JST 2008
8
+ #
9
+
10
+ require 'items'
11
+
12
+
13
+ module TestBaseMixin
14
+
15
+ def setup
16
+
17
+ @server = ItemServer.new
18
+ @server.start
19
+ end
20
+
21
+ def teardown
22
+
23
+ @server.shutdown
24
+ end
25
+
26
+ protected
27
+
28
+ #
29
+ # one or two asserts...
30
+ #
31
+ def expect (code, res_body, res)
32
+
33
+ assert_equal code, res.code.to_i
34
+
35
+ val = res.body
36
+
37
+ val = if res_body.is_a?(String)
38
+ val.strip
39
+ elsif res_body
40
+ eval(val)
41
+ end
42
+
43
+ assert_equal(res_body, val) if res_body
44
+
45
+ res
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rufus-verbs
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - John Mettraux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-01-18 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: john at openwfe dot org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.txt
24
+ files:
25
+ - lib/rufus
26
+ - lib/rufus/verbs
27
+ - lib/rufus/verbs/conditional.rb
28
+ - lib/rufus/verbs/endpoint.rb
29
+ - lib/rufus/verbs.rb
30
+ - test/auth_test.rb
31
+ - test/block_test.rb
32
+ - test/conditional_test.rb
33
+ - test/dryrun_test.rb
34
+ - test/https_test.rb
35
+ - test/iconditional_test.rb
36
+ - test/items.rb
37
+ - test/proxy_test.rb
38
+ - test/redir_test.rb
39
+ - test/simple_test.rb
40
+ - test/test.rb
41
+ - test/testbase.rb
42
+ - README.txt
43
+ has_rdoc: true
44
+ homepage: http://rufus.rubyforge.org/rufus_verbs
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 0.9.5
66
+ signing_key:
67
+ specification_version: 2
68
+ summary: GET, POST, PUT, DELETE, with something around
69
+ test_files:
70
+ - test/test.rb