public
Description: GET, POST, PUT, DELETE, with something around (ruby)
Homepage: http://rufus.rubyforge.org/rufus-verbs
Clone URL: git://github.com/jmettraux/rufus-verbs.git
Search Repo:
jmettraux (author)
Wed Apr 30 22:28:53 -0700 2008
commit  53ef8e94ca9995bcef04dc69e15e2d3454fe901a
tree    c2e7927bef03c22db556839f406fc2a10fcf8749
parent  b49482e567581e899e976930e0915d88f837aa60
rufus-verbs / test / simple_test.rb
100644 109 lines (77 sloc) 2.639 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#
# Testing rufus-verbs
#
# jmettraux@gmail.com
#
# Sun Jan 13 12:33:03 JST 2008
#
 
require 'test/unit'
require 'testbase'
 
require 'rufus/verbs'
 
 
class SimpleTest < Test::Unit::TestCase
    include TestBaseMixin
 
    include Rufus::Verbs
 
 
    def test_0
 
        #res = get :uri => "http://localhost:7777/items"
        #assert_equal 200, res.code.to_i
        #assert_equal "{}", res.body.strip
        expect 200, {}, get(:uri => "http://localhost:7777/items")
 
        res = post :uri => "http://localhost:7777/items/0", :d => "Toto"
        assert_equal 201, res.code.to_i
        assert_equal "http://localhost:7777/items/0", res['Location']
 
        expect 200, { 0 => "Toto" }, get(:uri => "http://localhost:7777/items")
 
        res = get :host => "localhost", :port => 7777, :path => "/items"
        assert_equal 200, res.code.to_i
        assert_equal ({ 0 => "Toto" }), eval(res.body)
 
        res = put :uri => "http://localhost:7777/items/0", :d => "Toto2"
        assert_equal 200, res.code.to_i
 
        expect 200, { 0 => "Toto2" }, get(:uri => "http://localhost:7777/items")
 
        res = put :uri => "http://localhost:7777/items/0", :d => "Toto3", :fake_put => true
        assert_equal 200, res.code.to_i
 
        expect 200, { 0 => "Toto3" }, get(:uri => "http://localhost:7777/items")
    end
 
    def test_1
 
        ep = EndPoint.new(:host => "localhost", :port => 7777)
        expect 200, {}, ep.get(:resource => "items")
 
        res = ep.put :resource => "items", :id => 0 do
            "blockdata"
        end
        assert_equal 404, res.code.to_i
 
        res = ep.post :resource => "items", :id => 0 do
            "blockdata"
        end
        assert_equal 201, res.code.to_i
        assert_equal "http://localhost:7777/items/0", res['Location']
 
        expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
    end
 
    def test_2
 
        s = get(:uri => "http://localhost:7777/items", :body => true)
        assert_equal "{}", s.strip
    end
 
    #
    # The "no-path" test
    #
    def test_3
 
        r = get "http://rufus.rubyforge.org"
        assert_kind_of Net::HTTPOK, r
    end
 
    #
    # HEAD
    #
    def test_4
 
        res = head "http://localhost:7777/items"
        assert_equal 200, res.code.to_i
        assert_nil res.body
    end
 
    #
    # OPTIONS
    #
    def test_5
 
        r = options "http://localhost:7777/items"
        assert_equal [ :delete, :get, :head, :options, :post, :put], r
    end
 
    def test_6
 
        r = Rufus::Verbs::options "http://localhost:7777/items"
        assert_equal [ :delete, :get, :head, :options, :post, :put], r
    end
end