ZenTest 3.11.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,48 +0,0 @@
1
- require 'test/unit'
2
- require 'test/zentest_assertions'
3
-
4
- unless defined? $TESTING_RTC then
5
- $TESTING_RTC = true
6
-
7
- begin
8
- require 'test/rails'
9
- rescue LoadError, NameError
10
- $TESTING_RTC = false
11
- end
12
- end
13
-
14
- begin
15
- module TRHelper
16
- def tr_helper; end
17
- end
18
- class TRHelperTest < Test::Rails::HelperTestCase; end
19
- rescue RuntimeError
20
- end if $TESTING_RTC
21
-
22
- begin
23
- module Widgets; end
24
- module Widgets::SomeHelper
25
- def widgets_some_helper; end
26
- end
27
- class Widgets::SomeHelperTest < Test::Rails::HelperTestCase; end
28
- rescue RuntimeError
29
- end if $TESTING_RTC
30
-
31
- class TestRailsHelperTestCase < Test::Unit::TestCase
32
-
33
- def test_self_inherited
34
- assert defined? TRHelperTest
35
-
36
- assert_includes TRHelperTest.instance_methods, 'tr_helper'
37
- end
38
-
39
- def test_self_inherited_namespaced
40
- assert defined? Widgets
41
- assert defined? Widgets::SomeHelperTest
42
-
43
- assert_includes(Widgets::SomeHelperTest.instance_methods,
44
- 'widgets_some_helper')
45
- end
46
-
47
- end if $TESTING_RTC
48
-
@@ -1,275 +0,0 @@
1
- require 'test/unit'
2
- require 'test/zentest_assertions'
3
-
4
- unless defined? $TESTING_RTC then
5
- $TESTING_RTC = true
6
-
7
- begin
8
- require 'test/rails'
9
- rescue LoadError, NameError
10
- $TESTING_RTC = false
11
- end
12
- end
13
-
14
- module Rails
15
- module VERSION
16
- STRING = '99.99.99' unless defined? STRING # HACK
17
- end
18
- end
19
-
20
- class TestRailsViewTestCase < Test::Rails::ViewTestCase
21
-
22
- def setup
23
- @assert_tag = []
24
- @assert_no_tag = []
25
-
26
- @assert_select = []
27
- end
28
-
29
- def test_assert_field
30
- assert_field :text, :game, :amount
31
-
32
- assert_equal 2, @assert_select.length
33
-
34
- expected = ["input[type='text'][name='game[amount]']"]
35
-
36
- assert_equal expected, @assert_select.first
37
-
38
- expected = ["label[for='game_amount']"]
39
-
40
- assert_equal expected, @assert_select.last
41
- end
42
-
43
- def test_assert_field_form
44
- assert_field '/game/save', :text, :game, :amount
45
-
46
- assert_equal 4, @assert_select.length
47
-
48
- assert_equal @assert_select.shift, ["form[action='/game/save']"]
49
- assert_equal(@assert_select.shift,
50
- ["input[type='text'][name='game[amount]']"])
51
-
52
- assert_equal @assert_select.shift, ["form[action='/game/save']"]
53
- assert_equal @assert_select.shift, ["label[for='game_amount']"]
54
- end
55
-
56
- def test_assert_form
57
- assert_form '/game/save'
58
-
59
- assert_equal 1, @assert_select.length
60
- assert_equal ["form[action='/game/save']"], @assert_select.first
61
- end
62
-
63
- def test_assert_form_method
64
- assert_form '/game/save', :post
65
-
66
- assert_equal 1, @assert_select.length
67
- assert_equal ["form[action='/game/save'][method='post']"],
68
- @assert_select.first
69
- end
70
-
71
- def test_assert_form_enctype
72
- assert_form '/game/save', nil, 'multipart/form-data'
73
-
74
- assert_equal 1, @assert_select.length
75
- assert_equal ["form[action='/game/save'][enctype='multipart/form-data']"],
76
- @assert_select.first
77
- end
78
-
79
- def test_assert_h
80
- assert_h 1, 'hi'
81
-
82
- assert_equal [['h1', { :text => 'hi' }]], @assert_select
83
- end
84
-
85
- def test_assert_img
86
- assert_image '/images/bucket.jpg'
87
-
88
- assert_equal [["img[src='/images/bucket.jpg']"]], @assert_select
89
- end
90
-
91
- def test_assert_input
92
- assert_input :text, 'game[amount]'
93
-
94
- assert_equal 1, @assert_select.length
95
- assert_equal ["input[type='text'][name='game[amount]']"],
96
- @assert_select.first
97
- end
98
-
99
- def test_assert_input_form
100
- assert_input '/game/save', :text, 'game[amount]'
101
-
102
- assert_equal 2, @assert_select.length
103
- assert_equal ["form[action='/game/save']"], @assert_select.shift
104
- assert_equal ["input[type='text'][name='game[amount]']"],
105
- @assert_select.shift
106
- end
107
-
108
- def test_assert_input_value
109
- assert_input :text, 'game[amount]', 5
110
-
111
- expected = ["input[type='text'][name='game[amount]'][value='5']"]
112
-
113
- assert_equal 1, @assert_select.length
114
- assert_equal expected, @assert_select.first
115
- end
116
-
117
- def test_assert_label
118
- assert_label 'game_amount'
119
-
120
- expected = ["label[for='game_amount']"]
121
-
122
- assert_equal 1, @assert_select.length
123
- assert_equal expected, @assert_select.first
124
- end
125
-
126
- def test_assert_label_form
127
- assert_label '/game/save', 'game_amount'
128
-
129
- assert_equal 2, @assert_select.length
130
- assert_equal ["form[action='/game/save']"], @assert_select.shift
131
- assert_equal ["label[for='game_amount']"], @assert_select.shift
132
- end
133
-
134
- def test_assert_links_to
135
- assert_links_to '/game/show/1', 'hi'
136
-
137
- expected = ["a[href='/game/show/1']", { :text => 'hi' }]
138
-
139
-
140
- assert_equal 1, @assert_select.length
141
- assert_equal expected, @assert_select.first
142
- end
143
-
144
- def test_assert_multipart_form
145
- assert_multipart_form '/game/save'
146
-
147
- expected = [
148
- "form[action='/game/save'][method='post'][enctype='multipart/form-data']"
149
- ]
150
-
151
- assert_equal 1, @assert_select.length
152
- assert_equal expected, @assert_select.first
153
- end
154
-
155
- def test_assert_post_form
156
- assert_post_form '/game/save'
157
-
158
- expected = ["form[action='/game/save'][method='post']"]
159
-
160
- assert_equal 1, @assert_select.length
161
- assert_equal expected, @assert_select.first
162
- end
163
-
164
- def test_assert_select_tag
165
- assert_select_tag :game, :location_id,
166
- 'Ballet' => 1, 'Guaymas' => 2
167
-
168
- assert_equal 2, @assert_select.length
169
-
170
- assert_include(@assert_select,
171
- ["select[name='game[location_id]'] option[value='2']",
172
- { :text => 'Guaymas' }])
173
- assert_include(@assert_select,
174
- ["select[name='game[location_id]'] option[value='1']",
175
- { :text => 'Ballet' }])
176
- end
177
-
178
- def test_assert_select_tag_form
179
- assert_select_tag '/game/save', :game, :location_id,
180
- 'Ballet' => 1, 'Guaymas' => 2
181
-
182
- assert_equal 4, @assert_select.length
183
-
184
- assert_include @assert_select, ["form[action='/game/save']"]
185
- assert_include(@assert_select,
186
- ["select[name='game[location_id]'] option[value='2']",
187
- { :text => 'Guaymas' }])
188
- assert_include @assert_select, ["form[action='/game/save']"]
189
- assert_include(@assert_select,
190
- ["select[name='game[location_id]'] option[value='1']",
191
- { :text => 'Ballet' }])
192
- end
193
-
194
- def test_assert_submit
195
- assert_submit 'Save!'
196
-
197
- assert_equal 1, @assert_select.length
198
- assert_equal ["input[type='submit'][value='Save!']"], @assert_select.first
199
- end
200
-
201
- def test_assert_submit_form
202
- assert_submit '/game/save', 'Save!'
203
-
204
- assert_equal 2, @assert_select.length
205
- assert_equal ["form[action='/game/save']"], @assert_select.shift
206
- assert_equal ["input[type='submit'][value='Save!']"], @assert_select.shift
207
- end
208
-
209
- def test_assert_tag_in_form
210
- assert_tag_in_form '/game/save', :tag => 'input'
211
-
212
- expected = {
213
- :tag => "form",
214
- :attributes => { :action => "/game/save" },
215
- :descendant => { :tag => "input" },
216
- }
217
-
218
- assert_equal 1, @assert_tag.length
219
- assert_equal expected, @assert_tag.first
220
- end
221
-
222
- def test_assert_text_area
223
- assert_text_area 'post[body]'
224
-
225
- assert_equal 1, @assert_select.length
226
- assert_equal ["textarea[name='post[body]']"], @assert_select.shift
227
- end
228
-
229
- def test_assert_text_area_body
230
- assert_text_area 'post[body]', 'OMG!1! that skank stole my BF!~1!'
231
-
232
- assert_equal 1, @assert_select.length
233
- assert_equal ["textarea[name='post[body]']",
234
- { :text => 'OMG!1! that skank stole my BF!~1!' }],
235
- @assert_select.shift
236
- end
237
-
238
- def test_assert_text_area_form
239
- assert_text_area '/post/save', 'post[body]'
240
-
241
- assert_equal 2, @assert_select.length
242
- assert_equal ["form[action='/post/save']"], @assert_select.shift
243
- assert_equal ["textarea[name='post[body]']"], @assert_select.shift
244
- end
245
-
246
- def test_assert_title
247
- assert_title 'hi'
248
-
249
- assert_equal [['title', { :text => 'hi' }]], @assert_select
250
- end
251
-
252
- def test_deny_links_to
253
- deny_links_to '/game/show/1', 'hi'
254
-
255
- expected = ["a[href='/game/show/1']", { :text => 'hi', :count => 0 }]
256
-
257
- assert_equal 1, @assert_select.length
258
- assert_equal expected, @assert_select.first
259
- end
260
-
261
- def assert_tag(arg)
262
- @assert_tag << arg
263
- end
264
-
265
- def assert_no_tag(arg)
266
- @assert_no_tag << arg
267
- end
268
-
269
- def assert_select(*args)
270
- @assert_select << args
271
- yield if block_given?
272
- end
273
-
274
- end if $TESTING_RTC
275
-
@@ -1,128 +0,0 @@
1
- require 'test/unit'
2
- require 'test/zentest_assertions'
3
-
4
- class TestZenTestAssertions < Test::Unit::TestCase
5
- @@has_mini = defined? Mini
6
- @@exception = if @@has_mini then
7
- Mini::Assertion
8
- else
9
- Test::Unit::AssertionFailedError
10
- end
11
-
12
- def util_assert_triggered expected
13
- e = assert_raises @@exception do
14
- yield
15
- end
16
-
17
- assert_equal expected, e.message.sub(/(---Backtrace---).*/m, '\1')
18
- end
19
-
20
- def test_assert_empty
21
- assert_empty []
22
-
23
- msg = if @@has_mini then
24
- "Expected [true] to be empty."
25
- else
26
- "[true] expected to be empty."
27
- end
28
-
29
- util_assert_triggered msg do
30
- assert_empty [true]
31
- end
32
- end
33
-
34
- def test_assert_include
35
- assert_include [true], true
36
-
37
- msg = if @@has_mini then
38
- "Expected [true] to include false."
39
- else
40
- "[true]\ndoes not include\nfalse."
41
- end
42
-
43
- util_assert_triggered msg do
44
- assert_include [true], false
45
- end
46
- end
47
-
48
- def test_assert_in_epsilon
49
- assert_in_epsilon 1.234, 1.234, 0.0001
50
-
51
- msg = if @@has_mini then
52
- "Expected 1.235 - 1.234 (0.00100000000000011) to be < 0.0001234."
53
- else
54
- "1.235 expected to be within 0.01% of 1.234, was 0.000809716599190374"
55
- end
56
-
57
- util_assert_triggered msg do
58
- assert_in_epsilon 1.235, 1.234, 0.0001
59
- end
60
- end
61
-
62
- def test_deny
63
- deny false
64
- deny nil
65
-
66
- e = assert_raises Test::Unit::AssertionFailedError do
67
- deny true
68
- end
69
-
70
- assert_match(/Failed refutation, no message given/, e.message)
71
- end
72
-
73
- def test_deny_empty
74
- deny_empty [true]
75
-
76
- msg = if @@has_mini then
77
- "Expected [] to not be empty."
78
- else
79
- "[] expected to have stuff."
80
- end
81
-
82
- util_assert_triggered msg do
83
- deny_empty []
84
- end
85
-
86
- end
87
-
88
- def test_deny_equal
89
- deny_equal true, false
90
-
91
- assert_raises Test::Unit::AssertionFailedError do
92
- deny_equal true, true
93
- end
94
- end
95
-
96
- def test_deny_include
97
- deny_include [true], false
98
-
99
- msg = if @@has_mini then
100
- "Expected [true] to not include true."
101
- else
102
- "[true] includes true."
103
- end
104
-
105
- util_assert_triggered msg do
106
- deny_include [true], true
107
- end
108
- end
109
-
110
- def test_deny_nil
111
- deny_nil false
112
-
113
- assert_raises Test::Unit::AssertionFailedError do
114
- deny_nil nil
115
- end
116
- end
117
-
118
- def test_util_capture
119
- out, err = util_capture do
120
- puts 'out'
121
- $stderr.puts 'err'
122
- end
123
-
124
- assert_equal "out\n", out
125
- assert_equal "err\n", err
126
- end
127
- end
128
-