renderer_test.rb
4.62 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require File.dirname(__FILE__) + '/test_helper'
class RendererTest < Test::Unit::TestCase
def setup
@controller = SeleniumController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@controller.layout_override =<<END
<html><head><title>test layout</title></head><body>
@content_for_layout
</body></html>
END
end
def test_route
get :test_file, :testname => 'html.html' #initialize the controller
assert_equal 'http://test.host/selenium/tests/suite/test_case.sel',
@controller.url_for(:controller => 'selenium', :action => 'test_file', :testname => 'suite/test_case.sel')
end
def test_html
get :test_file, :testname => 'html.html'
assert_headers
expected =<<END
<html><head><title>test layout</title></head><body>
<p>Testing plain HTML</p>
<table>
<tr><th colspan="3">Test HTML</th></tr>
<tr><td>open</td><td>/selenium/setup</td><td> </td></tr>
</table>
<p>and it works...</p>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_rhtml
get :test_file, :testname => 'rhtml.rhtml'
assert_headers
expected =<<END
<html><head><title>test layout</title></head><body>
<table>
<tr><th colspan="3">Rhtml</th></tr>
<tr><td>open</td><td>/fi</td><td> </td></tr>
<tr><td>open</td><td>/fo</td><td> </td></tr>
<tr><td>open</td><td>/fum</td><td> </td></tr>
<tr><td>assertTitle</td><td>Partial from RHTML</td><td> </td></tr>
</table>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_selenese
get :test_file, :testname => 'selenese.sel'
assert_headers
expected =<<END
<html><head><title>test layout</title></head><body>
<p>Selenese <strong>support</strong></p>
<table>
<tr><th colspan="3">Selenese</th></tr>
<tr><td>open</td><td>/selenium/setup</td><td> </td></tr>
<tr><td>goBack</td><td> </td><td> </td></tr>
<tr><td>assertTitle</td><td>Partial from Selenese</td><td> </td></tr>
</table>
<p>works.</p>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_rselenese
get :test_file, :testname => 'rselenese.rsel'
assert_headers
expected = <<END
<html><head><title>test layout</title></head><body>
<table>
<tr><th colspan="3">Rselenese</th></tr>
<tr><td>open</td><td>/selenium/setup</td><td> </td></tr>
<tr><td>open</td><td>/selenium/setup?keep_session=true</td><td> </td></tr>
<tr><td>open</td><td>/selenium/setup?fixtures=all</td><td> </td></tr>
<tr><td>open</td><td>/selenium/setup?fixtures=foo%2Cbar</td><td> </td></tr>
<tr><td>open</td><td>/selenium/setup?clear_tables=foo%2Cbar&amp;fixtures=all</td><td> </td></tr>
<tr><td>assertAbsoluteLocation</td><td>exact:http://test.host/selenium/setup</td><td> </td></tr>
<tr><td>assertTitle</td><td>selenium</td><td> </td></tr>
<tr><td>assertTitle</td><td>Partial from RSelenese</td><td> </td></tr>
</table>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_partial_support
get :test_file, :testname => 'partials/all_partials.rsel'
assert_headers
expected = <<END
<html><head><title>test layout</title></head><body>
<table>
<tr><th colspan="3">All partials</th></tr>
<tr><td>assertTitle</td><td>Partial from All partials</td><td> </td></tr>
<tr><td>type</td><td>partial</td><td>HTML partial</td></tr>
<tr><td>type</td><td>world</td><td>RHTML partial</td></tr>
<tr><td>type</td><td>partial</td><td>Selenese partial</td></tr>
<tr><td>type</td><td>world</td><td>RSelenese partial</td></tr>
<tr><td>type</td><td>nesting</td><td>Nesting partial</td></tr>
<tr><td>type</td><td>dlrow</td><td>RSelenese partial</td></tr>
</table>
</body></html>
END
assert_text_equal expected, @response.body
end
def test_own_layout
get :test_file, :testname => 'own_layout.html'
assert_headers
expected =<<END
<html>
<head>
<title>Test case with own layout</title>
<style type="text/css"> body { background-color: #ccc; } </style>
</head>
<body>
<table>
<tr><th colspan="3">Test own layout</th></tr>
<tr><td>open</td><td>/selenium/setup</td><td> </td></tr>
</table>
</body>
</html>
END
assert_text_equal expected, @response.body
end
def test_not_found
get :test_file, :testname => 'missing'
assert_response 404
assert_equal 'Not found', @response.body
end
def assert_headers
assert_response :success
assert_equal 'no-cache', @response.headers['Cache-control']
assert_equal 'no-cache', @response.headers['Pragma']
assert_equal '-1', @response.headers['Expires']
end
end