Sha256: 8efed1199179af4a00bc4cee0343996b71411ef0e1490b86574159506e2d89f2

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

#
# 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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rufus-verbs-0.1 test/simple_test.rb