This repository was archived by the owner on Jan 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.rb
68 lines (57 loc) · 1.51 KB
/
test.rb
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
require 'uri'
require 'drb'
require 'rss'
require 'rubygems'
require 'test/spec'
require 'json'
require 'post'
def get(uri)
Net::HTTP.get(URI.parse(uri))
end
def post(uri, params)
Net::HTTP.post_form(URI.parse(uri), params).body
end
DB_URI = "druby://localhost:8777"
SERVER_URI = "http://localhost:4568/ajax/"
context "db server" do
setup do
DRb.start_service
@db = DRbObject.new(nil, DB_URI)
end
specify "should support array methods" do
(@db << "foo").last.should.equal "foo"
@db.empty?.should.be false
@db.pop
end
end
context "http server" do
specify "/last should return a post" do
res = get(SERVER_URI + 'last')
entry = JSON.parse(res)
entry.should.be.an.instance_of(Hash)
entry["text"].should.not.be.nil
end
specify "should accept new posts under /next" do
res = post(SERVER_URI + "next", {
"text" => "It was a dark and stormy night.",
"user" => "lennon"
})
entry = JSON.parse(res)
entry.should.be.an.instance_of(Hash)
entry["text"].should.not.be.nil
end
specify "should return an array of posts from /story" do
res = JSON.parse(get(SERVER_URI + 'story'))
res.should.be.an.instance_of(Array)
res.each do |entry|
entry.should.be.an.instance_of(Hash)
entry["text"].should.not.be.nil
end
end
specify "should return a valid RSS feed" do
res = get("http://localhost:4568/misfict.rss")
rss = RSS::Parser.parse(res)
rss.channel.title.should.not.be.nil
rss.items.size.should.not == 0
end
end