ZenTest 3.6.0 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +11 -0
- data/lib/autotest.rb +6 -6
- data/lib/autotest/notify.rb +23 -27
- data/lib/autotest/screen.rb +12 -11
- data/lib/test/rails.rb +1 -1
- data/lib/test/rails/functional_test_case.rb +1 -1
- data/lib/test/rails/view_test_case.rb +218 -114
- data/lib/zentest.rb +1 -1
- data/test/test_rails_view_test_case.rb +236 -28
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
=== 3.6.1 / 2007-07-23
|
2
|
+
|
3
|
+
* 4 minor enhancements:
|
4
|
+
* Test::Rails::ViewTestCase now uses assert_select.
|
5
|
+
* assert_form and friends now work with blocks like assert_select
|
6
|
+
does.
|
7
|
+
* Allow path_parameters in view tests to be ammended, making working
|
8
|
+
with routes easier.
|
9
|
+
* New version of autotest/notify.rb uses notify-send.
|
10
|
+
* Fixed rdoc formatting on autotest and a couple plugins.
|
11
|
+
|
1
12
|
=== 3.6.0 / 2007-05-25
|
2
13
|
|
3
14
|
* 4 major enhancements:
|
data/lib/autotest.rb
CHANGED
@@ -48,12 +48,12 @@ $TESTING = false unless defined? $TESTING
|
|
48
48
|
#
|
49
49
|
# Strategy:
|
50
50
|
#
|
51
|
-
# 1
|
52
|
-
# 2
|
53
|
-
# 3
|
54
|
-
# 4
|
55
|
-
# 5
|
56
|
-
# 6
|
51
|
+
# 1. Find all files and associate them from impl <-> test.
|
52
|
+
# 2. Run all tests.
|
53
|
+
# 3. Scan for failures.
|
54
|
+
# 4. Detect changes in ANY (ruby?. file, rerun all failures + changed files.
|
55
|
+
# 5. Until 0 defects, goto 3.
|
56
|
+
# 6. When 0 defects, goto 2.
|
57
57
|
|
58
58
|
class Autotest
|
59
59
|
|
data/lib/autotest/notify.rb
CHANGED
@@ -1,38 +1,34 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def self.notify title, msg, ico = :info
|
11
|
-
LibNotify::Notification.new(title, msg, "gtk-#{ico}", nil).show
|
1
|
+
module Autotest::Notify
|
2
|
+
def self.notify(title, message, priority='critical')
|
3
|
+
icon = if priority == 'critical'
|
4
|
+
'dialog-error'
|
5
|
+
else
|
6
|
+
'dialog-information'
|
7
|
+
end
|
8
|
+
system "notify-send -u #{priority} -t 10000 -i #{icon} '#{title}' '#{message.inspect}'"
|
12
9
|
end
|
13
10
|
|
14
11
|
Autotest.add_hook :red do |at|
|
15
|
-
|
16
|
-
|
12
|
+
tests = 0
|
13
|
+
assertions = 0
|
14
|
+
failures = 0
|
15
|
+
errors = 0
|
16
|
+
at.results.scan(/(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/) do |t, a, f, e|
|
17
|
+
tests += t.to_i
|
18
|
+
assertions += a.to_i
|
19
|
+
failures += f.to_i
|
20
|
+
errors += e.to_i
|
21
|
+
end
|
22
|
+
message = "%d tests, %d assertions, %d failures, %d errors" %
|
23
|
+
[tests, assertions, failures, errors]
|
24
|
+
notify("Tests Failed", message)
|
17
25
|
end
|
18
26
|
|
19
27
|
Autotest.add_hook :green do |at|
|
20
|
-
notify
|
21
|
-
end
|
22
|
-
|
23
|
-
Autotest.add_hook :run do |at|
|
24
|
-
notify "autotest", "autotest was started" unless $TESTING
|
25
|
-
end
|
26
|
-
|
27
|
-
Autotest.add_hook :interrupt do |at|
|
28
|
-
notify "autotest", "autotest was reset" unless $TESTING
|
29
|
-
end
|
30
|
-
|
31
|
-
Autotest.add_hook :quit do |at|
|
32
|
-
notify "autotest", "autotest is exiting" unless $TESTING
|
28
|
+
notify("Tests Passed", "Outstanding tests passed", 'low') if at.tainted
|
33
29
|
end
|
34
30
|
|
35
31
|
Autotest.add_hook :all do |at|_hook
|
36
|
-
notify
|
32
|
+
notify("autotest", "Tests have fully passed", 'low')
|
37
33
|
end
|
38
34
|
end
|
data/lib/autotest/screen.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
##
|
2
|
+
# Autotest::Screen is test result notify GUN Screen's statusline.
|
3
|
+
#
|
4
|
+
# === screenshots
|
5
|
+
# * <img src="http://f.hatena.ne.jp/images/fotolife/s/secondlife/20061109/20061109015543.png" />
|
6
|
+
# * <img src="http://f.hatena.ne.jp/images/fotolife/s/secondlife/20061109/20061109015522.png" />
|
7
|
+
#
|
8
|
+
# == SYNOPSIS
|
9
|
+
# require 'autotest/screen'
|
10
|
+
# # Autotest::Screen.statusline = '%H %`%-w%{=b bw}%n %t%{-}%+w (your statusline)'
|
11
|
+
#
|
12
12
|
|
13
|
+
class Autotest::Screen
|
13
14
|
DEFAULT_STATUSLINE = '%H %`%-w%{=b bw}%n %t%{-}%+w'
|
14
15
|
DEFAULT_SCREEN_CMD = 'screen'
|
15
16
|
|
data/lib/test/rails.rb
CHANGED
@@ -247,7 +247,7 @@ $TESTING = true
|
|
247
247
|
# The test target no longer runs all tests, it stops on the first
|
248
248
|
# failure. This way a failure in a unit test doesn't fill your screen
|
249
249
|
# with less important errors because the underlying failure also
|
250
|
-
# affected your controllers and views.
|
250
|
+
# affected your controllers and views.
|
251
251
|
#
|
252
252
|
# The stats target is updated to account for controller and view tests.
|
253
253
|
|
@@ -11,18 +11,18 @@
|
|
11
11
|
#
|
12
12
|
# = Naming
|
13
13
|
#
|
14
|
-
# The test class must be named after your controller class name, so if
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
14
|
+
# The test class must be named after your controller class name, so if you're
|
15
|
+
# testing views for the +RouteController+ you would name your test case
|
16
|
+
# +RouteViewTest+. The test case will expect to find your view files in
|
17
|
+
# <tt>app/views/route</tt>.
|
18
18
|
#
|
19
|
-
# The test names should be in the form of +test_view_edgecase+ where
|
20
|
-
#
|
21
|
-
#
|
19
|
+
# The test names should be in the form of +test_view_edgecase+ where 'view'
|
20
|
+
# corresponds to the name of the view file, and 'edgecase' describes the
|
21
|
+
# scenario you are testing.
|
22
22
|
#
|
23
|
-
# If you are testing a view file named 'show.rhtml' your test should
|
24
|
-
#
|
25
|
-
#
|
23
|
+
# If you are testing a view file named 'show.rhtml' your test should be named
|
24
|
+
# +test_show+. If your view is behaves differently depending upon its
|
25
|
+
# parameters then you can make the test name descriptive like
|
26
26
|
# +test_show_photos+ and +test_show_no_photos+.
|
27
27
|
#
|
28
28
|
# = Examples
|
@@ -42,12 +42,13 @@
|
|
42
42
|
# render
|
43
43
|
#
|
44
44
|
# # assert that there's a form with an action of "/route/destroy"
|
45
|
-
# form_url
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
45
|
+
# assert_form form_url, :post do
|
46
|
+
# # with a hidden id field
|
47
|
+
# assert_input :hidden, :id
|
48
|
+
# # And a submit button that says 'Delete!'
|
49
|
+
# assert_submit 'Delete!'
|
50
|
+
# end
|
51
|
+
#
|
51
52
|
# # And a link back to the route so you don't delete it
|
52
53
|
# assert_links_to "/route/show/#{routes(:work).id}", 'No, I do not!'
|
53
54
|
# end
|
@@ -65,7 +66,7 @@
|
|
65
66
|
# class LayoutsViewTest < Test::Rails::ViewTestCase
|
66
67
|
#
|
67
68
|
# fixtures :users, :routes, :points, :photos
|
68
|
-
#
|
69
|
+
#
|
69
70
|
# def test_default
|
70
71
|
# # Template set-up
|
71
72
|
# @request.request_uri = '/foo'
|
@@ -77,12 +78,20 @@
|
|
77
78
|
# # Assert content just like a regular view test.
|
78
79
|
# assert_links_to '/', 'Home'
|
79
80
|
# assert_links_to '/user', 'Login'
|
80
|
-
# deny_links_to
|
81
|
-
#
|
82
|
-
#
|
81
|
+
# deny_links_to '/user/logout', 'Logout'
|
82
|
+
# assert_title 'Hello & Goodbye'
|
83
|
+
# assert_h 1, 'Hello & Goodbye'
|
83
84
|
# end
|
84
|
-
#
|
85
|
+
#
|
85
86
|
# end
|
87
|
+
#
|
88
|
+
# = Deprecated Features
|
89
|
+
#
|
90
|
+
# Form assertions are now using assert_select, so you don't need to pass URLs
|
91
|
+
# around everywhere and can instead use a block. (See above example).
|
92
|
+
#
|
93
|
+
# The form assertions will still work using the old syntax, but in a future
|
94
|
+
# release they will give warnings, then will be removed.
|
86
95
|
|
87
96
|
class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
88
97
|
|
@@ -95,6 +104,8 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
95
104
|
def setup
|
96
105
|
return if self.class == Test::Rails::ViewTestCase
|
97
106
|
|
107
|
+
@path_parameters ||= {}
|
108
|
+
|
98
109
|
klass_name = self.class.name.sub(/View/, 'Controller')
|
99
110
|
@controller_class_name ||= klass_name.sub 'Test', ''
|
100
111
|
|
@@ -135,7 +146,37 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
135
146
|
#
|
136
147
|
# render :template => 'profile/index'
|
137
148
|
#
|
138
|
-
#
|
149
|
+
# A test's path parameters may be overridden, allowing routes with
|
150
|
+
# additional parameters to work.
|
151
|
+
#
|
152
|
+
# == Working with Routes
|
153
|
+
#
|
154
|
+
# By default, a view tests sets the controller and action of a test to the
|
155
|
+
# controller name and action name for the test. This may be overriden.
|
156
|
+
#
|
157
|
+
# A test involving routes like:
|
158
|
+
#
|
159
|
+
# map.workspace '/users/:owner/workspace/:action',
|
160
|
+
# :controller => 'workspace', :action => 'workspace'
|
161
|
+
#
|
162
|
+
# Can be invoked by setting @path_parameters like this:
|
163
|
+
#
|
164
|
+
# def test__app_entry
|
165
|
+
# @path_parameters[:owner] = 'bob'
|
166
|
+
# @path_parameters[:action] = 'apps'
|
167
|
+
#
|
168
|
+
# render :partial => 'apps/app_entry'
|
169
|
+
#
|
170
|
+
# # ...
|
171
|
+
# end
|
172
|
+
#
|
173
|
+
# == View Lookup
|
174
|
+
#
|
175
|
+
# render strips off words trailing an _ in the test name one at a time until
|
176
|
+
# it finds a matching action. It tries the extensions 'rhtml', 'rxml',
|
177
|
+
# 'rjs', and 'mab' in order for each action until a view is found.
|
178
|
+
#
|
179
|
+
# With this test case:
|
139
180
|
#
|
140
181
|
# class RouteViewTest < Test::Rails::ViewTestCase
|
141
182
|
# def test_show_photos
|
@@ -146,19 +187,20 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
146
187
|
# end
|
147
188
|
# end
|
148
189
|
#
|
149
|
-
#
|
190
|
+
# In test_show_photos, render will look for:
|
150
191
|
# * app/views/route/show_photos.rhtml
|
151
192
|
# * app/views/route/show_photos.rxml
|
152
|
-
# * app/views/route/
|
153
|
-
# * app/views/route/
|
193
|
+
# * app/views/route/show_photos.rjs
|
194
|
+
# * app/views/route/show_photos.mab
|
195
|
+
# * app/views/route/show.[...]
|
154
196
|
#
|
155
|
-
# And test_show_no_photos will look for:
|
197
|
+
# And in test_show_no_photos, render will look for:
|
156
198
|
# * app/views/route/show_no_photos.rhtml
|
157
199
|
# * app/views/route/show_no_photos.rxml
|
158
|
-
# * app/views/route/
|
159
|
-
# * app/views/route/
|
160
|
-
# * app/views/route/
|
161
|
-
# * app/views/route/show.
|
200
|
+
# * app/views/route/show_no_photos.rjs
|
201
|
+
# * app/views/route/show_no_photos.mab
|
202
|
+
# * app/views/route/show_no.[...]
|
203
|
+
# * app/views/route/show.[...]
|
162
204
|
#
|
163
205
|
# If a view cannot be found the test will flunk.
|
164
206
|
|
@@ -166,11 +208,15 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
166
208
|
@action_name = action_name caller[0] if options.empty?
|
167
209
|
assigns[:action_name] = @action_name
|
168
210
|
|
169
|
-
|
211
|
+
default_path_parameters = {
|
170
212
|
:controller => @controller.controller_name,
|
171
|
-
:action => @action_name
|
213
|
+
:action => @action_name
|
172
214
|
}
|
173
215
|
|
216
|
+
path_parameters = default_path_parameters.merge(@path_parameters)
|
217
|
+
|
218
|
+
@request.path_parameters = path_parameters
|
219
|
+
|
174
220
|
defaults = { :layout => false }
|
175
221
|
options = defaults.merge options
|
176
222
|
|
@@ -203,16 +249,12 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
203
249
|
|
204
250
|
def assert_error_on(field, type)
|
205
251
|
error_message = ActiveRecord::Errors.default_error_messages[type]
|
206
|
-
|
207
|
-
:
|
208
|
-
:tag => 'li',
|
209
|
-
:content => /^#{field} #{error_message}/i }
|
252
|
+
assert_select "div.errorExplanation li",
|
253
|
+
:text => /^#{field} #{error_message}/i
|
210
254
|
end
|
211
255
|
|
212
256
|
##
|
213
|
-
#
|
214
|
-
# a name of "+model+[+column+]" and has a label with a for attribute of
|
215
|
-
# "+model+_+column+".
|
257
|
+
# A wrapper assert that calls both assert_input and assert_label.
|
216
258
|
#
|
217
259
|
# view:
|
218
260
|
# <%= start_form_tag :controller => 'game', :action => 'save' %>
|
@@ -222,13 +264,46 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
222
264
|
# test:
|
223
265
|
# assert_field '/game/save', :text, :game, :amount
|
224
266
|
|
225
|
-
def assert_field(
|
226
|
-
|
227
|
-
|
267
|
+
def assert_field(*args)
|
268
|
+
form_action, type, model, column, value =
|
269
|
+
Symbol === args.first ? [nil, *args] : args
|
270
|
+
|
271
|
+
if form_action then # HACK deprecate
|
272
|
+
assert_input form_action, type, "#{model}[#{column}]", value
|
273
|
+
assert_label form_action, "#{model}_#{column}"
|
274
|
+
else
|
275
|
+
assert_input type, "#{model}[#{column}]", value
|
276
|
+
assert_label "#{model}_#{column}"
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
##
|
281
|
+
# Asserts that there is a form whose action is +form_action+. Optionally,
|
282
|
+
# +method+ and +enctype+ may be specified. If a block is given, assert_form
|
283
|
+
# behaves like assert_select, so assert_input and friends may be scoped to
|
284
|
+
# the selected form.
|
285
|
+
#
|
286
|
+
# view:
|
287
|
+
# <%= start_form_tag :action => 'create_file' %>
|
288
|
+
# # ...
|
289
|
+
#
|
290
|
+
# test:
|
291
|
+
# assert_form '/game/save'
|
292
|
+
#
|
293
|
+
# or:
|
294
|
+
# assert_form '/game/save' do
|
295
|
+
# # ...
|
296
|
+
# end
|
297
|
+
|
298
|
+
def assert_form(form_action, method = nil, enctype = nil, &block)
|
299
|
+
selector = "form[action='#{form_action}']"
|
300
|
+
selector << "[method='#{method}']" if method
|
301
|
+
selector << "[enctype='#{enctype}']" if enctype
|
302
|
+
assert_select selector, &block
|
228
303
|
end
|
229
304
|
|
230
305
|
##
|
231
|
-
# Asserts a
|
306
|
+
# Asserts a hN tag of level +level+ exists and contains +content+.
|
232
307
|
#
|
233
308
|
# view:
|
234
309
|
# <h3>Recent Builds</h3>
|
@@ -237,7 +312,7 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
237
312
|
# assert_h 3, 'Recent Builds'
|
238
313
|
|
239
314
|
def assert_h(level, content)
|
240
|
-
|
315
|
+
assert_select "h#{level}", :text => content
|
241
316
|
end
|
242
317
|
|
243
318
|
##
|
@@ -250,45 +325,52 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
250
325
|
# assert_image '/images/bucket.jpg'
|
251
326
|
|
252
327
|
def assert_image(src)
|
253
|
-
|
328
|
+
assert_select "img[src='#{src}']"
|
254
329
|
end
|
255
330
|
|
256
331
|
##
|
257
|
-
# Asserts that
|
258
|
-
# a
|
332
|
+
# Asserts that an input element of +type+ with a name of +name+, and
|
333
|
+
# optionally a value of +value+ exists.
|
259
334
|
#
|
260
335
|
# view:
|
261
|
-
# <%= start_form_tag :controller => 'game', :action => 'save' %>
|
262
336
|
# <%= text_field 'game', 'amount' %>
|
263
337
|
#
|
264
338
|
# test:
|
265
|
-
# assert_input
|
339
|
+
# assert_input :text, "game[amount]"
|
340
|
+
|
341
|
+
def assert_input(*args)
|
342
|
+
action, type, name, value = Symbol === args.first ? [nil, *args] : args
|
343
|
+
|
344
|
+
raise ArgumentError, 'supply type and name' if type.nil? or name.nil?
|
266
345
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
346
|
+
input_selector = "input[type='#{type}'][name='#{name}']"
|
347
|
+
input_selector << "[value='#{value}']" if value
|
348
|
+
|
349
|
+
assert_select_in_form action do assert_select input_selector end
|
271
350
|
end
|
272
351
|
|
273
352
|
##
|
274
|
-
# Asserts that a
|
275
|
-
# "+model+_+column+".
|
353
|
+
# Asserts that a label with a for attribute of +for_attribute+ exists.
|
276
354
|
#
|
277
355
|
# view:
|
278
356
|
# <%= start_form_tag :controller => 'game', :action => 'save' %>
|
279
357
|
# <label for="game_amount">Amount:</label>
|
280
358
|
#
|
281
359
|
# test:
|
282
|
-
# assert_label '
|
360
|
+
# assert_label 'game_amount'
|
361
|
+
|
362
|
+
def assert_label(*args)
|
363
|
+
action, for_attribute = args.length == 1 ? [nil, *args] : args
|
283
364
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
365
|
+
raise ArgumentError, 'supply for_attribute' if for_attribute.nil?
|
366
|
+
|
367
|
+
label_selector = "label[for='#{for_attribute}']"
|
368
|
+
|
369
|
+
assert_select_in_form action do assert_select label_selector end
|
288
370
|
end
|
289
371
|
|
290
372
|
##
|
291
|
-
# Asserts that there is an anchor tag with an href of +href+
|
373
|
+
# Asserts that there is an anchor tag with an href of +href+ that optionally
|
292
374
|
# has +content+.
|
293
375
|
#
|
294
376
|
# view:
|
@@ -298,7 +380,7 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
298
380
|
# assert_links_to '/players/show/1', 'drbrain'
|
299
381
|
|
300
382
|
def assert_links_to(href, content = nil)
|
301
|
-
|
383
|
+
assert_select(*links_to_options_for(href, content))
|
302
384
|
end
|
303
385
|
|
304
386
|
##
|
@@ -312,12 +394,16 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
312
394
|
# deny_links_to '/players/show/1'
|
313
395
|
|
314
396
|
def deny_links_to(href, content = nil)
|
315
|
-
|
397
|
+
selector, options = links_to_options_for(href, content)
|
398
|
+
options[:count] = 0
|
399
|
+
|
400
|
+
assert_select selector, options
|
316
401
|
end
|
317
402
|
|
318
403
|
##
|
319
404
|
# Asserts that there is a form using the 'POST' method whose action is
|
320
|
-
# +form_action+ and uses the multipart content type.
|
405
|
+
# +form_action+ and uses the multipart content type. If passed a block,
|
406
|
+
# works like assert_form.
|
321
407
|
#
|
322
408
|
# view:
|
323
409
|
# <%= start_form_tag({ :action => 'create_file' }, :multipart => true) %>
|
@@ -325,14 +411,13 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
325
411
|
# test:
|
326
412
|
# assert_multipart_form '/game/save'
|
327
413
|
|
328
|
-
def assert_multipart_form(form_action)
|
329
|
-
|
330
|
-
:method => 'post', :enctype => 'multipart/form-data' }
|
414
|
+
def assert_multipart_form(form_action, &block)
|
415
|
+
assert_form(form_action, :post, 'multipart/form-data', &block)
|
331
416
|
end
|
332
417
|
|
333
418
|
##
|
334
419
|
# Asserts that there is a form using the 'POST' method whose action is
|
335
|
-
# +form_action+.
|
420
|
+
# +form_action+. If passed a block, works like assert_form.
|
336
421
|
#
|
337
422
|
# view:
|
338
423
|
# <%= start_form_tag :action => 'create_file' %>
|
@@ -340,57 +425,58 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
340
425
|
# test:
|
341
426
|
# assert_post_form '/game/save'
|
342
427
|
|
343
|
-
def assert_post_form(form_action)
|
344
|
-
|
345
|
-
:method => 'post' }
|
428
|
+
def assert_post_form(form_action, &block)
|
429
|
+
assert_form(form_action, :post, &block)
|
346
430
|
end
|
347
431
|
|
348
432
|
##
|
349
|
-
# Asserts that a
|
350
|
-
#
|
433
|
+
# Asserts that a select element with a name of "+model+[+column+]" and
|
434
|
+
# +options+ with specified names and values exists.
|
351
435
|
#
|
352
436
|
# view:
|
353
|
-
# <%= start_form_tag :action => 'save' %>
|
354
437
|
# <%= collection_select :game, :location_id, @locations, :id, :name %>
|
355
438
|
#
|
356
439
|
# test:
|
357
|
-
# assert_select_tag
|
358
|
-
|
440
|
+
# assert_select_tag :game, :location_id, 'Ballet' => 1, 'Guaymas' => 2
|
441
|
+
|
442
|
+
def assert_select_tag(*args)
|
443
|
+
action, model, column, options = Symbol === args.first ? [nil, *args] : args
|
359
444
|
|
360
|
-
def assert_select_tag(form_action, model, column, options)
|
361
445
|
assert_kind_of Hash, options, "options needs to be a Hash"
|
362
446
|
deny options.empty?, "options must not be empty"
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
447
|
+
|
448
|
+
select_selector = "select[name='#{model}[#{column}]']"
|
449
|
+
|
450
|
+
options.each do |option_name, option_value|
|
451
|
+
option_selector = "option[value='#{option_value}']"
|
452
|
+
selector = "#{select_selector} #{option_selector}"
|
453
|
+
|
454
|
+
assert_select_in_form action do
|
455
|
+
assert_select selector, :text => option_name
|
456
|
+
end
|
372
457
|
end
|
373
458
|
end
|
374
459
|
|
375
460
|
##
|
376
|
-
# Asserts that a
|
377
|
-
# of +value+.
|
461
|
+
# Asserts that a submit element with a value of +value+ exists.
|
378
462
|
#
|
379
463
|
# view:
|
380
|
-
# <%= start_form_tag :action => 'save' %>
|
381
464
|
# <input type="submit" value="Create!" %>
|
382
465
|
#
|
383
466
|
# test:
|
384
|
-
# assert_submit '
|
467
|
+
# assert_submit 'Create!'
|
468
|
+
|
469
|
+
def assert_submit(*args)
|
470
|
+
action, value = args.length == 1 ? [nil, *args] : args
|
385
471
|
|
386
|
-
|
387
|
-
|
388
|
-
|
472
|
+
submit_selector = "input[type='submit'][value='#{value}']"
|
473
|
+
|
474
|
+
assert_select_in_form action do assert_select submit_selector end
|
389
475
|
end
|
390
476
|
|
391
477
|
##
|
392
478
|
# Asserts that a form with +form_action+ has a descendent that matches
|
393
|
-
# +options
|
479
|
+
# +options+ exists.
|
394
480
|
#
|
395
481
|
# Typically this is not used directly in tests. Instead use it to build
|
396
482
|
# expressive tests that assert which fields are in what form.
|
@@ -408,14 +494,13 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
408
494
|
end
|
409
495
|
|
410
496
|
##
|
411
|
-
# Asserts that a
|
412
|
-
# optionally +value?.
|
497
|
+
# Asserts that a textarea with name +name+ and optionally +value+ exists.
|
413
498
|
#
|
414
499
|
# view:
|
415
500
|
# <%= text_area 'post', 'body' %>
|
416
501
|
#
|
417
502
|
# test:
|
418
|
-
# assert_text_area '
|
503
|
+
# assert_text_area 'post[body]'
|
419
504
|
#
|
420
505
|
# view:
|
421
506
|
# <textarea id="post_body" name="post[body]">
|
@@ -423,17 +508,21 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
423
508
|
# </textarea>
|
424
509
|
#
|
425
510
|
# test:
|
426
|
-
# assert_text_area '
|
511
|
+
# assert_text_area 'post[body]', posts(:post).body
|
427
512
|
|
428
|
-
def assert_text_area(
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
513
|
+
def assert_text_area(*args)
|
514
|
+
action, name, value = args.first !~ /\A\// ? [nil, *args] : args
|
515
|
+
|
516
|
+
raise ArgumentError, 'supply name' if name.nil?
|
517
|
+
|
518
|
+
text_area_selector = ["textarea[name='#{name}']"]
|
519
|
+
text_area_selector << { :text => value } if value
|
520
|
+
|
521
|
+
assert_select_in_form action do assert_select(*text_area_selector) end
|
435
522
|
end
|
436
523
|
|
524
|
+
alias assert_textarea assert_text_area
|
525
|
+
|
437
526
|
##
|
438
527
|
# Asserts that a title with +title+ exists.
|
439
528
|
#
|
@@ -442,11 +531,18 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
442
531
|
#
|
443
532
|
# test:
|
444
533
|
# assert_title 'some content'
|
445
|
-
|
534
|
+
|
446
535
|
def assert_title(title)
|
447
|
-
|
536
|
+
assert_select 'title', :text => title
|
537
|
+
end
|
538
|
+
|
539
|
+
##
|
540
|
+
# Opposite of assert_select.
|
541
|
+
|
542
|
+
def deny_select(selector)
|
543
|
+
assert_select selector, false
|
448
544
|
end
|
449
|
-
|
545
|
+
|
450
546
|
##
|
451
547
|
# Creates a new Paginator that uses the current controller. +item_count+,
|
452
548
|
# +items_per_page+ and +page_number+ are passed straight through.
|
@@ -456,19 +552,27 @@ class Test::Rails::ViewTestCase < Test::Rails::FunctionalTestCase
|
|
456
552
|
items_per_page, page_number)
|
457
553
|
end
|
458
554
|
|
459
|
-
|
555
|
+
##
|
556
|
+
# Utility method for compatibility with old-style assert_tag form
|
557
|
+
# assertions.
|
558
|
+
|
559
|
+
def assert_select_in_form(action, &block) # :nodoc:
|
560
|
+
if action then
|
561
|
+
assert_form(action, &block)
|
562
|
+
else
|
563
|
+
block.call
|
564
|
+
end
|
565
|
+
end
|
460
566
|
|
461
567
|
##
|
462
568
|
# Creates an assertion options hash for +href+ and +content+.
|
463
569
|
|
464
570
|
def links_to_options_for(href, content = nil)
|
465
|
-
|
466
|
-
|
467
|
-
return
|
571
|
+
selector = "a[href='#{href}']"
|
572
|
+
equality = content ? { :text => content } : {}
|
573
|
+
return selector, equality
|
468
574
|
end
|
469
575
|
|
470
|
-
private
|
471
|
-
|
472
576
|
##
|
473
577
|
# Returns the action_name based on a backtrace line passed in as +test+.
|
474
578
|
|
data/lib/zentest.rb
CHANGED
@@ -3,59 +3,267 @@ require 'test/zentest_assertions'
|
|
3
3
|
|
4
4
|
$TESTING_RTC = true
|
5
5
|
|
6
|
+
module Rails
|
7
|
+
module VERSION
|
8
|
+
STRING = '99.99.99'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
6
12
|
begin
|
7
13
|
require 'test/rails'
|
8
14
|
rescue LoadError, NameError
|
9
15
|
$TESTING_RTC = false
|
10
16
|
end
|
11
17
|
|
12
|
-
class View; end
|
13
|
-
|
14
18
|
class TestRailsViewTestCase < Test::Rails::ViewTestCase
|
15
19
|
|
16
20
|
def setup
|
17
|
-
# override
|
18
|
-
@request = Object.new
|
19
|
-
def @request.body; @body; end
|
20
|
-
def @request.body=(body); @body = body; end
|
21
|
-
|
22
21
|
@assert_tag = []
|
22
|
+
@assert_no_tag = []
|
23
|
+
|
24
|
+
@assert_select = []
|
23
25
|
end
|
24
26
|
|
25
|
-
def
|
26
|
-
|
27
|
-
<form action="/post/save">
|
28
|
-
<textarea id="post_body" name="post[body]">
|
29
|
-
OMG he like hates me and he\'s like going out with this total skank!~ oh noes!!~
|
30
|
-
</textarea>
|
31
|
-
</form>
|
32
|
-
'
|
27
|
+
def test_assert_field
|
28
|
+
assert_field :text, :game, :amount
|
33
29
|
|
34
|
-
|
30
|
+
assert_equal 2, @assert_select.length
|
31
|
+
|
32
|
+
expected = ["input[type='text'][name='game[amount]']"]
|
33
|
+
|
34
|
+
assert_equal expected, @assert_select.first
|
35
|
+
|
36
|
+
expected = ["label[for='game_amount']"]
|
37
|
+
|
38
|
+
assert_equal expected, @assert_select.last
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_assert_field_form
|
42
|
+
assert_field '/game/save', :text, :game, :amount
|
43
|
+
|
44
|
+
assert_equal 4, @assert_select.length
|
45
|
+
|
46
|
+
assert_equal ["form[action='/game/save']"], @assert_select.shift
|
47
|
+
assert_equal ["input[type='text'][name='game[amount]']"],
|
48
|
+
@assert_select.shift
|
49
|
+
|
50
|
+
assert_equal ["form[action='/game/save']"], @assert_select.shift
|
51
|
+
assert_equal ["label[for='game_amount']"], @assert_select.shift
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_assert_form
|
55
|
+
assert_form '/game/save'
|
56
|
+
|
57
|
+
assert_equal 1, @assert_select.length
|
58
|
+
assert_equal ["form[action='/game/save']"], @assert_select.first
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_assert_form_method
|
62
|
+
assert_form '/game/save', :post
|
63
|
+
|
64
|
+
assert_equal 1, @assert_select.length
|
65
|
+
assert_equal ["form[action='/game/save'][method='post']"],
|
66
|
+
@assert_select.first
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_assert_form_enctype
|
70
|
+
assert_form '/game/save', nil, 'multipart/form-data'
|
71
|
+
|
72
|
+
assert_equal 1, @assert_select.length
|
73
|
+
assert_equal ["form[action='/game/save'][enctype='multipart/form-data']"],
|
74
|
+
@assert_select.first
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_assert_h
|
78
|
+
assert_h 1, 'hi'
|
79
|
+
|
80
|
+
assert_equal [['h1', { :text => 'hi' }]], @assert_select
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_assert_img
|
84
|
+
assert_image '/images/bucket.jpg'
|
85
|
+
|
86
|
+
assert_equal [["img[src='/images/bucket.jpg']"]], @assert_select
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_assert_input
|
90
|
+
assert_input :text, 'game[amount]'
|
91
|
+
|
92
|
+
assert_equal 1, @assert_select.length
|
93
|
+
assert_equal ["input[type='text'][name='game[amount]']"],
|
94
|
+
@assert_select.first
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_assert_input_form
|
98
|
+
assert_input '/game/save', :text, 'game[amount]'
|
99
|
+
|
100
|
+
assert_equal 2, @assert_select.length
|
101
|
+
assert_equal ["form[action='/game/save']"], @assert_select.shift
|
102
|
+
assert_equal ["input[type='text'][name='game[amount]']"],
|
103
|
+
@assert_select.shift
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_assert_input_value
|
107
|
+
assert_input :text, 'game[amount]', 5
|
108
|
+
|
109
|
+
expected = ["input[type='text'][name='game[amount]'][value='5']"]
|
110
|
+
|
111
|
+
assert_equal 1, @assert_select.length
|
112
|
+
assert_equal expected, @assert_select.first
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_assert_label
|
116
|
+
assert_label 'game_amount'
|
117
|
+
|
118
|
+
expected = ["label[for='game_amount']"]
|
119
|
+
|
120
|
+
assert_equal 1, @assert_select.length
|
121
|
+
assert_equal expected, @assert_select.first
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_assert_label_form
|
125
|
+
assert_label '/game/save', 'game_amount'
|
126
|
+
|
127
|
+
assert_equal 2, @assert_select.length
|
128
|
+
assert_equal ["form[action='/game/save']"], @assert_select.shift
|
129
|
+
assert_equal ["label[for='game_amount']"], @assert_select.shift
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_assert_links_to
|
133
|
+
assert_links_to '/game/show/1', 'hi'
|
134
|
+
|
135
|
+
expected = ["a[href='/game/show/1']", { :text => 'hi' }]
|
136
|
+
|
137
|
+
|
138
|
+
assert_equal 1, @assert_select.length
|
139
|
+
assert_equal expected, @assert_select.first
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_assert_multipart_form
|
143
|
+
assert_multipart_form '/game/save'
|
144
|
+
|
145
|
+
expected = [
|
146
|
+
"form[action='/game/save'][method='post'][enctype='multipart/form-data']"
|
147
|
+
]
|
148
|
+
|
149
|
+
assert_equal 1, @assert_select.length
|
150
|
+
assert_equal expected, @assert_select.first
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_assert_post_form
|
154
|
+
assert_post_form '/game/save'
|
155
|
+
|
156
|
+
expected = ["form[action='/game/save'][method='post']"]
|
157
|
+
|
158
|
+
assert_equal 1, @assert_select.length
|
159
|
+
assert_equal expected, @assert_select.first
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_assert_select_tag
|
163
|
+
assert_select_tag :game, :location_id,
|
164
|
+
'Ballet' => 1, 'Guaymas' => 2
|
165
|
+
|
166
|
+
assert_equal 2, @assert_select.length
|
167
|
+
|
168
|
+
assert_equal ["select[name='game[location_id]'] option[value='2']",
|
169
|
+
{ :text => 'Guaymas' }], @assert_select.shift
|
170
|
+
assert_equal ["select[name='game[location_id]'] option[value='1']",
|
171
|
+
{ :text => 'Ballet' }], @assert_select.shift
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_assert_select_tag_form
|
175
|
+
assert_select_tag '/game/save', :game, :location_id,
|
176
|
+
'Ballet' => 1, 'Guaymas' => 2
|
177
|
+
|
178
|
+
assert_equal 4, @assert_select.length
|
179
|
+
|
180
|
+
assert_equal ["form[action='/game/save']"], @assert_select.shift
|
181
|
+
assert_equal ["select[name='game[location_id]'] option[value='2']",
|
182
|
+
{ :text => 'Guaymas' }], @assert_select.shift
|
183
|
+
assert_equal ["form[action='/game/save']"], @assert_select.shift
|
184
|
+
assert_equal ["select[name='game[location_id]'] option[value='1']",
|
185
|
+
{ :text => 'Ballet' }], @assert_select.shift
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_assert_submit
|
189
|
+
assert_submit 'Save!'
|
190
|
+
|
191
|
+
assert_equal 1, @assert_select.length
|
192
|
+
assert_equal ["input[type='submit'][value='Save!']"], @assert_select.first
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_assert_submit_form
|
196
|
+
assert_submit '/game/save', 'Save!'
|
197
|
+
|
198
|
+
assert_equal 2, @assert_select.length
|
199
|
+
assert_equal ["form[action='/game/save']"], @assert_select.shift
|
200
|
+
assert_equal ["input[type='submit'][value='Save!']"], @assert_select.shift
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_assert_tag_in_form
|
204
|
+
assert_tag_in_form '/game/save', :tag => 'input'
|
35
205
|
|
36
206
|
expected = {
|
37
|
-
:tag =>
|
38
|
-
|
39
|
-
|
207
|
+
:tag => "form",
|
208
|
+
:attributes => { :action => "/game/save" },
|
209
|
+
:descendant => { :tag => "input" },
|
210
|
+
}
|
40
211
|
|
212
|
+
assert_equal 1, @assert_tag.length
|
41
213
|
assert_equal expected, @assert_tag.first
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_assert_text_area
|
217
|
+
assert_text_area 'post[body]'
|
42
218
|
|
43
|
-
|
44
|
-
|
219
|
+
assert_equal 1, @assert_select.length
|
220
|
+
assert_equal ["textarea[name='post[body]']"], @assert_select.shift
|
221
|
+
end
|
45
222
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
223
|
+
def test_assert_text_area_body
|
224
|
+
assert_text_area 'post[body]', 'OMG!1! that skank stole my BF!~1!'
|
225
|
+
|
226
|
+
assert_equal 1, @assert_select.length
|
227
|
+
assert_equal ["textarea[name='post[body]']",
|
228
|
+
{ :text => 'OMG!1! that skank stole my BF!~1!' }],
|
229
|
+
@assert_select.shift
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_assert_text_area_form
|
233
|
+
assert_text_area '/post/save', 'post[body]'
|
234
|
+
|
235
|
+
assert_equal 2, @assert_select.length
|
236
|
+
assert_equal ["form[action='/post/save']"], @assert_select.shift
|
237
|
+
assert_equal ["textarea[name='post[body]']"], @assert_select.shift
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_assert_title
|
241
|
+
assert_title 'hi'
|
242
|
+
|
243
|
+
assert_equal [['title', { :text => 'hi' }]], @assert_select
|
244
|
+
end
|
52
245
|
|
53
|
-
|
246
|
+
def test_deny_links_to
|
247
|
+
deny_links_to '/game/show/1', 'hi'
|
248
|
+
|
249
|
+
expected = ["a[href='/game/show/1']", { :text => 'hi', :count => 0 }]
|
250
|
+
|
251
|
+
assert_equal 1, @assert_select.length
|
252
|
+
assert_equal expected, @assert_select.first
|
54
253
|
end
|
55
254
|
|
56
255
|
def assert_tag(arg)
|
57
256
|
@assert_tag << arg
|
58
257
|
end
|
59
258
|
|
259
|
+
def assert_no_tag(arg)
|
260
|
+
@assert_no_tag << arg
|
261
|
+
end
|
262
|
+
|
263
|
+
def assert_select(*args)
|
264
|
+
@assert_select << args
|
265
|
+
yield if block_given?
|
266
|
+
end
|
267
|
+
|
60
268
|
end if $TESTING_RTC
|
61
269
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ZenTest
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 3.6.
|
7
|
-
date: 2007-
|
6
|
+
version: 3.6.1
|
7
|
+
date: 2007-07-23 00:00:00 -07:00
|
8
8
|
summary: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails."
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -134,5 +134,5 @@ dependencies:
|
|
134
134
|
requirements:
|
135
135
|
- - ">="
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: 1.2.
|
137
|
+
version: 1.2.2
|
138
138
|
version:
|