minitest-rails 0.9.2 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +14 -16
  3. data/Gemfile +7 -0
  4. data/Manifest.txt +12 -9
  5. data/README.rdoc +13 -1
  6. data/Rakefile +6 -5
  7. data/gemfiles/3.0.gemfile +2 -5
  8. data/gemfiles/3.1.gemfile +2 -5
  9. data/gemfiles/3.2.gemfile +2 -5
  10. data/gemfiles/4.0.gemfile +2 -6
  11. data/lib/generators/.document +0 -0
  12. data/lib/generators/mini_test/controller/templates/controller_spec.rb +3 -3
  13. data/lib/generators/mini_test/controller/templates/controller_test.rb +4 -4
  14. data/lib/generators/mini_test/helper/templates/helper_test.rb +1 -1
  15. data/lib/generators/mini_test/install/install_generator.rb +5 -0
  16. data/lib/generators/mini_test/install/templates/test_helper.rb +9 -0
  17. data/lib/generators/mini_test/integration/templates/integration_spec.rb +3 -3
  18. data/lib/generators/mini_test/integration/templates/integration_test.rb +3 -3
  19. data/lib/generators/mini_test/mailer/mailer_generator.rb +2 -2
  20. data/lib/generators/mini_test/mailer/templates/mailer_test.rb +4 -4
  21. data/lib/generators/mini_test/model/model_generator.rb +3 -3
  22. data/lib/generators/mini_test/model/templates/model_spec.rb +2 -4
  23. data/lib/generators/mini_test/model/templates/model_test.rb +9 -3
  24. data/lib/generators/mini_test/route/templates/route_spec.rb +1 -1
  25. data/lib/generators/mini_test/route/templates/route_test.rb +1 -1
  26. data/lib/generators/mini_test/scaffold/templates/controller_spec.rb +12 -14
  27. data/lib/generators/mini_test/scaffold/templates/controller_test.rb +6 -6
  28. data/lib/minitest/rails/assertions.rb +1811 -0
  29. data/lib/minitest/rails/expectations.rb +659 -0
  30. data/lib/minitest/rails/generators.rb +18 -0
  31. data/lib/minitest/rails/railtie.rb +1 -1
  32. data/lib/minitest/rails/tasks/.document +0 -0
  33. data/lib/minitest/rails/tasks/minitest.rake +44 -13
  34. data/lib/minitest/rails/testing.rb +10 -20
  35. data/lib/minitest/rails/version.rb +1 -1
  36. data/lib/minitest/rails.rb +22 -3
  37. data/minitest-rails.gemspec +21 -16
  38. data/tasks/test.rake +27 -15
  39. data/test/generators/test_install_generator.rb +17 -0
  40. data/test/generators/test_mailer_generator.rb +19 -0
  41. data/test/generators/test_model_generator.rb +25 -1
  42. data/test/helper.rb +27 -0
  43. data/test/rails/action_controller/test_assertions.rb +46 -0
  44. data/test/rails/action_controller/test_controllers.rb +2 -13
  45. data/test/rails/action_controller/test_expectations.rb +45 -0
  46. data/test/rails/active_support/test_assertions.rb +59 -0
  47. data/test/rails/active_support/test_expectations.rb +49 -0
  48. data/test/rails/generators/test_spec_type.rb +36 -0
  49. data/test/rails/minitest_5_api_test.rb +8 -0
  50. metadata +66 -54
  51. data/gemfiles/3.0.gemfile.lock +0 -91
  52. data/gemfiles/3.1.gemfile.lock +0 -102
  53. data/gemfiles/3.2.gemfile.lock +0 -101
  54. data/gemfiles/4.0.gemfile.lock +0 -99
  55. data/lib/autotest/discover.rb +0 -5
  56. data/lib/autotest/fixtures.rb +0 -7
  57. data/lib/autotest/migrate.rb +0 -5
  58. data/lib/autotest/minitest_rails.rb +0 -63
  59. data/tasks/gemfiles.rake +0 -24
