jmettraux / rufus-verbs

GET, POST, PUT, DELETE, with something around (ruby)

This URL has Read+Write access

rufus-verbs / test / fopen_test.rb
100644 59 lines (41 sloc) 1.207 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
#
# Testing rufus-verbs
#
# jmettraux@gmail.com
#
# Mon Feb 18 13:00:36 JST 2008
#
 
 
require File.dirname(__FILE__) + '/base.rb'
 
 
class UriTest < Test::Unit::TestCase
  include TestBaseMixin
 
  include Rufus::Verbs
 
  def test_0
 
    uri = "http://localhost:7777/items"
 
    res = fopen uri
    assert_equal 200, res.code.to_i
    assert_equal "{}", res.body.strip
 
    res = fopen "file:CHANGELOG.txt"
    assert_kind_of String, res.read
 
    res = fopen "CHANGELOG.txt"
    assert_kind_of String, res.read
 
    res = fopen "http://localhost:7777/things"
    assert_equal 200, res.code.to_i
    assert_equal "{}", res.body.strip
      #
      # it follows redirections :)
 
    res = fopen "http://localhost:7777/things", :noredir => true
    assert_equal 303, res.code.to_i
 
    fopen "CHANGELOG.txt" do |f|
      assert_kind_of String, f.read
    end
 
    fopen "http://localhost:7777/things" do |res|
      assert_equal 200, res.code.to_i
      assert_equal "{}", res.body.strip
    end
  end
 
  def test_1
 
    assert_kind_of String, fopen("CHANGELOG.txt").read
    assert_kind_of String, fopen("file:CHANGELOG.txt").read
    assert_kind_of String, fopen("http://localhost:7777/items").read
  end
end