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,659 @@
1
+ module MiniTest::Rails::Expectations
2
+
3
+ ##############################################################################
4
+ # ActiveSupport Expectations
5
+ ##############################################################################
6
+
7
+ ##
8
+ # Checks if an expression is blank. Passes if actual.blank? is true.
9
+ #
10
+ # === This expectation is deprecated.
11
+ #
12
+ # Use the following to check for <tt>blank?</tt> instead:
13
+ #
14
+ # actual.must_be :blank?
15
+ #
16
+ # The deprecated expectation can be called like this:
17
+ #
18
+ # "".must_be_blank
19
+ # nil.must_be_blank
20
+ # [].must_be_blank
21
+ # {}.must_be_blank
22
+ #
23
+ # See also ActiveSupport::TestCase#assert_blank
24
+ #
25
+ # :method: must_be_blank
26
+ # :args: message = nil
27
+ infect_an_assertion :assert_blank, :must_be_blank, :unary
28
+
29
+ ##
30
+ # Checks if an expression is not present. Passes if actual.present? is false.
31
+ #
32
+ # === This expectation is deprecated.
33
+ #
34
+ # Use the following to check for <tt>present?</tt> instead:
35
+ #
36
+ # actual.wont_be :present?
37
+ #
38
+ # The deprecated expectation can be called like this:
39
+ #
40
+ # "".wont_be_present
41
+ # nil.wont_be_present
42
+ # [].wont_be_present
43
+ # {}.wont_be_present
44
+ #
45
+ # See also ActiveSupport::TestCase#refute_present
46
+ #
47
+ # :method: wont_be_present
48
+ # :args: message = nil
49
+ infect_an_assertion :refute_present, :wont_be_present, :unary
50
+
51
+ ##
52
+ # Checks if an expression is present. Passes if actual.present? is true.
53
+ #
54
+ # === This expectation is deprecated.
55
+ #
56
+ # Use the following to check for <tt>present?</tt> instead:
57
+ #
58
+ # actual.must_be :present?
59
+ #
60
+ # The deprecated expectation can be called like this:
61
+ #
62
+ # "here".must_be_present
63
+ # Object.new.must_be_present
64
+ # [1,2,3].must_be_present
65
+ # {:key => :value}.must_be_present
66
+ #
67
+ # See also ActiveSupport::TestCase#assert_present
68
+ #
69
+ # :method: must_be_present
70
+ # :args: message = nil
71
+ infect_an_assertion :assert_present, :must_be_present, :unary
72
+
73
+ ##
74
+ # Checks if an expression is not blank. Passes if actual.blank? is false.
75
+ #
76
+ # === This expectation is deprecated.
77
+ #
78
+ # Use the following to check for <tt>blank?</tt> instead:
79
+ #
80
+ # actual.wont_be :blank?
81
+ #
82
+ # The deprecated expectation can be called like this:
83
+ #
84
+ # "here".wont_be_blank
85
+ # Object.new.wont_be_blank
86
+ # [1,2,3].wont_be_blank
87
+ # {:key => :value}.wont_be_blank
88
+ #
89
+ # See also ActiveSupport::TestCase#refute_blank
90
+ #
91
+ # :method: wont_be_blank
92
+ # :args: message = nil
93
+ infect_an_assertion :refute_blank, :wont_be_blank, :unary
94
+
95
+ ##
96
+ # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
97
+ #
98
+ # lambda { User.create password: "valid" }.must_change "User.count"
99
+ # lambda { 3.times do
100
+ # User.create password: "valid"
101
+ # end }.must_change "User.count", 3
102
+ #
103
+ # See also ActiveSupport::TestCase#assert_difference
104
+ #
105
+ # :method: must_change
106
+ # :args: expression, difference = 1, message = nil
107
+ infect_an_assertion :assert_difference, :must_change
108
+
109
+ ##
110
+ # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
111
+ #
112
+ # lambda { User.new }.wont_change "User.count"
113
+ #
114
+ # See also ActiveSupport::TestCase#refute_difference
115
+ #
116
+ # :method: wont_change
117
+ # :args: expression, message = nil
118
+ infect_an_assertion :refute_difference, :wont_change
119
+
120
+ ##############################################################################
121
+ # ActionController/ActionView/ActionDispatch Expectations
122
+ ##############################################################################
123
+
124
+ # Expects that the response is one of the following types:
125
+ #
126
+ # * <tt>:success</tt> - Status code was in the 200-299 range
127
+ # * <tt>:redirect</tt> - Status code was in the 300-399 range
128
+ # * <tt>:missing</tt> - Status code was 404
129
+ # * <tt>:error</tt> - Status code was in the 500-599 range
130
+ #
131
+ # You can also pass an explicit status number like <tt>assert_response(501)</tt>
132
+ # or its symbolic equivalent <tt>assert_response(:not_implemented)</tt>.
133
+ # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list.
134
+ #
135
+ # # expect that the response was a redirection
136
+ # must_respond_with :redirect
137
+ # response.must_respond_with :redirect
138
+ #
139
+ # # expect that the response code was status code 401 (unauthorized)
140
+ # must_respond_with 401
141
+ # response.must_respond_with 401
142
+ #
143
+ # See also ActionController::TestCase#assert_response
144
+ # See also ActionView::TestCase#assert_response
145
+ # See also ActionDispatch::IntegrationTest#assert_response
146
+ #
147
+ # :method: must_respond_with
148
+ # :call-seq: must_respond_with(type, message = nil)
149
+
150
+ ##
151
+ # Expects that the redirection options passed in match those of the redirect called in the latest action.
152
+ # This match can be partial, such that <tt>assert_redirected_to(controller: "weblog")</tt> will also
153
+ # match the redirection of <tt>redirect_to(controller: "weblog", action: "show")</tt> and so on.
154
+ #
155
+ # # expect that the redirection was to the "index" action on the WeblogController
156
+ # must_redirect_to controller: "weblog", action: "index"
157
+ #
158
+ # # expect that the redirection was to the named route login_url
159
+ # must_redirect_to login_url
160
+ #
161
+ # # expect that the redirection was to the url for @customer
162
+ # must_redirect_to @customer
163
+ #
164
+ # # expect that the redirection matches the regular expression
165
+ # must_redirect_to %r(\Ahttp://example.org)
166
+ #
167
+ # See also ActionController::TestCase#assert_redirected_to
168
+ # See also ActionView::TestCase#assert_redirected_to
169
+ # See also ActionDispatch::IntegrationTest#assert_redirected_to
170
+ #
171
+ # :method: must_redirect_to
172
+ # :call-seq: must_redirect_to(options = {}, message=nil)
173
+
174
+ ##
175
+ # Expects that the request was rendered with the appropriate template file or partials.
176
+ #
177
+ # # expect that the "new" view template was rendered
178
+ # must_render_template "new"
179
+ #
180
+ # # expect that the exact template "admin/posts/new" was rendered
181
+ # must_render_template %r{\Aadmin/posts/new\Z}
182
+ #
183
+ # # expect that the layout 'admin' was rendered
184
+ # must_render_template layout: 'admin'
185
+ # must_render_template layout: 'layouts/admin'
186
+ # must_render_template layout: :admin
187
+ #
188
+ # # expect that no layout was rendered
189
+ # must_render_template layout: nil
190
+ # must_render_template layout: false
191
+ #
192
+ # # expect that the "_customer" partial was rendered twice
193
+ # must_render_template partial: '_customer', count: 2
194
+ #
195
+ # # expect that no partials were rendered
196
+ # must_render_template partial: false
197
+ #
198
+ # In a view test case, you can also expect that specific locals are passed
199
+ # to partials:
200
+ #
201
+ # # expect that the "_customer" partial was rendered with a specific object
202
+ # must_render_template partial: '_customer', locals: { customer: @customer }
203
+ #
204
+ # See also ActionController::TestCase#assert_template
205
+ # See also ActionView::TestCase#assert_template
206
+ # See also ActionDispatch::IntegrationTest#assert_template
207
+ #
208
+ # :method: must_render_template
209
+ # :call-seq: must_render_template(options = {}, message = nil)
210
+
211
+ ##
212
+ # Expects that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
213
+ # The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
214
+ # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
215
+ #
216
+ # The +defaults+ parameter is unused.
217
+ #
218
+ # # Expects that the default action is generated for a route with no action
219
+ # {controller: "items", action: "index"}.must_route_from "/items"
220
+ #
221
+ # # Tests that the list action is properly routed
222
+ # {controller: "items", action: "list"}.must_route_to "/items/list"
223
+ #
224
+ # # Tests the generation of a route with a parameter
225
+ # { controller: "items", action: "list", id: "1" }.must_route_from "/items/list/1"
226
+ #
227
+ # # Expects that the generated route gives us our custom route
228
+ # { controller: 'scm', action: 'show_diff', revision: "12" }.must_route_from "changesets/12"
229
+ #
230
+ # See also ActionController::TestCase#assert_generates
231
+ # See also ActionView::TestCase#assert_generates
232
+ # See also ActionDispatch::IntegrationTest#assert_generates
233
+ #
234
+ # :method: must_route_from
235
+ # :call-seq: options.must_route_from(expected_path, defaults={}, extras = {}, message=nil)
236
+ infect_an_assertion :assert_generates, :must_route_to
237
+
238
+ ##
239
+ # Expects that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
240
+ # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
241
+ #
242
+ # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
243
+ # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
244
+ # and a :method containing the required HTTP verb.
245
+ #
246
+ # # assert that POSTing to /items will call the create action on ItemsController
247
+ # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
248
+ #
249
+ # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
250
+ # 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
251
+ # extras argument, appending the query string on the path directly will not work. For example:
252
+ #
253
+ # # Expect that a path of '/items/list/1?view=print' returns the correct options
254
+ # 'items/list/1'.must_route_from({controller: 'items', action: 'list', id: '1', view: 'print'}, { view: "print" })
255
+ #
256
+ # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
257
+ #
258
+ # # Check the default route (i.e., the index action)
259
+ # 'items'.must_route_from({controller: 'items', action: 'index'})
260
+ #
261
+ # # Test a specific action
262
+ # 'items/list'.must_route_from({controller: 'items', action: 'list'})
263
+ #
264
+ # # Test an action with a parameter
265
+ # 'items/destroy/1'.must_route_from({controller: 'items', action: 'destroy', id: '1'})
266
+ #
267
+ # # Test a custom route
268
+ # 'view/item1'.must_route_from({controller: 'items', action: 'show', id: '1'})
269
+ #
270
+ # See also ActionController::TestCase#assert_recognizes
271
+ # See also ActionView::TestCase#assert_recognizes
272
+ # See also ActionDispatch::IntegrationTest#assert_recognizes
273
+ #
274
+ # :method: must_route_from
275
+ # :call-seq: path.must_route_from(expected_options, extras={}, msg=nil)
276
+ infect_an_assertion :assert_recognizes, :must_route_from
277
+
278
+ ##
279
+ # Expects that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
280
+ # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
281
+ # and +assert_generates+ into one step.
282
+ #
283
+ # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
284
+ # +message+ parameter allows you to specify a custom error message to display upon failure.
285
+ #
286
+ # # Expect a basic route: a controller with the default action (index)
287
+ # { controller: 'home', action: 'index' }.must_route_for '/home'
288
+ #
289
+ # # Test a route generated with a specific controller, action, and parameter (id)
290
+ # { controller: 'entries', action: 'show', id: 23 }.must_route_for '/entries/show/23'
291
+ #
292
+ # # Expect a basic route (controller + default action), with an error message if it fails
293
+ # { controller: 'store', action: 'index' }.must_route_for '/store'
294
+ #
295
+ # # Tests a route, providing a defaults hash
296
+ # {id: "9", item: "square"}.must_route_for 'controller/action/9', {controller: "controller", action: "action"}, {}, {item: "square"}
297
+ #
298
+ # # Tests a route with a HTTP method
299
+ # { controller: "product", action: "update", id: "321" }.must_route_for({ method: 'put', path: '/product/321' })
300
+ #
301
+ # See also ActionController::TestCase#assert_routing
302
+ # See also ActionView::TestCase#assert_routing
303
+ # See also ActionDispatch::IntegrationTest#assert_routing
304
+ #
305
+ # :method: must_route_for
306
+ # :call-seq: options.must_route_for(path, defaults={}, extras={}, message=nil)
307
+ infect_an_assertion :assert_routing, :must_route_for
308
+
309
+ # An expectation that selects elements and makes one or more equality tests.
310
+ #
311
+ # If the first argument is an element, selects all matching elements
312
+ # starting from (and including) that element and all its children in
313
+ # depth-first order.
314
+ #
315
+ # If no element if specified, calling +must_select+ selects from the
316
+ # response HTML unless +must_select+ is called from within an +must_select+ block.
317
+ #
318
+ # When called with a block +must_select+ passes an array of selected elements
319
+ # to the block. Calling +must_select+ from the block, with no element specified,
320
+ # runs the expectation on the complete set of elements selected by the enclosing expectation.
321
+ # Alternatively the array may be iterated through so that +must_select+ can be called
322
+ # separately for each element.
323
+ #
324
+ #
325
+ # ==== Example
326
+ # If the response contains two ordered lists, each with four list elements then:
327
+ # must_select "ol" do |elements|
328
+ # elements.each do |element|
329
+ # must_select element, "li", 4
330
+ # end
331
+ # end
332
+ #
333
+ # will pass, as will:
334
+ # must_select "ol" do
335
+ # must_select "li", 8
336
+ # end
337
+ #
338
+ # The selector may be a CSS selector expression (String), an expression
339
+ # with substitution values, or an HTML::Selector object.
340
+ #
341
+ # === Equality Tests
342
+ #
343
+ # The equality test may be one of the following:
344
+ # * <tt>true</tt> - Assertion is true if at least one element selected.
345
+ # * <tt>false</tt> - Assertion is true if no element selected.
346
+ # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
347
+ # one element matches the string or regular expression.
348
+ # * <tt>Integer</tt> - Assertion is true if exactly that number of
349
+ # elements are selected.
350
+ # * <tt>Range</tt> - Assertion is true if the number of selected
351
+ # elements fit the range.
352
+ # If no equality test specified, the expectation is true if at least one
353
+ # element selected.
354
+ #
355
+ # To perform more than one equality tests, use a hash with the following keys:
356
+ # * <tt>:text</tt> - Narrow the selection to elements that have this text
357
+ # value (string or regexp).
358
+ # * <tt>:html</tt> - Narrow the selection to elements that have this HTML
359
+ # content (string or regexp).
360
+ # * <tt>:count</tt> - Assertion is true if the number of selected elements
361
+ # is equal to this value.
362
+ # * <tt>:minimum</tt> - Assertion is true if the number of selected
363
+ # elements is at least this value.
364
+ # * <tt>:maximum</tt> - Assertion is true if the number of selected
365
+ # elements is at most this value.
366
+ #
367
+ # If the method is called with a block, once all equality tests are
368
+ # evaluated the block is called with an array of all matched elements.
369
+ #
370
+ # # At least one form element
371
+ # must_select "form"
372
+ #
373
+ # # Form element includes four input fields
374
+ # must_select "form input", 4
375
+ #
376
+ # # Page title is "Welcome"
377
+ # must_select "title", "Welcome"
378
+ #
379
+ # # Page title is "Welcome" and there is only one title element
380
+ # must_select "title", {count: 1, text: "Welcome"},
381
+ # "Wrong title or more than one title element"
382
+ #
383
+ # # Page contains no forms
384
+ # must_select "form", false, "This page must contain no forms"
385
+ #
386
+ # # Test the content and style
387
+ # must_select "body div.header ul.menu"
388
+ #
389
+ # # Use substitution values
390
+ # must_select "ol>li#?", /item-\d+/
391
+ #
392
+ # # All input fields in the form have a name
393
+ # must_select "form input" do
394
+ # must_select "[name=?]", /.+/ # Not empty
395
+ # end
396
+ #
397
+ # See also ActionController::TestCase#assert_select
398
+ # See also ActionView::TestCase#assert_select
399
+ # See also ActionDispatch::IntegrationTest#assert_select
400
+ #
401
+ # :method: must_select
402
+ # :call-seq: must_select(*args, &block)
403
+
404
+ # Extracts the body of an email and runs nested expectations on it.
405
+ #
406
+ # You must enable deliveries for this expectation to work, use:
407
+ # ActionMailer::Base.perform_deliveries = true
408
+ #
409
+ # must_select_email do
410
+ # must_select "h1", "Email alert"
411
+ # end
412
+ #
413
+ # must_select_email do
414
+ # items = must_select "ol>li"
415
+ # items.each do
416
+ # # Work with items here...
417
+ # end
418
+ # end
419
+ #
420
+ # See also ActionController::TestCase#assert_select_email
421
+ # See also ActionView::TestCase#assert_select_email
422
+ # See also ActionDispatch::IntegrationTest#assert_select_email
423
+ #
424
+ # :method: must_select_email
425
+ # :call-seq: must_select_email(&block)
426
+
427
+ # Extracts the content of an element, treats it as encoded HTML and runs
428
+ # nested expectation on it.
429
+ #
430
+ # You typically call this method within another expectation to operate on
431
+ # all currently selected elements. You can also pass an element or array
432
+ # of elements.
433
+ #
434
+ # The content of each element is un-encoded, and wrapped in the root
435
+ # element +encoded+. It then calls the block with all un-encoded elements.
436
+ #
437
+ # # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)
438
+ # must_select "feed[xmlns='http://www.w3.org/2005/Atom']" do
439
+ # # Select each entry item and then the title item
440
+ # must_select "entry>title" do
441
+ # # Run expectations on the encoded title elements
442
+ # must_select_encoded do
443
+ # must_select "b"
444
+ # end
445
+ # end
446
+ # end
447
+ #
448
+ #
449
+ # # Selects all paragraph tags from within the description of an RSS feed
450
+ # must_select "rss[version=2.0]" do
451
+ # # Select description element of each feed item.
452
+ # must_select "channel>item>description" do
453
+ # # Run expectations on the encoded elements.
454
+ # must_select_encoded do
455
+ # must_select "p"
456
+ # end
457
+ # end
458
+ # end
459
+ #
460
+ # See also ActionController::TestCase#assert_select_encoded
461
+ # See also ActionView::TestCase#assert_select_encoded
462
+ # See also ActionDispatch::IntegrationTest#assert_select_encoded
463
+ #
464
+ # :method: must_select_encoded
465
+ # :call-seq: must_select_encoded(element = nil, &block)
466
+
467
+ ##
468
+ # Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values.
469
+ # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
470
+ #
471
+ # apple_link = '<a href="http://www.example.com">Apples</a>'
472
+ # link_to("Apples", "http://www.example.com").must_dom_equal apple_link
473
+ #
474
+ # See also ActionController::TestCase#assert_dom_equal
475
+ # See also ActionView::TestCase#assert_dom_equal
476
+ # See also ActionDispatch::IntegrationTest#assert_dom_equal
477
+ #
478
+ # :method: must_dom_equal
479
+ # :args: expected, message = nil
480
+ infect_an_assertion :assert_dom_equal, :must_dom_equal
481
+
482
+ ##
483
+ # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
484
+ #
485
+ # orange_link = '<a href="http://www.example.com">Oranges</a>'
486
+ # link_to("Apples", "http://www.example.com").wont_dom_equal orange_link
487
+ #
488
+ # See also ActionController::TestCase#refute_dom_equal
489
+ # See also ActionView::TestCase#refute_dom_equal
490
+ # See also ActionDispatch::IntegrationTest#refute_dom_equal
491
+ # See also ActionController::TestCase#assert_dom_not_equal
492
+ # See also ActionView::TestCase#assert_dom_not_equal
493
+ # See also ActionDispatch::IntegrationTest#assert_dom_not_equal
494
+ #
495
+ # :method: wont_dom_equal
496
+ # :args: expected, message = nil
497
+ infect_an_assertion :refute_dom_equal, :wont_dom_equal
498
+
499
+ ##
500
+ # Expects that there is a tag/node/element in the body of the response
501
+ # that meets all of the given conditions. The +conditions+ parameter must
502
+ # be a hash of any of the following keys (all are optional):
503
+ #
504
+ # * <tt>:tag</tt>: the node type must match the corresponding value
505
+ # * <tt>:attributes</tt>: a hash. The node's attributes must match the
506
+ # corresponding values in the hash.
507
+ # * <tt>:parent</tt>: a hash. The node's parent must match the
508
+ # corresponding hash.
509
+ # * <tt>:child</tt>: a hash. At least one of the node's immediate children
510
+ # must meet the criteria described by the hash.
511
+ # * <tt>:ancestor</tt>: a hash. At least one of the node's ancestors must
512
+ # meet the criteria described by the hash.
513
+ # * <tt>:descendant</tt>: a hash. At least one of the node's descendants
514
+ # must meet the criteria described by the hash.
515
+ # * <tt>:sibling</tt>: a hash. At least one of the node's siblings must
516
+ # meet the criteria described by the hash.
517
+ # * <tt>:after</tt>: a hash. The node must be after any sibling meeting
518
+ # the criteria described by the hash, and at least one sibling must match.
519
+ # * <tt>:before</tt>: a hash. The node must be before any sibling meeting
520
+ # the criteria described by the hash, and at least one sibling must match.
521
+ # * <tt>:children</tt>: a hash, for counting children of a node. Accepts
522
+ # the keys:
523
+ # * <tt>:count</tt>: either a number or a range which must equal (or
524
+ # include) the number of children that match.
525
+ # * <tt>:less_than</tt>: the number of matching children must be less
526
+ # than this number.
527
+ # * <tt>:greater_than</tt>: the number of matching children must be
528
+ # greater than this number.
529
+ # * <tt>:only</tt>: another hash consisting of the keys to use
530
+ # to match on the children, and only matching children will be
531
+ # counted.
532
+ # * <tt>:content</tt>: the textual content of the node must match the
533
+ # given value. This will not match HTML tags in the body of a
534
+ # tag--only text.
535
+ #
536
+ # Conditions are matched using the following algorithm:
537
+ #
538
+ # * if the condition is a string, it must be a substring of the value.
539
+ # * if the condition is a regexp, it must match the value.
540
+ # * if the condition is a number, the value must match number.to_s.
541
+ # * if the condition is +true+, the value must not be +nil+.
542
+ # * if the condition is +false+ or +nil+, the value must be +nil+.
543
+ #
544
+ # # Expect that there is a "span" tag
545
+ # must_have_tag tag: "span"
546
+ #
547
+ # # Expect that there is a "span" tag with id="x"
548
+ # must_have_tag tag: "span", attributes: { id: "x" }
549
+ #
550
+ # # Expect that there is a "span" tag using the short-hand
551
+ # must_have_tag :span
552
+ #
553
+ # # Expect that there is a "span" tag with id="x" using the short-hand
554
+ # must_have_tag :span, attributes: { id: "x" }
555
+ #
556
+ # # Expect that there is a "span" inside of a "div"
557
+ # must_have_tag tag: "span", parent: { tag: "div" }
558
+ #
559
+ # # Expect that there is a "span" somewhere inside a table
560
+ # must_have_tag tag: "span", ancestor: { tag: "table" }
561
+ #
562
+ # # Expect that there is a "span" with at least one "em" child
563
+ # must_have_tag tag: "span", child: { tag: "em" }
564
+ #
565
+ # # Expect that there is a "span" containing a (possibly nested)
566
+ # # "strong" tag.
567
+ # must_have_tag tag: "span", descendant: { tag: "strong" }
568
+ #
569
+ # # Expect that there is a "span" containing between 2 and 4 "em" tags
570
+ # # as immediate children
571
+ # must_have_tag tag: "span",
572
+ # children: { count: 2..4, only: { tag: "em" } }
573
+ #
574
+ # # Get funky: assert that there is a "div", with an "ul" ancestor
575
+ # # and an "li" parent (with "class" = "enum"), and containing a
576
+ # # "span" descendant that contains text matching /hello world/
577
+ # must_have_tag tag: "div",
578
+ # ancestor: { tag: "ul" },
579
+ # parent: { tag: "li",
580
+ # attributes: { class: "enum" } },
581
+ # descendant: { tag: "span",
582
+ # child: /hello world/ }
583
+ #
584
+ # <b>Please note</b>: +must_have_tag+ and +wont_have_tag+ only work
585
+ # with well-formed XHTML. They recognize a few tags as implicitly self-closing
586
+ # (like br and hr and such) but will not work correctly with tags
587
+ # that allow optional closing tags (p, li, td). <em>You must explicitly
588
+ # close all of your tags to use these assertions.</em>
589
+ #
590
+ # See also ActionController::TestCase#assert_tag
591
+ # See also ActionView::TestCase#assert_tag
592
+ # See also ActionDispatch::IntegrationTest#assert_tag
593
+ #
594
+ # :method: must_have_tag
595
+ # :call-seq: must_have_tag(*opts)
596
+
597
+ ##
598
+ # Identical to +must_have_tag+, but asserts that a matching tag does _not_
599
+ # exist. (See +must_have_tag+ for a full discussion of the syntax.)
600
+ #
601
+ # # Expect that there is not a "div" containing a "p"
602
+ # wont_have_tag tag: "div", descendant: { tag: "p" }
603
+ #
604
+ # # Expect that an unordered list is empty
605
+ # wont_have_tag tag: "ul", descendant: { tag: "li" }
606
+ #
607
+ # # Expect that there is not a "p" tag with between 1 to 3 "img" tags
608
+ # # as immediate children
609
+ # wont_have_tag tag: "p",
610
+ # children: { count: 1..3, only: { tag: "img" } }
611
+ #
612
+ # See also ActionController::TestCase#refute_tag
613
+ # See also ActionView::TestCase#refute_tag
614
+ # See also ActionDispatch::IntegrationTest#refute_tag
615
+ # See also ActionController::TestCase#assert_no_tag
616
+ # See also ActionView::TestCase#assert_no_tag
617
+ # See also ActionDispatch::IntegrationTest#assert_no_tag
618
+ #
619
+ # :method: wont_have_tag
620
+ # :call-seq: wont_have_tag(*opts)
621
+ end
622
+
623
+ unless ENV["MT_NO_EXPECTATIONS"]
624
+ class Object # :nodoc:
625
+ include MiniTest::Rails::Expectations
626
+ end
627
+ # Not real expectations, just aliases
628
+ # The error messages don't get messed up this way
629
+ class ActionController::TestCase # :nodoc:
630
+ alias :must_respond_with :assert_response
631
+ alias :must_redirect_to :assert_redirected_to
632
+ alias :must_render_template :assert_template
633
+ alias :must_have_tag :assert_tag
634
+ alias :wont_have_tag :assert_no_tag
635
+ alias :must_select :assert_select
636
+ alias :must_select_email :assert_select_email
637
+ alias :must_select_encoded :assert_select_encoded
638
+ end
639
+ class ActionView::TestCase # :nodoc:
640
+ alias :must_respond_with :assert_response
641
+ alias :must_redirect_to :assert_redirected_to
642
+ alias :must_render_template :assert_template
643
+ alias :must_have_tag :assert_tag
644
+ alias :wont_have_tag :assert_no_tag
645
+ alias :must_select :assert_select
646
+ alias :must_select_email :assert_select_email
647
+ alias :must_select_encoded :assert_select_encoded
648
+ end
649
+ class ActionDispatch::IntegrationTest # :nodoc:
650
+ alias :must_respond_with :assert_response
651
+ alias :must_redirect_to :assert_redirected_to
652
+ alias :must_render_template :assert_template
653
+ alias :must_have_tag :assert_tag
654
+ alias :wont_have_tag :assert_no_tag
655
+ alias :must_select :assert_select
656
+ alias :must_select_email :assert_select_email
657
+ alias :must_select_encoded :assert_select_encoded
658
+ end
659
+ end
@@ -0,0 +1,18 @@
1
+ require "minitest/rails"
2
+ require "rails/generators/test_case"
3
+
4
+ class Rails::Generators::TestCase
5
+ register_spec_type(self) do |desc|
6
+ Class === desc && desc < Rails::Generators::Base
7
+ end
8
+
9
+ register_spec_type(/Generator( ?Test)?\z/i, self)
10
+
11
+ def self.determine_default_generator(name)
12
+ generator = determine_constant_from_test_name(name) do |constant|
13
+ Class === constant && constant < Rails::Generators::Base
14
+ end
15
+ raise NameError.new("Unable to resolve generator for #{name}") if generator.nil?
16
+ generator
17
+ end
18
+ end
@@ -2,7 +2,7 @@ require "rails"
2
2
 
3
3
  module MiniTest
4
4
  module Rails
5
- class Railtie < ::Rails::Railtie
5
+ class Railtie < ::Rails::Railtie # :nodoc:
6
6
  generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
7
7
  generators.integration_tool :mini_test
8
8
  generators.test_framework :mini_test
File without changes