@@ -0,0 +1,1811 @@
1
+ class ActiveSupport::TestCase
2
+ ##
3
+ # Checks if an expression is blank. Passes if actual.blank? is true.
4
+ #
5
+ # === This assertion is deprecated.
6
+ #
7
+ # Use the following to check for <tt>blank?</tt> instead:
8
+ #
9
+ # assert actual.blank?
10
+ #
11
+ # The deprecated assertion can be called like this:
12
+ #
13
+ # assert_blank []
14
+ #
15
+ # See also MiniTest::Rails::Expectations#must_be_blank
16
+ #
17
+ # :method: assert_blank
18
+ # :call-seq: assert_blank(actual, message = nil)
19
+
20
+ ##
21
+ # Checks if an expression is not present. Passes if actual.present? is false.
22
+ #
23
+ # === This assertion is deprecated.
24
+ #
25
+ # Use the following to check for <tt>present?</tt> instead:
26
+ #
27
+ # refute actual.present?
28
+ #
29
+ # The deprecated assertion can be called like this:
30
+ #
31
+ # refute_present nil
32
+ #
33
+ # See also MiniTest::Rails::Expectations#wont_be_present
34
+ #
35
+ # :args: actual, message = nil
36
+ alias :refute_present :assert_blank
37
+
38
+ ##
39
+ # Checks if an expression is present. Passes if actual.present? is true.
40
+ #
41
+ # === This assertion is deprecated.
42
+ #
43
+ # Use the following to check for <tt>present?</tt> instead:
44
+ #
45
+ # assert actual.present?
46
+ #
47
+ # The deprecated assertion can be called like this:
48
+ #
49
+ # assert_present Object.new
50
+ #
51
+ # See also MiniTest::Rails::Expectations#must_be_present
52
+ #
53
+ # :method: assert_present
54
+ # :call-seq: assert_present(actual, message = nil)
55
+
56
+ ##
57
+ # Checks if an expression is not blank. Passes if actual.blank? is false.
58
+ #
59
+ # === This assertion is deprecated.
60
+ #
61
+ # Use the following to check for <tt>blank?</tt> instead:
62
+ #
63
+ # refute actual.blank?
64
+ #
65
+ # The deprecated assertion can be called like this:
66
+ #
67
+ # refute_blank [1,2,3]
68
+ #
69
+ # See also MiniTest::Rails::Expectations#wont_be_blank
70
+ #
71
+ # :args: actual, message = nil
72
+ alias :refute_blank :assert_present
73
+
74
+ ##
75
+ # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
76
+ #
77
+ # assert_difference "User.count", +1 do
78
+ # User.create
79
+ # end
80
+ #
81
+ # See also MiniTest::Rails::Expectations#must_change
82
+ #
83
+ # :method: assert_difference
84
+ # :call-seq: assert_difference(expression, difference = 1, message = nil, &block)
85
+
86
+ ##
87
+ # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
88
+ #
89
+ # assert_no_difference "User.count" do
90
+ # User.new
91
+ # end
92
+ #
93
+ # See also MiniTest::Rails::Expectations#wont_change
94
+ #
95
+ # :method: assert_no_difference
96
+ # :call-seq: assert_no_difference(expression, message = nil, &block)
97
+
98
+ ##
99
+ # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
100
+ #
101
+ # refute_difference "User.count", do
102
+ # User.new
103
+ # end
104
+ #
105
+ # See also MiniTest::Rails::Expectations#wont_change
106
+ #
107
+ # :args: expression, message = nil, &block
108
+ alias :refute_difference :assert_no_difference
109
+
110
+ end
111
+
112
+ class ActionController::TestCase
113
+ # Asserts that the response is one of the following types:
114
+ #
115
+ # * <tt>:success</tt> - Status code was in the 200-299 range
116
+ # * <tt>:redirect</tt> - Status code was in the 300-399 range
117
+ # * <tt>:missing</tt> - Status code was 404
118
+ # * <tt>:error</tt> - Status code was in the 500-599 range
119
+ #
120
+ # You can also pass an explicit status number like <tt>assert_response(501)</tt>
121
+ # or its symbolic equivalent <tt>assert_response(:not_implemented)</tt>.
122
+ # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list.
123
+ #
124
+ # # assert that the response was a redirection
125
+ # assert_response :redirect
126
+ #
127
+ # # assert that the response code was status code 401 (unauthorized)
128
+ # assert_response 401
129
+ #
130
+ # See also MiniTest::Rails::Expectations#must_respond_with
131
+ #
132
+ # :method: assert_response
133
+ # :call-seq: assert_response(type, message = nil)
134
+
135
+ ##
136
+ # Assert that the redirection options passed in match those of the redirect called in the latest action.
137
+ # This match can be partial, such that <tt>assert_redirected_to(controller: "weblog")</tt> will also
138
+ # match the redirection of <tt>redirect_to(controller: "weblog", action: "show")</tt> and so on.
139
+ #
140
+ # # assert that the redirection was to the "index" action on the WeblogController
141
+ # assert_redirected_to controller: "weblog", action: "index"
142
+ #
143
+ # # assert that the redirection was to the named route login_url
144
+ # assert_redirected_to login_url
145
+ #
146
+ # # assert that the redirection was to the url for @customer
147
+ # assert_redirected_to @customer
148
+ #
149
+ # # asserts that the redirection matches the regular expression
150
+ # assert_redirected_to %r(\Ahttp://example.org)
151
+ #
152
+ # See also MiniTest::Rails::Expectations#must_redirect_to
153
+ #
154
+ # :method: assert_redirected_to
155
+ # :call-seq: assert_redirected_to(options = {}, message=nil)
156
+
157
+ ##
158
+ # Asserts that the request was rendered with the appropriate template file or partials.
159
+ #
160
+ # # assert that the "new" view template was rendered
161
+ # assert_template "new"
162
+ #
163
+ # # assert that the exact template "admin/posts/new" was rendered
164
+ # assert_template %r{\Aadmin/posts/new\Z}
165
+ #
166
+ # # assert that the layout 'admin' was rendered
167
+ # assert_template layout: 'admin'
168
+ # assert_template layout: 'layouts/admin'
169
+ # assert_template layout: :admin
170
+ #
171
+ # # assert that no layout was rendered
172
+ # assert_template layout: nil
173
+ # assert_template layout: false
174
+ #
175
+ # # assert that the "_customer" partial was rendered twice
176
+ # assert_template partial: '_customer', count: 2
177
+ #
178
+ # # assert that no partials were rendered
179
+ # assert_template partial: false
180
+ #
181
+ # In a view test case, you can also assert that specific locals are passed
182
+ # to partials:
183
+ #
184
+ # # assert that the "_customer" partial was rendered with a specific object
185
+ # assert_template partial: '_customer', locals: { customer: @customer }
186
+ #
187
+ # See also MiniTest::Rails::Expectations#must_render_template
188
+ #
189
+ # :method: assert_template
190
+ # :call-seq: assert_template(options = {}, message = nil)
191
+
192
+ ##
193
+ # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
194
+ # The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
195
+ # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
196
+ #
197
+ # The +defaults+ parameter is unused.
198
+ #
199
+ # # Asserts that the default action is generated for a route with no action
200
+ # assert_generates "/items", controller: "items", action: "index"
201
+ #
202
+ # # Tests that the list action is properly routed
203
+ # assert_generates "/items/list", controller: "items", action: "list"
204
+ #
205
+ # # Tests the generation of a route with a parameter
206
+ # assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
207
+ #
208
+ # # Asserts that the generated route gives us our custom route
209
+ # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
210
+ #
211
+ # See also MiniTest::Rails::Expectations#must_route_to
212
+ #
213
+ # :method: assert_generates
214
+ # :call-seq: assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
215
+
216
+ ##
217
+ # Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
218
+ # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
219
+ #
220
+ # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
221
+ # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
222
+ # and a :method containing the required HTTP verb.
223
+ #
224
+ # # assert that POSTing to /items will call the create action on ItemsController
225
+ # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
226
+ #
227
+ # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
228
+ # to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the
229
+ # extras argument, appending the query string on the path directly will not work. For example:
230
+ #
231
+ # # assert that a path of '/items/list/1?view=print' returns the correct options
232
+ # assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
233
+ #
234
+ # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
235
+ #
236
+ # # Check the default route (i.e., the index action)
237
+ # assert_recognizes({controller: 'items', action: 'index'}, 'items')
238
+ #
239
+ # # Test a specific action
240
+ # assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
241
+ #
242
+ # # Test an action with a parameter
243
+ # assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
244
+ #
245
+ # # Test a custom route
246
+ # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
247
+ #
248
+ # See also MiniTest::Rails::Expectations#must_route_from
249
+ #
250
+ # :method: assert_recognizes
251
+ # :call-seq: assert_recognizes(expected_options, path, extras={}, msg=nil)
252
+
253
+ ##
254
+ # Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
255
+ # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
256
+ # and +assert_generates+ into one step.
257
+ #
258
+ # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
259
+ # +message+ parameter allows you to specify a custom error message to display upon failure.
260
+ #
261
+ # # Assert a basic route: a controller with the default action (index)
262
+ # assert_routing '/home', controller: 'home', action: 'index'
263
+ #
264
+ # # Test a route generated with a specific controller, action, and parameter (id)
265
+ # assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
266
+ #
267
+ # # Assert a basic route (controller + default action), with an error message if it fails
268
+ # assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
269
+ #
270
+ # # Tests a route, providing a defaults hash
271
+ # assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
272
+ #
273
+ # # Tests a route with a HTTP method
274
+ # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
275
+ #
276
+ # See also MiniTest::Rails::Expectations#must_route
277
+ #
278
+ # :method: assert_routing
279
+ # :call-seq: assert_routing(path, options, defaults={}, extras={}, message=nil)
280
+
281
+ # An assertion that selects elements and makes one or more equality tests.
282
+ #
283
+ # If the first argument is an element, selects all matching elements
284
+ # starting from (and including) that element and all its children in
285
+ # depth-first order.
286
+ #
287
+ # If no element if specified, calling +assert_select+ selects from the
288
+ # response HTML unless +assert_select+ is called from within an +assert_select+ block.
289
+ #
290
+ # When called with a block +assert_select+ passes an array of selected elements
291
+ # to the block. Calling +assert_select+ from the block, with no element specified,
292
+ # runs the assertion on the complete set of elements selected by the enclosing assertion.
293
+ # Alternatively the array may be iterated through so that +assert_select+ can be called
294
+ # separately for each element.
295
+ #
296
+ #
297
+ # ==== Example
298
+ # If the response contains two ordered lists, each with four list elements then:
299
+ # assert_select "ol" do |elements|
300
+ # elements.each do |element|
301
+ # assert_select element, "li", 4
302
+ # end
303
+ # end
304
+ #
305
+ # will pass, as will:
306
+ # assert_select "ol" do
307
+ # assert_select "li", 8
308
+ # end
309
+ #
310
+ # The selector may be a CSS selector expression (String), an expression
311
+ # with substitution values, or an HTML::Selector object.
312
+ #
313
+ # === Equality Tests
314
+ #
315
+ # The equality test may be one of the following:
316
+ # * <tt>true</tt> - Assertion is true if at least one element selected.
317
+ # * <tt>false</tt> - Assertion is true if no element selected.
318
+ # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
319
+ # one element matches the string or regular expression.
320
+ # * <tt>Integer</tt> - Assertion is true if exactly that number of
321
+ # elements are selected.
322
+ # * <tt>Range</tt> - Assertion is true if the number of selected
323
+ # elements fit the range.
324
+ # If no equality test specified, the assertion is true if at least one
325
+ # element selected.
326
+ #
327
+ # To perform more than one equality tests, use a hash with the following keys:
328
+ # * <tt>:text</tt> - Narrow the selection to elements that have this text
329
+ # value (string or regexp).
330
+ # * <tt>:html</tt> - Narrow the selection to elements that have this HTML
331
+ # content (string or regexp).
332
+ # * <tt>:count</tt> - Assertion is true if the number of selected elements
333
+ # is equal to this value.
334
+ # * <tt>:minimum</tt> - Assertion is true if the number of selected
335
+ # elements is at least this value.
336
+ # * <tt>:maximum</tt> - Assertion is true if the number of selected
337
+ # elements is at most this value.
338
+ #
339
+ # If the method is called with a block, once all equality tests are
340
+ # evaluated the block is called with an array of all matched elements.
341
+ #
342
+ # # At least one form element
343
+ # assert_select "form"
344
+ #
345
+ # # Form element includes four input fields
346
+ # assert_select "form input", 4
347
+ #
348
+ # # Page title is "Welcome"
349
+ # assert_select "title", "Welcome"
350
+ #
351
+ # # Page title is "Welcome" and there is only one title element
352
+ # assert_select "title", {count: 1, text: "Welcome"},
353
+ # "Wrong title or more than one title element"
354
+ #
355
+ # # Page contains no forms
356
+ # assert_select "form", false, "This page must contain no forms"
357
+ #
358
+ # # Test the content and style
359
+ # assert_select "body div.header ul.menu"
360
+ #
361
+ # # Use substitution values
362
+ # assert_select "ol>li#?", /item-\d+/
363
+ #
364
+ # # All input fields in the form have a name
365
+ # assert_select "form input" do
366
+ # assert_select "[name=?]", /.+/ # Not empty
367
+ # end
368
+ #
369
+ # See also MiniTest::Rails::Expectations#must_select
370
+ #
371
+ # :method: assert_select
372
+ # :call-seq: assert_select(*args, &block)
373
+
374
+ # Extracts the body of an email and runs nested assertions on it.
375
+ #
376
+ # You must enable deliveries for this assertion to work, use:
377
+ # ActionMailer::Base.perform_deliveries = true
378
+ #
379
+ # assert_select_email do
380
+ # assert_select "h1", "Email alert"
381
+ # end
382
+ #
383
+ # assert_select_email do
384
+ # items = assert_select "ol>li"
385
+ # items.each do
386
+ # # Work with items here...
387
+ # end
388
+ # end
389
+ #
390
+ # See also MiniTest::Rails::Expectations#must_select_email
391
+ #
392
+ # :method: assert_select_email
393
+ # :call-seq: assert_select_email(&block)
394
+
395
+ # Extracts the content of an element, treats it as encoded HTML and runs
396
+ # nested assertion on it.
397
+ #
398
+ # You typically call this method within another assertion to operate on
399
+ # all currently selected elements. You can also pass an element or array
400
+ # of elements.
401
+ #
402
+ # The content of each element is un-encoded, and wrapped in the root
403
+ # element +encoded+. It then calls the block with all un-encoded elements.
404
+ #
405
+ # # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)
406
+ # assert_select "feed[xmlns='http://www.w3.org/2005/Atom']" do
407
+ # # Select each entry item and then the title item
408
+ # assert_select "entry>title" do
409
+ # # Run assertions on the encoded title elements
410
+ # assert_select_encoded do
411
+ # assert_select "b"
412
+ # end
413
+ # end
414
+ # end
415
+ #
416
+ #
417
+ # # Selects all paragraph tags from within the description of an RSS feed
418
+ # assert_select "rss[version=2.0]" do
419
+ # # Select description element of each feed item.
420
+ # assert_select "channel>item>description" do
421
+ # # Run assertions on the encoded elements.
422
+ # assert_select_encoded do
423
+ # assert_select "p"
424
+ # end
425
+ # end
426
+ # end
427
+ #
428
+ # See also MiniTest::Rails::Expectations#must_select_encoded
429
+ #
430
+ # :method: assert_select_encoded
431
+ # :call-seq: assert_select_encoded(element = nil, &block)
432
+
433
+ ##
434
+ # Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values.
435
+ #
436
+ # assert_dom_equal '<a href="http://www.example.com">Apples</a>',
437
+ # link_to("Apples", "http://www.example.com")
438
+ #
439
+ # See also MiniTest::Rails::Expectations#must_dom_equal
440
+ #
441
+ # :method: assert_dom_equal
442
+ # :call-seq: assert_dom_equal(expected, actual, message = nil)
443
+
444
+ ##
445
+ # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
446
+ #
447
+ # assert_dom_not_equal '<a href="http://www.example.com">Oranges</a>',
448
+ # link_to("Apples", "http://www.example.com")
449
+ #
450
+ # See also MiniTest::Rails::Expectations#wont_dom_equal
451
+ #
452
+ # :method: assert_dom_not_equal
453
+ # :call-seq: assert_dom_not_equal(expected, actual, message = nil)
454
+
455
+ ##
456
+ # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
457
+ #
458
+ # refute_dom_equal '<a href="http://www.example.com">Oranges</a>',
459
+ # link_to("Apples", "http://www.example.com")
460
+ #
461
+ # See also MiniTest::Rails::Expectations#wont_dom_equal
462
+ #
463
+ # :method: assert_dom_equal
464
+ # :call-seq: assert_dom_equal(expected, actual, message = nil)
465
+ alias :refute_dom_equal :assert_dom_not_equal
466
+
467
+ ##
468
+ # Asserts that there is a tag/node/element in the body of the response
469
+ # that meets all of the given conditions. The +conditions+ parameter must
470
+ # be a hash of any of the following keys (all are optional):
471
+ #
472
+ # * <tt>:tag</tt>: the node type must match the corresponding value
473
+ # * <tt>:attributes</tt>: a hash. The node's attributes must match the
474
+ # corresponding values in the hash.
475
+ # * <tt>:parent</tt>: a hash. The node's parent must match the
476
+ # corresponding hash.
477
+ # * <tt>:child</tt>: a hash. At least one of the node's immediate children
478
+ # must meet the criteria described by the hash.
479
+ # * <tt>:ancestor</tt>: a hash. At least one of the node's ancestors must
480
+ # meet the criteria described by the hash.
481
+ # * <tt>:descendant</tt>: a hash. At least one of the node's descendants
482
+ # must meet the criteria described by the hash.
483
+ # * <tt>:sibling</tt>: a hash. At least one of the node's siblings must
484
+ # meet the criteria described by the hash.
485
+ # * <tt>:after</tt>: a hash. The node must be after any sibling meeting
486
+ # the criteria described by the hash, and at least one sibling must match.
487
+ # * <tt>:before</tt>: a hash. The node must be before any sibling meeting
488
+ # the criteria described by the hash, and at least one sibling must match.
489
+ # * <tt>:children</tt>: a hash, for counting children of a node. Accepts
490
+ # the keys:
491
+ # * <tt>:count</tt>: either a number or a range which must equal (or
492
+ # include) the number of children that match.
493
+ # * <tt>:less_than</tt>: the number of matching children must be less
494
+ # than this number.
495
+ # * <tt>:greater_than</tt>: the number of matching children must be
496
+ # greater than this number.
497
+ # * <tt>:only</tt>: another hash consisting of the keys to use
498
+ # to match on the children, and only matching children will be
499
+ # counted.
500
+ # * <tt>:content</tt>: the textual content of the node must match the
501
+ # given value. This will not match HTML tags in the body of a
502
+ # tag--only text.
503
+ #
504
+ # Conditions are matched using the following algorithm:
505
+ #
506
+ # * if the condition is a string, it must be a substring of the value.
507
+ # * if the condition is a regexp, it must match the value.
508
+ # * if the condition is a number, the value must match number.to_s.
509
+ # * if the condition is +true+, the value must not be +nil+.
510
+ # * if the condition is +false+ or +nil+, the value must be +nil+.
511
+ #
512
+ # # Assert that there is a "span" tag
513
+ # assert_tag tag: "span"
514
+ #
515
+ # # Assert that there is a "span" tag with id="x"
516
+ # assert_tag tag: "span", attributes: { id: "x" }
517
+ #
518
+ # # Assert that there is a "span" tag using the short-hand
519
+ # assert_tag :span
520
+ #
521
+ # # Assert that there is a "span" tag with id="x" using the short-hand
522
+ # assert_tag :span, attributes: { id: "x" }
523
+ #
524
+ # # Assert that there is a "span" inside of a "div"
525
+ # assert_tag tag: "span", parent: { tag: "div" }
526
+ #
527
+ # # Assert that there is a "span" somewhere inside a table
528
+ # assert_tag tag: "span", ancestor: { tag: "table" }
529
+ #
530
+ # # Assert that there is a "span" with at least one "em" child
531
+ # assert_tag tag: "span", child: { tag: "em" }
532
+ #
533
+ # # Assert that there is a "span" containing a (possibly nested)
534
+ # # "strong" tag.
535
+ # assert_tag tag: "span", descendant: { tag: "strong" }
536
+ #
537
+ # # Assert that there is a "span" containing between 2 and 4 "em" tags
538
+ # # as immediate children
539
+ # assert_tag tag: "span",
540
+ # children: { count: 2..4, only: { tag: "em" } }
541
+ #
542
+ # # Get funky: assert that there is a "div", with an "ul" ancestor
543
+ # # and an "li" parent (with "class" = "enum"), and containing a
544
+ # # "span" descendant that contains text matching /hello world/
545
+ # assert_tag tag: "div",
546
+ # ancestor: { tag: "ul" },
547
+ # parent: { tag: "li",
548
+ # attributes: { class: "enum" } },
549
+ # descendant: { tag: "span",
550
+ # child: /hello world/ }
551
+ #
552
+ # <b>Please note</b>: +assert_tag+ and +assert_no_tag+ only work
553
+ # with well-formed XHTML. They recognize a few tags as implicitly self-closing
554
+ # (like br and hr and such) but will not work correctly with tags
555
+ # that allow optional closing tags (p, li, td). <em>You must explicitly
556
+ # close all of your tags to use these assertions.</em>
557
+ #
558
+ # See also MiniTest::Rails::Expectations#must_have_tag
559
+ #
560
+ # :method: assert_tag
561
+ # :call-seq: assert_tag(*opts)
562
+
563
+ ##
564
+ # Identical to +assert_tag+, but asserts that a matching tag does _not_
565
+ # exist. (See +assert_tag+ for a full discussion of the syntax.)
566
+ #
567
+ # # Assert that there is not a "div" containing a "p"
568
+ # assert_no_tag tag: "div", descendant: { tag: "p" }
569
+ #
570
+ # # Assert that an unordered list is empty
571
+ # assert_no_tag tag: "ul", descendant: { tag: "li" }
572
+ #
573
+ # # Assert that there is not a "p" tag with between 1 to 3 "img" tags
574
+ # # as immediate children
575
+ # assert_no_tag tag: "p",
576
+ # children: { count: 1..3, only: { tag: "img" } }
577
+ #
578
+ # See also MiniTest::Rails::Expectations#wont_have_tag
579
+ #
580
+ # :method: assert_no_tag
581
+ # :call-seq: assert_no_tag(*opts)
582
+
583
+ ##
584
+ # Identical to +assert_tag+, but asserts that a matching tag does _not_
585
+ # exist. (See +assert_tag+ for a full discussion of the syntax.)
586
+ #
587
+ # # Assert that there is not a "div" containing a "p"
588
+ # assert_no_tag tag: "div", descendant: { tag: "p" }
589
+ #
590
+ # # Assert that an unordered list is empty
591
+ # assert_no_tag tag: "ul", descendant: { tag: "li" }
592
+ #
593
+ # # Assert that there is not a "p" tag with between 1 to 3 "img" tags
594
+ # # as immediate children
595
+ # assert_no_tag tag: "p",
596
+ # children: { count: 1..3, only: { tag: "img" } }
597
+ #
598
+ # See also MiniTest::Rails::Expectations#wont_have_tag
599
+ #
600
+ # :method: refute_tag
601
+ # :call-seq: refute_tag(*opts)
602
+ alias :refute_tag :assert_no_tag
603
+ end
604
+
605
+ class ActionView::TestCase
606
+ ##
607
+ # Checks if an expression is blank. Passes if actual.blank? is true.
608
+ #
609
+ # === This assertion is deprecated.
610
+ #
611
+ # Use the following to check for <tt>blank?</tt> instead:
612
+ #
613
+ # assert actual.blank?
614
+ #
615
+ # The deprecated assertion can be called like this:
616
+ #
617
+ # assert_blank []
618
+ #
619
+ # See also MiniTest::Rails::Expectations#must_be_blank
620
+ #
621
+ # :method: assert_blank
622
+ # :call-seq: assert_blank(actual, message = nil)
623
+
624
+ ##
625
+ # Checks if an expression is not present. Passes if actual.present? is false.
626
+ #
627
+ # === This assertion is deprecated.
628
+ #
629
+ # Use the following to check for <tt>present?</tt> instead:
630
+ #
631
+ # refute actual.present?
632
+ #
633
+ # The deprecated assertion can be called like this:
634
+ #
635
+ # refute_present nil
636
+ #
637
+ # See also MiniTest::Rails::Expectations#wont_be_present
638
+ #
639
+ # :args: actual, message = nil
640
+ alias :refute_present :assert_blank
641
+
642
+ ##
643
+ # Checks if an expression is present. Passes if actual.present? is true.
644
+ #
645
+ # === This assertion is deprecated.
646
+ #
647
+ # Use the following to check for <tt>present?</tt> instead:
648
+ #
649
+ # assert actual.present?
650
+ #
651
+ # The deprecated assertion can be called like this:
652
+ #
653
+ # assert_present Object.new
654
+ #
655
+ # See also MiniTest::Rails::Expectations#must_be_present
656
+ #
657
+ # :method: assert_present
658
+ # :call-seq: assert_present(actual, message = nil)
659
+
660
+ ##
661
+ # Checks if an expression is not blank. Passes if actual.blank? is false.
662
+ #
663
+ # === This assertion is deprecated.
664
+ #
665
+ # Use the following to check for <tt>blank?</tt> instead:
666
+ #
667
+ # refute actual.blank?
668
+ #
669
+ # The deprecated assertion can be called like this:
670
+ #
671
+ # refute_blank [1,2,3]
672
+ #
673
+ # See also MiniTest::Rails::Expectations#wont_be_blank
674
+ #
675
+ # :args: actual, message = nil
676
+ alias :refute_blank :assert_present
677
+
678
+ ##
679
+ # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
680
+ #
681
+ # assert_difference "User.count", +1 do
682
+ # User.create
683
+ # end
684
+ #
685
+ # See also MiniTest::Rails::Expectations#must_change
686
+ #
687
+ # :method: assert_difference
688
+ # :call-seq: assert_difference(expression, difference = 1, message = nil, &block)
689
+
690
+ ##
691
+ # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
692
+ #
693
+ # assert_no_difference "User.count" do
694
+ # User.new
695
+ # end
696
+ #
697
+ # See also MiniTest::Rails::Expectations#wont_change
698
+ #
699
+ # :method: assert_no_difference
700
+ # :call-seq: assert_no_difference(expression, message = nil, &block)
701
+
702
+ ##
703
+ # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
704
+ #
705
+ # refute_difference "User.count", do
706
+ # User.new
707
+ # end
708
+ #
709
+ # See also MiniTest::Rails::Expectations#wont_change
710
+ #
711
+ # :args: expression, message = nil, &block
712
+ alias :refute_difference :assert_no_difference
713
+
714
+ end
715
+
716
+ class ActionController::TestCase
717
+ # Asserts that the response is one of the following types:
718
+ #
719
+ # * <tt>:success</tt> - Status code was in the 200-299 range
720
+ # * <tt>:redirect</tt> - Status code was in the 300-399 range
721
+ # * <tt>:missing</tt> - Status code was 404
722
+ # * <tt>:error</tt> - Status code was in the 500-599 range
723
+ #
724
+ # You can also pass an explicit status number like <tt>assert_response(501)</tt>
725
+ # or its symbolic equivalent <tt>assert_response(:not_implemented)</tt>.
726
+ # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list.
727
+ #
728
+ # # assert that the response was a redirection
729
+ # assert_response :redirect
730
+ #
731
+ # # assert that the response code was status code 401 (unauthorized)
732
+ # assert_response 401
733
+ #
734
+ # See also MiniTest::Rails::Expectations#must_respond_with
735
+ #
736
+ # :method: assert_response
737
+ # :call-seq: assert_response(type, message = nil)
738
+
739
+ ##
740
+ # Assert that the redirection options passed in match those of the redirect called in the latest action.
741
+ # This match can be partial, such that <tt>assert_redirected_to(controller: "weblog")</tt> will also
742
+ # match the redirection of <tt>redirect_to(controller: "weblog", action: "show")</tt> and so on.
743
+ #
744
+ # # assert that the redirection was to the "index" action on the WeblogController
745
+ # assert_redirected_to controller: "weblog", action: "index"
746
+ #
747
+ # # assert that the redirection was to the named route login_url
748
+ # assert_redirected_to login_url
749
+ #
750
+ # # assert that the redirection was to the url for @customer
751
+ # assert_redirected_to @customer
752
+ #
753
+ # # asserts that the redirection matches the regular expression
754
+ # assert_redirected_to %r(\Ahttp://example.org)
755
+ #
756
+ # See also MiniTest::Rails::Expectations#must_redirect_to
757
+ #
758
+ # :method: assert_redirected_to
759
+ # :call-seq: assert_redirected_to(options = {}, message=nil)
760
+
761
+ ##
762
+ # Asserts that the request was rendered with the appropriate template file or partials.
763
+ #
764
+ # # assert that the "new" view template was rendered
765
+ # assert_template "new"
766
+ #
767
+ # # assert that the exact template "admin/posts/new" was rendered
768
+ # assert_template %r{\Aadmin/posts/new\Z}
769
+ #
770
+ # # assert that the layout 'admin' was rendered
771
+ # assert_template layout: 'admin'
772
+ # assert_template layout: 'layouts/admin'
773
+ # assert_template layout: :admin
774
+ #
775
+ # # assert that no layout was rendered
776
+ # assert_template layout: nil
777
+ # assert_template layout: false
778
+ #
779
+ # # assert that the "_customer" partial was rendered twice
780
+ # assert_template partial: '_customer', count: 2
781
+ #
782
+ # # assert that no partials were rendered
783
+ # assert_template partial: false
784
+ #
785
+ # In a view test case, you can also assert that specific locals are passed
786
+ # to partials:
787
+ #
788
+ # # assert that the "_customer" partial was rendered with a specific object
789
+ # assert_template partial: '_customer', locals: { customer: @customer }
790
+ #
791
+ # See also MiniTest::Rails::Expectations#must_render_template
792
+ #
793
+ # :method: assert_template
794
+ # :call-seq: assert_template(options = {}, message = nil)
795
+
796
+ ##
797
+ # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
798
+ # The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
799
+ # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
800
+ #
801
+ # The +defaults+ parameter is unused.
802
+ #
803
+ # # Asserts that the default action is generated for a route with no action
804
+ # assert_generates "/items", controller: "items", action: "index"
805
+ #
806
+ # # Tests that the list action is properly routed
807
+ # assert_generates "/items/list", controller: "items", action: "list"
808
+ #
809
+ # # Tests the generation of a route with a parameter
810
+ # assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
811
+ #
812
+ # # Asserts that the generated route gives us our custom route
813
+ # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
814
+ #
815
+ # See also MiniTest::Rails::Expectations#must_route_to
816
+ #
817
+ # :method: assert_generates
818
+ # :call-seq: assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
819
+
820
+ ##
821
+ # Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
822
+ # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
823
+ #
824
+ # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
825
+ # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
826
+ # and a :method containing the required HTTP verb.
827
+ #
828
+ # # assert that POSTing to /items will call the create action on ItemsController
829
+ # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
830
+ #
831
+ # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
832
+ # to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the
833
+ # extras argument, appending the query string on the path directly will not work. For example:
834
+ #
835
+ # # assert that a path of '/items/list/1?view=print' returns the correct options
836
+ # assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
837
+ #
838
+ # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
839
+ #
840
+ # # Check the default route (i.e., the index action)
841
+ # assert_recognizes({controller: 'items', action: 'index'}, 'items')
842
+ #
843
+ # # Test a specific action
844
+ # assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
845
+ #
846
+ # # Test an action with a parameter
847
+ # assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
848
+ #
849
+ # # Test a custom route
850
+ # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
851
+ #
852
+ # See also MiniTest::Rails::Expectations#must_route_from
853
+ #
854
+ # :method: assert_recognizes
855
+ # :call-seq: assert_recognizes(expected_options, path, extras={}, msg=nil)
856
+
857
+ ##
858
+ # Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
859
+ # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
860
+ # and +assert_generates+ into one step.
861
+ #
862
+ # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
863
+ # +message+ parameter allows you to specify a custom error message to display upon failure.
864
+ #
865
+ # # Assert a basic route: a controller with the default action (index)
866
+ # assert_routing '/home', controller: 'home', action: 'index'
867
+ #
868
+ # # Test a route generated with a specific controller, action, and parameter (id)
869
+ # assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
870
+ #
871
+ # # Assert a basic route (controller + default action), with an error message if it fails
872
+ # assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
873
+ #
874
+ # # Tests a route, providing a defaults hash
875
+ # assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
876
+ #
877
+ # # Tests a route with a HTTP method
878
+ # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
879
+ #
880
+ # See also MiniTest::Rails::Expectations#must_route
881
+ #
882
+ # :method: assert_routing
883
+ # :call-seq: assert_routing(path, options, defaults={}, extras={}, message=nil)
884
+
885
+ # An assertion that selects elements and makes one or more equality tests.
886
+ #
887
+ # If the first argument is an element, selects all matching elements
888
+ # starting from (and including) that element and all its children in
889
+ # depth-first order.
890
+ #
891
+ # If no element if specified, calling +assert_select+ selects from the
892
+ # response HTML unless +assert_select+ is called from within an +assert_select+ block.
893
+ #
894
+ # When called with a block +assert_select+ passes an array of selected elements
895
+ # to the block. Calling +assert_select+ from the block, with no element specified,
896
+ # runs the assertion on the complete set of elements selected by the enclosing assertion.
897
+ # Alternatively the array may be iterated through so that +assert_select+ can be called
898
+ # separately for each element.
899
+ #
900
+ #
901
+ # ==== Example
902
+ # If the response contains two ordered lists, each with four list elements then:
903
+ # assert_select "ol" do |elements|
904
+ # elements.each do |element|
905
+ # assert_select element, "li", 4
906
+ # end
907
+ # end
908
+ #
909
+ # will pass, as will:
910
+ # assert_select "ol" do
911
+ # assert_select "li", 8
912
+ # end
913
+ #
914
+ # The selector may be a CSS selector expression (String), an expression
915
+ # with substitution values, or an HTML::Selector object.
916
+ #
917
+ # === Equality Tests
918
+ #
919
+ # The equality test may be one of the following:
920
+ # * <tt>true</tt> - Assertion is true if at least one element selected.
921
+ # * <tt>false</tt> - Assertion is true if no element selected.
922
+ # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
923
+ # one element matches the string or regular expression.
924
+ # * <tt>Integer</tt> - Assertion is true if exactly that number of
925
+ # elements are selected.
926
+ # * <tt>Range</tt> - Assertion is true if the number of selected
927
+ # elements fit the range.
928
+ # If no equality test specified, the assertion is true if at least one
929
+ # element selected.
930
+ #
931
+ # To perform more than one equality tests, use a hash with the following keys:
932
+ # * <tt>:text</tt> - Narrow the selection to elements that have this text
933
+ # value (string or regexp).
934
+ # * <tt>:html</tt> - Narrow the selection to elements that have this HTML
935
+ # content (string or regexp).
936
+ # * <tt>:count</tt> - Assertion is true if the number of selected elements
937
+ # is equal to this value.
938
+ # * <tt>:minimum</tt> - Assertion is true if the number of selected
939
+ # elements is at least this value.
940
+ # * <tt>:maximum</tt> - Assertion is true if the number of selected
941
+ # elements is at most this value.
942
+ #
943
+ # If the method is called with a block, once all equality tests are
944
+ # evaluated the block is called with an array of all matched elements.
945
+ #
946
+ # # At least one form element
947
+ # assert_select "form"
948
+ #
949
+ # # Form element includes four input fields
950
+ # assert_select "form input", 4
951
+ #
952
+ # # Page title is "Welcome"
953
+ # assert_select "title", "Welcome"
954
+ #
955
+ # # Page title is "Welcome" and there is only one title element
956
+ # assert_select "title", {count: 1, text: "Welcome"},
957
+ # "Wrong title or more than one title element"
958
+ #
959
+ # # Page contains no forms
960
+ # assert_select "form", false, "This page must contain no forms"
961
+ #
962
+ # # Test the content and style
963
+ # assert_select "body div.header ul.menu"
964
+ #
965
+ # # Use substitution values
966
+ # assert_select "ol>li#?", /item-\d+/
967
+ #
968
+ # # All input fields in the form have a name
969
+ # assert_select "form input" do
970
+ # assert_select "[name=?]", /.+/ # Not empty
971
+ # end
972
+ #
973
+ # See also MiniTest::Rails::Expectations#must_select
974
+ #
975
+ # :method: assert_select
976
+ # :call-seq: assert_select(*args, &block)
977
+
978
+ # Extracts the body of an email and runs nested assertions on it.
979
+ #
980
+ # You must enable deliveries for this assertion to work, use:
981
+ # ActionMailer::Base.perform_deliveries = true
982
+ #
983
+ # assert_select_email do
984
+ # assert_select "h1", "Email alert"
985
+ # end
986
+ #
987
+ # assert_select_email do
988
+ # items = assert_select "ol>li"
989
+ # items.each do
990
+ # # Work with items here...
991
+ # end
992
+ # end
993
+ #
994
+ # See also MiniTest::Rails::Expectations#must_select_email
995
+ #
996
+ # :method: assert_select_email
997
+ # :call-seq: assert_select_email(&block)
998
+
999
+ # Extracts the content of an element, treats it as encoded HTML and runs
1000
+ # nested assertion on it.
1001
+ #
1002
+ # You typically call this method within another assertion to operate on
1003
+ # all currently selected elements. You can also pass an element or array
1004
+ # of elements.
1005
+ #
1006
+ # The content of each element is un-encoded, and wrapped in the root
1007
+ # element +encoded+. It then calls the block with all un-encoded elements.
1008
+ #
1009
+ # # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)
1010
+ # assert_select "feed[xmlns='http://www.w3.org/2005/Atom']" do
1011
+ # # Select each entry item and then the title item
1012
+ # assert_select "entry>title" do
1013
+ # # Run assertions on the encoded title elements
1014
+ # assert_select_encoded do
1015
+ # assert_select "b"
1016
+ # end
1017
+ # end
1018
+ # end
1019
+ #
1020
+ #
1021
+ # # Selects all paragraph tags from within the description of an RSS feed
1022
+ # assert_select "rss[version=2.0]" do
1023
+ # # Select description element of each feed item.
1024
+ # assert_select "channel>item>description" do
1025
+ # # Run assertions on the encoded elements.
1026
+ # assert_select_encoded do
1027
+ # assert_select "p"
1028
+ # end
1029
+ # end
1030
+ # end
1031
+ #
1032
+ # See also MiniTest::Rails::Expectations#must_select_encoded
1033
+ #
1034
+ # :method: assert_select_encoded
1035
+ # :call-seq: assert_select_encoded(element = nil, &block)
1036
+
1037
+ ##
1038
+ # Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values.
1039
+ #
1040
+ # assert_dom_equal '<a href="http://www.example.com">Apples</a>',
1041
+ # link_to("Apples", "http://www.example.com")
1042
+ #
1043
+ # See also MiniTest::Rails::Expectations#must_dom_equal
1044
+ #
1045
+ # :method: assert_dom_equal
1046
+ # :call-seq: assert_dom_equal(expected, actual, message = nil)
1047
+
1048
+ ##
1049
+ # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
1050
+ #
1051
+ # assert_dom_not_equal '<a href="http://www.example.com">Oranges</a>',
1052
+ # link_to("Apples", "http://www.example.com")
1053
+ #
1054
+ # See also MiniTest::Rails::Expectations#wont_dom_equal
1055
+ #
1056
+ # :method: assert_dom_not_equal
1057
+ # :call-seq: assert_dom_not_equal(expected, actual, message = nil)
1058
+
1059
+ ##
1060
+ # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
1061
+ #
1062
+ # refute_dom_equal '<a href="http://www.example.com">Oranges</a>',
1063
+ # link_to("Apples", "http://www.example.com")
1064
+ #
1065
+ # See also MiniTest::Rails::Expectations#wont_dom_equal
1066
+ #
1067
+ # :method: assert_dom_equal
1068
+ # :call-seq: assert_dom_equal(expected, actual, message = nil)
1069
+ alias :refute_dom_equal :assert_dom_not_equal
1070
+
1071
+ ##
1072
+ # Asserts that there is a tag/node/element in the body of the response
1073
+ # that meets all of the given conditions. The +conditions+ parameter must
1074
+ # be a hash of any of the following keys (all are optional):
1075
+ #
1076
+ # * <tt>:tag</tt>: the node type must match the corresponding value
1077
+ # * <tt>:attributes</tt>: a hash. The node's attributes must match the
1078
+ # corresponding values in the hash.
1079
+ # * <tt>:parent</tt>: a hash. The node's parent must match the
1080
+ # corresponding hash.
1081
+ # * <tt>:child</tt>: a hash. At least one of the node's immediate children
1082
+ # must meet the criteria described by the hash.
1083
+ # * <tt>:ancestor</tt>: a hash. At least one of the node's ancestors must
1084
+ # meet the criteria described by the hash.
1085
+ # * <tt>:descendant</tt>: a hash. At least one of the node's descendants
1086
+ # must meet the criteria described by the hash.
1087
+ # * <tt>:sibling</tt>: a hash. At least one of the node's siblings must
1088
+ # meet the criteria described by the hash.
1089
+ # * <tt>:after</tt>: a hash. The node must be after any sibling meeting
1090
+ # the criteria described by the hash, and at least one sibling must match.
1091
+ # * <tt>:before</tt>: a hash. The node must be before any sibling meeting
1092
+ # the criteria described by the hash, and at least one sibling must match.
1093
+ # * <tt>:children</tt>: a hash, for counting children of a node. Accepts
1094
+ # the keys:
1095
+ # * <tt>:count</tt>: either a number or a range which must equal (or
1096
+ # include) the number of children that match.
1097
+ # * <tt>:less_than</tt>: the number of matching children must be less
1098
+ # than this number.
1099
+ # * <tt>:greater_than</tt>: the number of matching children must be
1100
+ # greater than this number.
1101
+ # * <tt>:only</tt>: another hash consisting of the keys to use
1102
+ # to match on the children, and only matching children will be
1103
+ # counted.
1104
+ # * <tt>:content</tt>: the textual content of the node must match the
1105
+ # given value. This will not match HTML tags in the body of a
1106
+ # tag--only text.
1107
+ #
1108
+ # Conditions are matched using the following algorithm:
1109
+ #
1110
+ # * if the condition is a string, it must be a substring of the value.
1111
+ # * if the condition is a regexp, it must match the value.
1112
+ # * if the condition is a number, the value must match number.to_s.
1113
+ # * if the condition is +true+, the value must not be +nil+.
1114
+ # * if the condition is +false+ or +nil+, the value must be +nil+.
1115
+ #
1116
+ # # Assert that there is a "span" tag
1117
+ # assert_tag tag: "span"
1118
+ #
1119
+ # # Assert that there is a "span" tag with id="x"
1120
+ # assert_tag tag: "span", attributes: { id: "x" }
1121
+ #
1122
+ # # Assert that there is a "span" tag using the short-hand
1123
+ # assert_tag :span
1124
+ #
1125
+ # # Assert that there is a "span" tag with id="x" using the short-hand
1126
+ # assert_tag :span, attributes: { id: "x" }
1127
+ #
1128
+ # # Assert that there is a "span" inside of a "div"
1129
+ # assert_tag tag: "span", parent: { tag: "div" }
1130
+ #
1131
+ # # Assert that there is a "span" somewhere inside a table
1132
+ # assert_tag tag: "span", ancestor: { tag: "table" }
1133
+ #
1134
+ # # Assert that there is a "span" with at least one "em" child
1135
+ # assert_tag tag: "span", child: { tag: "em" }
1136
+ #
1137
+ # # Assert that there is a "span" containing a (possibly nested)
1138
+ # # "strong" tag.
1139
+ # assert_tag tag: "span", descendant: { tag: "strong" }
1140
+ #
1141
+ # # Assert that there is a "span" containing between 2 and 4 "em" tags
1142
+ # # as immediate children
1143
+ # assert_tag tag: "span",
1144
+ # children: { count: 2..4, only: { tag: "em" } }
1145
+ #
1146
+ # # Get funky: assert that there is a "div", with an "ul" ancestor
1147
+ # # and an "li" parent (with "class" = "enum"), and containing a
1148
+ # # "span" descendant that contains text matching /hello world/
1149
+ # assert_tag tag: "div",
1150
+ # ancestor: { tag: "ul" },
1151
+ # parent: { tag: "li",
1152
+ # attributes: { class: "enum" } },
1153
+ # descendant: { tag: "span",
1154
+ # child: /hello world/ }
1155
+ #
1156
+ # <b>Please note</b>: +assert_tag+ and +assert_no_tag+ only work
1157
+ # with well-formed XHTML. They recognize a few tags as implicitly self-closing
1158
+ # (like br and hr and such) but will not work correctly with tags
1159
+ # that allow optional closing tags (p, li, td). <em>You must explicitly
1160
+ # close all of your tags to use these assertions.</em>
1161
+ #
1162
+ # See also MiniTest::Rails::Expectations#must_have_tag
1163
+ #
1164
+ # :method: assert_tag
1165
+ # :call-seq: assert_tag(*opts)
1166
+
1167
+ ##
1168
+ # Identical to +assert_tag+, but asserts that a matching tag does _not_
1169
+ # exist. (See +assert_tag+ for a full discussion of the syntax.)
1170
+ #
1171
+ # # Assert that there is not a "div" containing a "p"
1172
+ # assert_no_tag tag: "div", descendant: { tag: "p" }
1173
+ #
1174
+ # # Assert that an unordered list is empty
1175
+ # assert_no_tag tag: "ul", descendant: { tag: "li" }
1176
+ #
1177
+ # # Assert that there is not a "p" tag with between 1 to 3 "img" tags
1178
+ # # as immediate children
1179
+ # assert_no_tag tag: "p",
1180
+ # children: { count: 1..3, only: { tag: "img" } }
1181
+ #
1182
+ # See also MiniTest::Rails::Expectations#wont_have_tag
1183
+ #
1184
+ # :method: assert_no_tag
1185
+ # :call-seq: assert_no_tag(*opts)
1186
+
1187
+ ##
1188
+ # Identical to +assert_tag+, but asserts that a matching tag does _not_
1189
+ # exist. (See +assert_tag+ for a full discussion of the syntax.)
1190
+ #
1191
+ # # Assert that there is not a "div" containing a "p"
1192
+ # assert_no_tag tag: "div", descendant: { tag: "p" }
1193
+ #
1194
+ # # Assert that an unordered list is empty
1195
+ # assert_no_tag tag: "ul", descendant: { tag: "li" }
1196
+ #
1197
+ # # Assert that there is not a "p" tag with between 1 to 3 "img" tags
1198
+ # # as immediate children
1199
+ # assert_no_tag tag: "p",
1200
+ # children: { count: 1..3, only: { tag: "img" } }
1201
+ #
1202
+ # See also MiniTest::Rails::Expectations#wont_have_tag
1203
+ #
1204
+ # :method: refute_tag
1205
+ # :call-seq: refute_tag(*opts)
1206
+ alias :refute_tag :assert_no_tag
1207
+ end
1208
+
1209
+ class ActionDispatch::IntegrationTest
1210
+ ##
1211
+ # Checks if an expression is blank. Passes if actual.blank? is true.
1212
+ #
1213
+ # === This assertion is deprecated.
1214
+ #
1215
+ # Use the following to check for <tt>blank?</tt> instead:
1216
+ #
1217
+ # assert actual.blank?
1218
+ #
1219
+ # The deprecated assertion can be called like this:
1220
+ #
1221
+ # assert_blank []
1222
+ #
1223
+ # See also MiniTest::Rails::Expectations#must_be_blank
1224
+ #
1225
+ # :method: assert_blank
1226
+ # :call-seq: assert_blank(actual, message = nil)
1227
+
1228
+ ##
1229
+ # Checks if an expression is not present. Passes if actual.present? is false.
1230
+ #
1231
+ # === This assertion is deprecated.
1232
+ #
1233
+ # Use the following to check for <tt>present?</tt> instead:
1234
+ #
1235
+ # refute actual.present?
1236
+ #
1237
+ # The deprecated assertion can be called like this:
1238
+ #
1239
+ # refute_present nil
1240
+ #
1241
+ # See also MiniTest::Rails::Expectations#wont_be_present
1242
+ #
1243
+ # :args: actual, message = nil
1244
+ alias :refute_present :assert_blank
1245
+
1246
+ ##
1247
+ # Checks if an expression is present. Passes if actual.present? is true.
1248
+ #
1249
+ # === This assertion is deprecated.
1250
+ #
1251
+ # Use the following to check for <tt>present?</tt> instead:
1252
+ #
1253
+ # assert actual.present?
1254
+ #
1255
+ # The deprecated assertion can be called like this:
1256
+ #
1257
+ # assert_present Object.new
1258
+ #
1259
+ # See also MiniTest::Rails::Expectations#must_be_present
1260
+ #
1261
+ # :method: assert_present
1262
+ # :call-seq: assert_present(actual, message = nil)
1263
+
1264
+ ##
1265
+ # Checks if an expression is not blank. Passes if actual.blank? is false.
1266
+ #
1267
+ # === This assertion is deprecated.
1268
+ #
1269
+ # Use the following to check for <tt>blank?</tt> instead:
1270
+ #
1271
+ # refute actual.blank?
1272
+ #
1273
+ # The deprecated assertion can be called like this:
1274
+ #
1275
+ # refute_blank [1,2,3]
1276
+ #
1277
+ # See also MiniTest::Rails::Expectations#wont_be_blank
1278
+ #
1279
+ # :args: actual, message = nil
1280
+ alias :refute_blank :assert_present
1281
+
1282
+ ##
1283
+ # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
1284
+ #
1285
+ # assert_difference "User.count", +1 do
1286
+ # User.create
1287
+ # end
1288
+ #
1289
+ # See also MiniTest::Rails::Expectations#must_change
1290
+ #
1291
+ # :method: assert_difference
1292
+ # :call-seq: assert_difference(expression, difference = 1, message = nil, &block)
1293
+
1294
+ ##
1295
+ # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
1296
+ #
1297
+ # assert_no_difference "User.count" do
1298
+ # User.new
1299
+ # end
1300
+ #
1301
+ # See also MiniTest::Rails::Expectations#wont_change
1302
+ #
1303
+ # :method: assert_no_difference
1304
+ # :call-seq: assert_no_difference(expression, message = nil, &block)
1305
+
1306
+ ##
1307
+ # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
1308
+ #
1309
+ # refute_difference "User.count", do
1310
+ # User.new
1311
+ # end
1312
+ #
1313
+ # See also MiniTest::Rails::Expectations#wont_change
1314
+ #
1315
+ # :args: expression, message = nil, &block
1316
+ alias :refute_difference :assert_no_difference
1317
+
1318
+ end
1319
+
1320
+ class ActionController::TestCase
1321
+ # Asserts that the response is one of the following types:
1322
+ #
1323
+ # * <tt>:success</tt> - Status code was in the 200-299 range
1324
+ # * <tt>:redirect</tt> - Status code was in the 300-399 range
1325
+ # * <tt>:missing</tt> - Status code was 404
1326
+ # * <tt>:error</tt> - Status code was in the 500-599 range
1327
+ #
1328
+ # You can also pass an explicit status number like <tt>assert_response(501)</tt>
1329
+ # or its symbolic equivalent <tt>assert_response(:not_implemented)</tt>.
1330
+ # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list.
1331
+ #
1332
+ # # assert that the response was a redirection
1333
+ # assert_response :redirect
1334
+ #
1335
+ # # assert that the response code was status code 401 (unauthorized)
1336
+ # assert_response 401
1337
+ #
1338
+ # See also MiniTest::Rails::Expectations#must_respond_with
1339
+ #
1340
+ # :method: assert_response
1341
+ # :call-seq: assert_response(type, message = nil)
1342
+
1343
+ ##
1344
+ # Assert that the redirection options passed in match those of the redirect called in the latest action.
1345
+ # This match can be partial, such that <tt>assert_redirected_to(controller: "weblog")</tt> will also
1346
+ # match the redirection of <tt>redirect_to(controller: "weblog", action: "show")</tt> and so on.
1347
+ #
1348
+ # # assert that the redirection was to the "index" action on the WeblogController
1349
+ # assert_redirected_to controller: "weblog", action: "index"
1350
+ #
1351
+ # # assert that the redirection was to the named route login_url
1352
+ # assert_redirected_to login_url
1353
+ #
1354
+ # # assert that the redirection was to the url for @customer
1355
+ # assert_redirected_to @customer
1356
+ #
1357
+ # # asserts that the redirection matches the regular expression
1358
+ # assert_redirected_to %r(\Ahttp://example.org)
1359
+ #
1360
+ # See also MiniTest::Rails::Expectations#must_redirect_to
1361
+ #
1362
+ # :method: assert_redirected_to
1363
+ # :call-seq: assert_redirected_to(options = {}, message=nil)
1364
+
1365
+ ##
1366
+ # Asserts that the request was rendered with the appropriate template file or partials.
1367
+ #
1368
+ # # assert that the "new" view template was rendered
1369
+ # assert_template "new"
1370
+ #
1371
+ # # assert that the exact template "admin/posts/new" was rendered
1372
+ # assert_template %r{\Aadmin/posts/new\Z}
1373
+ #
1374
+ # # assert that the layout 'admin' was rendered
1375
+ # assert_template layout: 'admin'
1376
+ # assert_template layout: 'layouts/admin'
1377
+ # assert_template layout: :admin
1378
+ #
1379
+ # # assert that no layout was rendered
1380
+ # assert_template layout: nil
1381
+ # assert_template layout: false
1382
+ #
1383
+ # # assert that the "_customer" partial was rendered twice
1384
+ # assert_template partial: '_customer', count: 2
1385
+ #
1386
+ # # assert that no partials were rendered
1387
+ # assert_template partial: false
1388
+ #
1389
+ # In a view test case, you can also assert that specific locals are passed
1390
+ # to partials:
1391
+ #
1392
+ # # assert that the "_customer" partial was rendered with a specific object
1393
+ # assert_template partial: '_customer', locals: { customer: @customer }
1394
+ #
1395
+ # See also MiniTest::Rails::Expectations#must_render_template
1396
+ #
1397
+ # :method: assert_template
1398
+ # :call-seq: assert_template(options = {}, message = nil)
1399
+
1400
+ ##
1401
+ # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
1402
+ # The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
1403
+ # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
1404
+ #
1405
+ # The +defaults+ parameter is unused.
1406
+ #
1407
+ # # Asserts that the default action is generated for a route with no action
1408
+ # assert_generates "/items", controller: "items", action: "index"
1409
+ #
1410
+ # # Tests that the list action is properly routed
1411
+ # assert_generates "/items/list", controller: "items", action: "list"
1412
+ #
1413
+ # # Tests the generation of a route with a parameter
1414
+ # assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
1415
+ #
1416
+ # # Asserts that the generated route gives us our custom route
1417
+ # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
1418
+ #
1419
+ # See also MiniTest::Rails::Expectations#must_route_to
1420
+ #
1421
+ # :method: assert_generates
1422
+ # :call-seq: assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
1423
+
1424
+ ##
1425
+ # Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
1426
+ # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
1427
+ #
1428
+ # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
1429
+ # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
1430
+ # and a :method containing the required HTTP verb.
1431
+ #
1432
+ # # assert that POSTing to /items will call the create action on ItemsController
1433
+ # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
1434
+ #
1435
+ # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
1436
+ # to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the
1437
+ # extras argument, appending the query string on the path directly will not work. For example:
1438
+ #
1439
+ # # assert that a path of '/items/list/1?view=print' returns the correct options
1440
+ # assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
1441
+ #
1442
+ # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
1443
+ #
1444
+ # # Check the default route (i.e., the index action)
1445
+ # assert_recognizes({controller: 'items', action: 'index'}, 'items')
1446
+ #
1447
+ # # Test a specific action
1448
+ # assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
1449
+ #
1450
+ # # Test an action with a parameter
1451
+ # assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
1452
+ #
1453
+ # # Test a custom route
1454
+ # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
1455
+ #
1456
+ # See also MiniTest::Rails::Expectations#must_route_from
1457
+ #
1458
+ # :method: assert_recognizes
1459
+ # :call-seq: assert_recognizes(expected_options, path, extras={}, msg=nil)
1460
+
1461
+ ##
1462
+ # Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
1463
+ # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
1464
+ # and +assert_generates+ into one step.
1465
+ #
1466
+ # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
1467
+ # +message+ parameter allows you to specify a custom error message to display upon failure.
1468
+ #
1469
+ # # Assert a basic route: a controller with the default action (index)
1470
+ # assert_routing '/home', controller: 'home', action: 'index'
1471
+ #
1472
+ # # Test a route generated with a specific controller, action, and parameter (id)
1473
+ # assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
1474
+ #
1475
+ # # Assert a basic route (controller + default action), with an error message if it fails
1476
+ # assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
1477
+ #
1478
+ # # Tests a route, providing a defaults hash
1479
+ # assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
1480
+ #
1481
+ # # Tests a route with a HTTP method
1482
+ # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
1483
+ #
1484
+ # See also MiniTest::Rails::Expectations#must_route
1485
+ #
1486
+ # :method: assert_routing
1487
+ # :call-seq: assert_routing(path, options, defaults={}, extras={}, message=nil)
1488
+
1489
+ # An assertion that selects elements and makes one or more equality tests.
1490
+ #
1491
+ # If the first argument is an element, selects all matching elements
1492
+ # starting from (and including) that element and all its children in
1493
+ # depth-first order.
1494
+ #
1495
+ # If no element if specified, calling +assert_select+ selects from the
1496
+ # response HTML unless +assert_select+ is called from within an +assert_select+ block.
1497
+ #
1498
+ # When called with a block +assert_select+ passes an array of selected elements
1499
+ # to the block. Calling +assert_select+ from the block, with no element specified,
1500
+ # runs the assertion on the complete set of elements selected by the enclosing assertion.
1501
+ # Alternatively the array may be iterated through so that +assert_select+ can be called
1502
+ # separately for each element.
1503
+ #
1504
+ #
1505
+ # ==== Example
1506
+ # If the response contains two ordered lists, each with four list elements then:
1507
+ # assert_select "ol" do |elements|
1508
+ # elements.each do |element|
1509
+ # assert_select element, "li", 4
1510
+ # end
1511
+ # end
1512
+ #
1513
+ # will pass, as will:
1514
+ # assert_select "ol" do
1515
+ # assert_select "li", 8
1516
+ # end
1517
+ #
1518
+ # The selector may be a CSS selector expression (String), an expression
1519
+ # with substitution values, or an HTML::Selector object.
1520
+ #
1521
+ # === Equality Tests
1522
+ #
1523
+ # The equality test may be one of the following:
1524
+ # * <tt>true</tt> - Assertion is true if at least one element selected.
1525
+ # * <tt>false</tt> - Assertion is true if no element selected.
1526
+ # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
1527
+ # one element matches the string or regular expression.
1528
+ # * <tt>Integer</tt> - Assertion is true if exactly that number of
1529
+ # elements are selected.
1530
+ # * <tt>Range</tt> - Assertion is true if the number of selected
1531
+ # elements fit the range.
1532
+ # If no equality test specified, the assertion is true if at least one
1533
+ # element selected.
1534
+ #
1535
+ # To perform more than one equality tests, use a hash with the following keys:
1536
+ # * <tt>:text</tt> - Narrow the selection to elements that have this text
1537
+ # value (string or regexp).
1538
+ # * <tt>:html</tt> - Narrow the selection to elements that have this HTML
1539
+ # content (string or regexp).
1540
+ # * <tt>:count</tt> - Assertion is true if the number of selected elements
1541
+ # is equal to this value.
1542
+ # * <tt>:minimum</tt> - Assertion is true if the number of selected
1543
+ # elements is at least this value.
1544
+ # * <tt>:maximum</tt> - Assertion is true if the number of selected
1545
+ # elements is at most this value.
1546
+ #
1547
+ # If the method is called with a block, once all equality tests are
1548
+ # evaluated the block is called with an array of all matched elements.
1549
+ #
1550
+ # # At least one form element
1551
+ # assert_select "form"
1552
+ #
1553
+ # # Form element includes four input fields
1554
+ # assert_select "form input", 4
1555
+ #
1556
+ # # Page title is "Welcome"
1557
+ # assert_select "title", "Welcome"
1558
+ #
1559
+ # # Page title is "Welcome" and there is only one title element
1560
+ # assert_select "title", {count: 1, text: "Welcome"},
1561
+ # "Wrong title or more than one title element"
1562
+ #
1563
+ # # Page contains no forms
1564
+ # assert_select "form", false, "This page must contain no forms"
1565
+ #
1566
+ # # Test the content and style
1567
+ # assert_select "body div.header ul.menu"
1568
+ #
1569
+ # # Use substitution values
1570
+ # assert_select "ol>li#?", /item-\d+/
1571
+ #
1572
+ # # All input fields in the form have a name
1573
+ # assert_select "form input" do
1574
+ # assert_select "[name=?]", /.+/ # Not empty
1575
+ # end
1576
+ #
1577
+ # See also MiniTest::Rails::Expectations#must_select
1578
+ #
1579
+ # :method: assert_select
1580
+ # :call-seq: assert_select(*args, &block)
1581
+
1582
+ # Extracts the body of an email and runs nested assertions on it.
1583
+ #
1584
+ # You must enable deliveries for this assertion to work, use:
1585
+ # ActionMailer::Base.perform_deliveries = true
1586
+ #
1587
+ # assert_select_email do
1588
+ # assert_select "h1", "Email alert"
1589
+ # end
1590
+ #
1591
+ # assert_select_email do
1592
+ # items = assert_select "ol>li"
1593
+ # items.each do
1594
+ # # Work with items here...
1595
+ # end
1596
+ # end
1597
+ #
1598
+ # See also MiniTest::Rails::Expectations#must_select_email
1599
+ #
1600
+ # :method: assert_select_email
1601
+ # :call-seq: assert_select_email(&block)
1602
+
1603
+ # Extracts the content of an element, treats it as encoded HTML and runs
1604
+ # nested assertion on it.
1605
+ #
1606
+ # You typically call this method within another assertion to operate on
1607
+ # all currently selected elements. You can also pass an element or array
1608
+ # of elements.
1609
+ #
1610
+ # The content of each element is un-encoded, and wrapped in the root
1611
+ # element +encoded+. It then calls the block with all un-encoded elements.
1612
+ #
1613
+ # # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)
1614
+ # assert_select "feed[xmlns='http://www.w3.org/2005/Atom']" do
1615
+ # # Select each entry item and then the title item
1616
+ # assert_select "entry>title" do
1617
+ # # Run assertions on the encoded title elements
1618
+ # assert_select_encoded do
1619
+ # assert_select "b"
1620
+ # end
1621
+ # end
1622
+ # end
1623
+ #
1624
+ #
1625
+ # # Selects all paragraph tags from within the description of an RSS feed
1626
+ # assert_select "rss[version=2.0]" do
1627
+ # # Select description element of each feed item.
1628
+ # assert_select "channel>item>description" do
1629
+ # # Run assertions on the encoded elements.
1630
+ # assert_select_encoded do
1631
+ # assert_select "p"
1632
+ # end
1633
+ # end
1634
+ # end
1635
+ #
1636
+ # See also MiniTest::Rails::Expectations#must_select_encoded
1637
+ #
1638
+ # :method: assert_select_encoded
1639
+ # :call-seq: assert_select_encoded(element = nil, &block)
1640
+
1641
+ ##
1642
+ # Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values.
1643
+ #
1644
+ # assert_dom_equal '<a href="http://www.example.com">Apples</a>',
1645
+ # link_to("Apples", "http://www.example.com")
1646
+ #
1647
+ # See also MiniTest::Rails::Expectations#must_dom_equal
1648
+ #
1649
+ # :method: assert_dom_equal
1650
+ # :call-seq: assert_dom_equal(expected, actual, message = nil)
1651
+
1652
+ ##
1653
+ # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
1654
+ #
1655
+ # assert_dom_not_equal '<a href="http://www.example.com">Oranges</a>',
1656
+ # link_to("Apples", "http://www.example.com")
1657
+ #
1658
+ # See also MiniTest::Rails::Expectations#wont_dom_equal
1659
+ #
1660
+ # :method: assert_dom_not_equal
1661
+ # :call-seq: assert_dom_not_equal(expected, actual, message = nil)
1662
+
1663
+ ##
1664
+ # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
1665
+ #
1666
+ # refute_dom_equal '<a href="http://www.example.com">Oranges</a>',
1667
+ # link_to("Apples", "http://www.example.com")
1668
+ #
1669
+ # See also MiniTest::Rails::Expectations#wont_dom_equal
1670
+ #
1671
+ # :method: assert_dom_equal
1672
+ # :call-seq: assert_dom_equal(expected, actual, message = nil)
1673
+ alias :refute_dom_equal :assert_dom_not_equal
1674
+
1675
+ ##
1676
+ # Asserts that there is a tag/node/element in the body of the response
1677
+ # that meets all of the given conditions. The +conditions+ parameter must
1678
+ # be a hash of any of the following keys (all are optional):
1679
+ #
1680
+ # * <tt>:tag</tt>: the node type must match the corresponding value
1681
+ # * <tt>:attributes</tt>: a hash. The node's attributes must match the
1682
+ # corresponding values in the hash.
1683
+ # * <tt>:parent</tt>: a hash. The node's parent must match the
1684
+ # corresponding hash.
1685
+ # * <tt>:child</tt>: a hash. At least one of the node's immediate children
1686
+ # must meet the criteria described by the hash.
1687
+ # * <tt>:ancestor</tt>: a hash. At least one of the node's ancestors must
1688
+ # meet the criteria described by the hash.
1689
+ # * <tt>:descendant</tt>: a hash. At least one of the node's descendants
1690
+ # must meet the criteria described by the hash.
1691
+ # * <tt>:sibling</tt>: a hash. At least one of the node's siblings must
1692
+ # meet the criteria described by the hash.
1693
+ # * <tt>:after</tt>: a hash. The node must be after any sibling meeting
1694
+ # the criteria described by the hash, and at least one sibling must match.
1695
+ # * <tt>:before</tt>: a hash. The node must be before any sibling meeting
1696
+ # the criteria described by the hash, and at least one sibling must match.
1697
+ # * <tt>:children</tt>: a hash, for counting children of a node. Accepts
1698
+ # the keys:
1699
+ # * <tt>:count</tt>: either a number or a range which must equal (or
1700
+ # include) the number of children that match.
1701
+ # * <tt>:less_than</tt>: the number of matching children must be less
1702
+ # than this number.
1703
+ # * <tt>:greater_than</tt>: the number of matching children must be
1704
+ # greater than this number.
1705
+ # * <tt>:only</tt>: another hash consisting of the keys to use
1706
+ # to match on the children, and only matching children will be
1707
+ # counted.
1708
+ # * <tt>:content</tt>: the textual content of the node must match the
1709
+ # given value. This will not match HTML tags in the body of a
1710
+ # tag--only text.
1711
+ #
1712
+ # Conditions are matched using the following algorithm:
1713
+ #
1714
+ # * if the condition is a string, it must be a substring of the value.
1715
+ # * if the condition is a regexp, it must match the value.
1716
+ # * if the condition is a number, the value must match number.to_s.
1717
+ # * if the condition is +true+, the value must not be +nil+.
1718
+ # * if the condition is +false+ or +nil+, the value must be +nil+.
1719
+ #
1720
+ # # Assert that there is a "span" tag
1721
+ # assert_tag tag: "span"
1722
+ #
1723
+ # # Assert that there is a "span" tag with id="x"
1724
+ # assert_tag tag: "span", attributes: { id: "x" }
1725
+ #
1726
+ # # Assert that there is a "span" tag using the short-hand
1727
+ # assert_tag :span
1728
+ #
1729
+ # # Assert that there is a "span" tag with id="x" using the short-hand
1730
+ # assert_tag :span, attributes: { id: "x" }
1731
+ #
1732
+ # # Assert that there is a "span" inside of a "div"
1733
+ # assert_tag tag: "span", parent: { tag: "div" }
1734
+ #
1735
+ # # Assert that there is a "span" somewhere inside a table
1736
+ # assert_tag tag: "span", ancestor: { tag: "table" }
1737
+ #
1738
+ # # Assert that there is a "span" with at least one "em" child
1739
+ # assert_tag tag: "span", child: { tag: "em" }
1740
+ #
1741
+ # # Assert that there is a "span" containing a (possibly nested)
1742
+ # # "strong" tag.
1743
+ # assert_tag tag: "span", descendant: { tag: "strong" }
1744
+ #
1745
+ # # Assert that there is a "span" containing between 2 and 4 "em" tags
1746
+ # # as immediate children
1747
+ # assert_tag tag: "span",
1748
+ # children: { count: 2..4, only: { tag: "em" } }
1749
+ #
1750
+ # # Get funky: assert that there is a "div", with an "ul" ancestor
1751
+ # # and an "li" parent (with "class" = "enum"), and containing a
1752
+ # # "span" descendant that contains text matching /hello world/
1753
+ # assert_tag tag: "div",
1754
+ # ancestor: { tag: "ul" },
1755
+ # parent: { tag: "li",
1756
+ # attributes: { class: "enum" } },
1757
+ # descendant: { tag: "span",
1758
+ # child: /hello world/ }
1759
+ #
1760
+ # <b>Please note</b>: +assert_tag+ and +assert_no_tag+ only work
1761
+ # with well-formed XHTML. They recognize a few tags as implicitly self-closing
1762
+ # (like br and hr and such) but will not work correctly with tags
1763
+ # that allow optional closing tags (p, li, td). <em>You must explicitly
1764
+ # close all of your tags to use these assertions.</em>
1765
+ #
1766
+ # See also MiniTest::Rails::Expectations#must_have_tag
1767
+ #
1768
+ # :method: assert_tag
1769
+ # :call-seq: assert_tag(*opts)
1770
+
1771
+ ##
1772
+ # Identical to +assert_tag+, but asserts that a matching tag does _not_
1773
+ # exist. (See +assert_tag+ for a full discussion of the syntax.)
1774
+ #
1775
+ # # Assert that there is not a "div" containing a "p"
1776
+ # assert_no_tag tag: "div", descendant: { tag: "p" }
1777
+ #
1778
+ # # Assert that an unordered list is empty
1779
+ # assert_no_tag tag: "ul", descendant: { tag: "li" }
1780
+ #
1781
+ # # Assert that there is not a "p" tag with between 1 to 3 "img" tags
1782
+ # # as immediate children
1783
+ # assert_no_tag tag: "p",
1784
+ # children: { count: 1..3, only: { tag: "img" } }
1785
+ #
1786
+ # See also MiniTest::Rails::Expectations#wont_have_tag
1787
+ #
1788
+ # :method: assert_no_tag
1789
+ # :call-seq: assert_no_tag(*opts)
1790
+
1791
+ ##
1792
+ # Identical to +assert_tag+, but asserts that a matching tag does _not_
1793
+ # exist. (See +assert_tag+ for a full discussion of the syntax.)
1794
+ #
1795
+ # # Assert that there is not a "div" containing a "p"
1796
+ # assert_no_tag tag: "div", descendant: { tag: "p" }
1797
+ #
1798
+ # # Assert that an unordered list is empty
1799
+ # assert_no_tag tag: "ul", descendant: { tag: "li" }
1800
+ #
1801
+ # # Assert that there is not a "p" tag with between 1 to 3 "img" tags
1802
+ # # as immediate children
1803
+ # assert_no_tag tag: "p",
1804
+ # children: { count: 1..3, only: { tag: "img" } }
1805
+ #
1806
+ # See also MiniTest::Rails::Expectations#wont_have_tag
1807
+ #
1808
+ # :method: refute_tag
1809
+ # :call-seq: refute_tag(*opts)
1810
+ alias :refute_tag :assert_no_tag
1811
+ end