-
Notifications
You must be signed in to change notification settings - Fork 3
/
page_test.rb
69 lines (54 loc) · 2.29 KB
/
page_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 'test_helper'
class PageTest < Test::Unit::TestCase
context "A page" do
setup do
@page = Trample::Page.new(:get, "http://google.com/", :username => "joetheuser")
end
should "have a request_method" do
assert_equal :get, @page.request_method
end
should "have a url" do
assert_equal "http://google.com/", @page.url
end
should "have request parameters" do
assert_equal({:username => "joetheuser"}, @page.parameters)
end
should "be equal with the same request_method and url" do
assert_equal Trample::Page.new(:get, "http://google.com"), Trample::Page.new(:get, "http://google.com")
end
should "not be equal with a different request_method or url" do
assert_not_equal Trample::Page.new(:get, "http://google.com"), Trample::Page.new(:get, "http://google.com/asdf")
end
end
context "Block-based request parameters for POST requests" do
setup do
@page = Trample::Page.new(:post, "http://google.com/:id", lambda { { :id => 1, :username => "joetheuser" } })
end
should "be resolved at call time" do
assert_equal({:username => "joetheuser", :id => 1}, @page.parameters)
end
should "interpolate parameters into the url" do
assert_equal "http://google.com/1", @page.url
end
should "not interpolate the port number if there is one" do
page = Trample::Page.new(:post, "http://localhost:3000/:id", lambda { { :id => 1, :username => "joetheuser" } })
assert_equal "http://localhost:3000/1", page.url
end
end
context "Block based parameters for GET requests" do
setup do
@page = Trample::Page.new(:get, "http://mysite.com/somethings/:id", lambda { {:id => 5} })
end
should "interpolate those parameters with the url string" do
assert_equal "http://mysite.com/somethings/5", @page.url
end
should "interpolate a different parameter each time" do
page = Trample::Page.new(:get, "http://mysite.com/somethings/:id", lambda { {:id => rand(10)} })
assert_not_equal page.url, page.url
end
should "not interpolate the port number if there is one" do
page = Trample::Page.new(:get, "http://mysite.com:8080/somethings/:id", lambda { {:id => 5} })
assert_equal "http://mysite.com:8080/somethings/5", page.url
end
end
end