minitest-rails 3.0.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +1 -1
  4. data/README.md +117 -0
  5. data/UPDATING.md +31 -0
  6. data/lib/generators/minitest.rb +17 -4
  7. data/lib/generators/minitest/controller/controller_generator.rb +6 -9
  8. data/lib/generators/minitest/controller/templates/{controller_spec.rb → functional_spec.rb.tt} +4 -4
  9. data/lib/generators/minitest/controller/templates/{controller_test.rb → functional_test.rb.tt} +3 -3
  10. data/lib/generators/minitest/generator/generator_generator.rb +3 -8
  11. data/lib/generators/minitest/generator/templates/{generator_spec.rb → generator_spec.rb.tt} +2 -2
  12. data/lib/generators/minitest/generator/templates/{generator_test.rb → generator_test.rb.tt} +1 -2
  13. data/lib/generators/minitest/helper/helper_generator.rb +5 -3
  14. data/lib/generators/minitest/install/install_generator.rb +21 -8
  15. data/lib/generators/minitest/install/templates/test/application_system_test_case.rb.tt +10 -0
  16. data/lib/generators/minitest/install/templates/test/channels/application_cable/connection_test.rb.tt +23 -0
  17. data/lib/generators/minitest/install/templates/test/test_helper.rb.tt +23 -0
  18. data/lib/generators/minitest/integration/integration_generator.rb +12 -9
  19. data/lib/generators/minitest/integration/templates/integration_spec.rb.tt +9 -0
  20. data/lib/generators/minitest/integration/templates/integration_test.rb.tt +9 -0
  21. data/lib/generators/minitest/job/job_generator.rb +13 -10
  22. data/lib/generators/minitest/job/templates/unit_spec.rb.tt +9 -0
  23. data/lib/generators/minitest/job/templates/{job_test.rb → unit_test.rb.tt} +3 -3
  24. data/lib/generators/minitest/mailer/mailer_generator.rb +8 -11
  25. data/lib/generators/minitest/mailer/templates/functional_spec.rb.tt +21 -0
  26. data/lib/generators/minitest/mailer/templates/{mailer_test.rb → functional_test.rb.tt} +3 -3
  27. data/lib/generators/minitest/mailer/templates/{preview.rb → preview.rb.tt} +0 -0
  28. data/lib/generators/minitest/model/model_generator.rb +9 -12
  29. data/lib/generators/minitest/model/templates/{fixtures.yml → fixtures.yml.tt} +3 -3
  30. data/lib/generators/minitest/model/templates/unit_spec.rb.tt +9 -0
  31. data/lib/generators/minitest/model/templates/unit_test.rb.tt +9 -0
  32. data/lib/generators/minitest/plugin/plugin_generator.rb +15 -0
  33. data/lib/generators/minitest/plugin/templates/%file_name%_test.rb.tt +15 -0
  34. data/lib/generators/minitest/plugin/templates/test_helper.rb +2 -0
  35. data/lib/generators/minitest/scaffold/scaffold_generator.rb +28 -23
  36. data/lib/generators/minitest/scaffold/templates/api_functional_spec.rb.tt +42 -0
  37. data/lib/generators/minitest/scaffold/templates/api_functional_test.rb.tt +44 -0
  38. data/lib/generators/minitest/scaffold/templates/functional_spec.rb.tt +52 -0
  39. data/lib/generators/minitest/scaffold/templates/{controller_test.rb → functional_test.rb.tt} +16 -16
  40. data/lib/generators/minitest/scaffold/templates/system_spec.rb.tt +55 -0
  41. data/lib/generators/minitest/scaffold/templates/system_test.rb.tt +57 -0
  42. data/lib/generators/minitest/system/system_generator.rb +25 -0
  43. data/lib/generators/minitest/system/templates/application_system_test_case.rb.tt +10 -0
  44. data/lib/generators/minitest/system/templates/system_spec.rb.tt +9 -0
  45. data/lib/generators/minitest/system/templates/system_test.rb.tt +9 -0
  46. data/lib/minitest/rails.rb +76 -105
  47. data/lib/minitest/rails/assertions.rb +6 -906
  48. data/lib/minitest/rails/assertions/action_cable.rb +232 -0
  49. data/lib/minitest/rails/assertions/action_dispatch.rb +356 -0
  50. data/lib/minitest/rails/assertions/action_mailer.rb +153 -0
  51. data/lib/minitest/rails/assertions/action_view.rb +356 -0
  52. data/lib/minitest/rails/assertions/active_job.rb +151 -0
  53. data/lib/minitest/rails/assertions/active_support.rb +57 -0
  54. data/lib/minitest/rails/capybara.rb +17 -0
  55. data/lib/minitest/rails/expectations.rb +5 -565
  56. data/lib/minitest/rails/expectations/action_cable.rb +197 -0
  57. data/lib/minitest/rails/expectations/action_dispatch.rb +307 -0
  58. data/lib/minitest/rails/expectations/action_mailer.rb +175 -0
  59. data/lib/minitest/rails/expectations/active_job.rb +182 -0
  60. data/lib/minitest/rails/expectations/active_support.rb +73 -0
  61. data/lib/minitest/rails/parallelize.rb +41 -0
  62. data/lib/minitest/rails/railtie.rb +3 -2
  63. data/lib/minitest/rails/version.rb +1 -1
  64. metadata +87 -92
  65. data/.autotest +0 -23
  66. data/.gemtest +0 -0
  67. data/.travis.yml +0 -25
  68. data/CHANGELOG.rdoc +0 -223
  69. data/Gemfile +0 -7
  70. data/Manifest.txt +0 -76
  71. data/README.rdoc +0 -110
  72. data/Rakefile +0 -30
  73. data/gemfiles/5.0.gemfile +0 -5
  74. data/gemfiles/head.gemfile +0 -5
  75. data/lib/generators/.document +0 -0
  76. data/lib/generators/minitest/install/templates/test_helper.rb +0 -19
  77. data/lib/generators/minitest/integration/templates/integration_spec.rb +0 -8
  78. data/lib/generators/minitest/integration/templates/integration_test.rb +0 -7
  79. data/lib/generators/minitest/job/templates/job_spec.rb +0 -9
  80. data/lib/generators/minitest/mailer/templates/mailer_spec.rb +0 -20
  81. data/lib/generators/minitest/model/templates/model_spec.rb +0 -11
  82. data/lib/generators/minitest/model/templates/model_test.rb +0 -13
  83. data/lib/generators/minitest/scaffold/templates/api_controller_spec.rb +0 -42
  84. data/lib/generators/minitest/scaffold/templates/api_controller_test.rb +0 -44
  85. data/lib/generators/minitest/scaffold/templates/controller_spec.rb +0 -52
  86. data/lib/minitest/rails/constant_lookup.rb +0 -52
  87. data/lib/minitest/rails/controller.rb +0 -14
  88. data/minitest-rails.gemspec +0 -48
  89. data/tasks/test.rake +0 -29
  90. data/test/generators/test_controller_generator.rb +0 -58
  91. data/test/generators/test_generator_generator.rb +0 -58
  92. data/test/generators/test_helper_generator.rb +0 -34
  93. data/test/generators/test_install_generator.rb +0 -27
  94. data/test/generators/test_job_generator.rb +0 -45
  95. data/test/generators/test_mailer_generator.rb +0 -42
  96. data/test/generators/test_model_generator.rb +0 -80
  97. data/test/generators/test_scaffold_generator.rb +0 -26
  98. data/test/helper.rb +0 -93
  99. data/test/rails/action_dispatch/test_assertions.rb +0 -39
  100. data/test/rails/action_dispatch/test_expectations.rb +0 -39
  101. data/test/rails/action_dispatch/test_spec_type.rb +0 -49
  102. data/test/rails/action_mailer/test_mailers.rb +0 -109
  103. data/test/rails/action_mailer/test_spec_type.rb +0 -47
  104. data/test/rails/action_view/test_helpers.rb +0 -73
  105. data/test/rails/action_view/test_spec_type.rb +0 -58
  106. data/test/rails/active_job/test_assertions.rb +0 -46
  107. data/test/rails/active_job/test_expectations.rb +0 -55
  108. data/test/rails/active_job/test_spec_type.rb +0 -49
  109. data/test/rails/active_support/test_assertions.rb +0 -31
  110. data/test/rails/active_support/test_expectations.rb +0 -21
  111. data/test/rails/active_support/test_spec_type.rb +0 -28
  112. data/test/rails/generators/test_spec_type.rb +0 -45
  113. data/test/rails/test_constant_lookup.rb +0 -58
  114. data/test/test_sanity.rb +0 -7
@@ -1,906 +1,6 @@
1
- class ActiveSupport::TestCase
2
- ##
3
- # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
4
- #
5
- # assert_difference "User.count", +1 do
6
- # User.create
7
- # end
8
- #
9
- # See also Minitest::Rails::Expectations#must_change
10
- #
11
- # :method: assert_difference
12
- # :call-seq: assert_difference(expression, difference = 1, message = nil, &block)
13
-
14
- ##
15
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
16
- #
17
- # assert_no_difference "User.count" do
18
- # User.new
19
- # end
20
- #
21
- # See also Minitest::Rails::Expectations#wont_change
22
- #
23
- # :method: assert_no_difference
24
- # :call-seq: assert_no_difference(expression, message = nil, &block)
25
-
26
- ##
27
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
28
- #
29
- # refute_difference "User.count", do
30
- # User.new
31
- # end
32
- #
33
- # See also Minitest::Rails::Expectations#wont_change
34
- #
35
- # :args: expression, message = nil, &block
36
- alias :refute_difference :assert_no_difference
37
-
38
- end
39
-
40
- class ActionView::TestCase
41
- ##
42
- # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
43
- #
44
- # assert_difference "User.count", +1 do
45
- # User.create
46
- # end
47
- #
48
- # See also Minitest::Rails::Expectations#must_change
49
- #
50
- # :method: assert_difference
51
- # :call-seq: assert_difference(expression, difference = 1, message = nil, &block)
52
-
53
- ##
54
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
55
- #
56
- # assert_no_difference "User.count" do
57
- # User.new
58
- # end
59
- #
60
- # See also Minitest::Rails::Expectations#wont_change
61
- #
62
- # :method: assert_no_difference
63
- # :call-seq: assert_no_difference(expression, message = nil, &block)
64
-
65
- ##
66
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
67
- #
68
- # refute_difference "User.count", do
69
- # User.new
70
- # end
71
- #
72
- # See also Minitest::Rails::Expectations#wont_change
73
- #
74
- # :args: expression, message = nil, &block
75
- alias :refute_difference :assert_no_difference
76
-
77
- # Asserts that the response is one of the following types:
78
- #
79
- # * <tt>:success</tt> - Status code was in the 200-299 range
80
- # * <tt>:redirect</tt> - Status code was in the 300-399 range
81
- # * <tt>:missing</tt> - Status code was 404
82
- # * <tt>:error</tt> - Status code was in the 500-599 range
83
- #
84
- # You can also pass an explicit status number like <tt>assert_response(501)</tt>
85
- # or its symbolic equivalent <tt>assert_response(:not_implemented)</tt>.
86
- # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list.
87
- #
88
- # # assert that the response was a redirection
89
- # assert_response :redirect
90
- #
91
- # # assert that the response code was status code 401 (unauthorized)
92
- # assert_response 401
93
- #
94
- # See also Minitest::Rails::Expectations#must_respond_with
95
- #
96
- # :method: assert_response
97
- # :call-seq: assert_response(type, message = nil)
98
-
99
- ##
100
- # Assert that the redirection options passed in match those of the redirect called in the latest action.
101
- # This match can be partial, such that <tt>assert_redirected_to(controller: "weblog")</tt> will also
102
- # match the redirection of <tt>redirect_to(controller: "weblog", action: "show")</tt> and so on.
103
- #
104
- # # assert that the redirection was to the "index" action on the WeblogController
105
- # assert_redirected_to controller: "weblog", action: "index"
106
- #
107
- # # assert that the redirection was to the named route login_url
108
- # assert_redirected_to login_url
109
- #
110
- # # assert that the redirection was to the url for @customer
111
- # assert_redirected_to @customer
112
- #
113
- # # asserts that the redirection matches the regular expression
114
- # assert_redirected_to %r(\Ahttp://example.org)
115
- #
116
- # See also Minitest::Rails::Expectations#must_redirect_to
117
- #
118
- # :method: assert_redirected_to
119
- # :call-seq: assert_redirected_to(options = {}, message=nil)
120
-
121
- ##
122
- # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
123
- # The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
124
- # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
125
- #
126
- # The +defaults+ parameter is unused.
127
- #
128
- # # Asserts that the default action is generated for a route with no action
129
- # assert_generates "/items", controller: "items", action: "index"
130
- #
131
- # # Tests that the list action is properly routed
132
- # assert_generates "/items/list", controller: "items", action: "list"
133
- #
134
- # # Tests the generation of a route with a parameter
135
- # assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
136
- #
137
- # # Asserts that the generated route gives us our custom route
138
- # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
139
- #
140
- # See also Minitest::Rails::Expectations#must_route_to
141
- #
142
- # :method: assert_generates
143
- # :call-seq: assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
144
-
145
- ##
146
- # Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
147
- # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
148
- #
149
- # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
150
- # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
151
- # and a :method containing the required HTTP verb.
152
- #
153
- # # assert that POSTing to /items will call the create action on ItemsController
154
- # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
155
- #
156
- # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
157
- # 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
158
- # extras argument, appending the query string on the path directly will not work. For example:
159
- #
160
- # # assert that a path of '/items/list/1?view=print' returns the correct options
161
- # assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
162
- #
163
- # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
164
- #
165
- # # Check the default route (i.e., the index action)
166
- # assert_recognizes({controller: 'items', action: 'index'}, 'items')
167
- #
168
- # # Test a specific action
169
- # assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
170
- #
171
- # # Test an action with a parameter
172
- # assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
173
- #
174
- # # Test a custom route
175
- # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
176
- #
177
- # See also Minitest::Rails::Expectations#must_route_from
178
- #
179
- # :method: assert_recognizes
180
- # :call-seq: assert_recognizes(expected_options, path, extras={}, msg=nil)
181
-
182
- ##
183
- # Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
184
- # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
185
- # and +assert_generates+ into one step.
186
- #
187
- # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
188
- # +message+ parameter allows you to specify a custom error message to display upon failure.
189
- #
190
- # # Assert a basic route: a controller with the default action (index)
191
- # assert_routing '/home', controller: 'home', action: 'index'
192
- #
193
- # # Test a route generated with a specific controller, action, and parameter (id)
194
- # assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
195
- #
196
- # # Assert a basic route (controller + default action), with an error message if it fails
197
- # assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
198
- #
199
- # # Tests a route, providing a defaults hash
200
- # assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
201
- #
202
- # # Tests a route with a HTTP method
203
- # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
204
- #
205
- # See also Minitest::Rails::Expectations#must_route
206
- #
207
- # :method: assert_routing
208
- # :call-seq: assert_routing(path, options, defaults={}, extras={}, message=nil)
209
-
210
- # An assertion that selects elements and makes one or more equality tests.
211
- #
212
- # If the first argument is an element, selects all matching elements
213
- # starting from (and including) that element and all its children in
214
- # depth-first order.
215
- #
216
- # If no element if specified, calling +assert_select+ selects from the
217
- # response HTML unless +assert_select+ is called from within an +assert_select+ block.
218
- #
219
- # When called with a block +assert_select+ passes an array of selected elements
220
- # to the block. Calling +assert_select+ from the block, with no element specified,
221
- # runs the assertion on the complete set of elements selected by the enclosing assertion.
222
- # Alternatively the array may be iterated through so that +assert_select+ can be called
223
- # separately for each element.
224
- #
225
- #
226
- # ==== Example
227
- # If the response contains two ordered lists, each with four list elements then:
228
- # assert_select "ol" do |elements|
229
- # elements.each do |element|
230
- # assert_select element, "li", 4
231
- # end
232
- # end
233
- #
234
- # will pass, as will:
235
- # assert_select "ol" do
236
- # assert_select "li", 8
237
- # end
238
- #
239
- # The selector may be a CSS selector expression (String), an expression
240
- # with substitution values, or an HTML::Selector object.
241
- #
242
- # === Equality Tests
243
- #
244
- # The equality test may be one of the following:
245
- # * <tt>true</tt> - Assertion is true if at least one element selected.
246
- # * <tt>false</tt> - Assertion is true if no element selected.
247
- # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
248
- # one element matches the string or regular expression.
249
- # * <tt>Integer</tt> - Assertion is true if exactly that number of
250
- # elements are selected.
251
- # * <tt>Range</tt> - Assertion is true if the number of selected
252
- # elements fit the range.
253
- # If no equality test specified, the assertion is true if at least one
254
- # element selected.
255
- #
256
- # To perform more than one equality tests, use a hash with the following keys:
257
- # * <tt>:text</tt> - Narrow the selection to elements that have this text
258
- # value (string or regexp).
259
- # * <tt>:html</tt> - Narrow the selection to elements that have this HTML
260
- # content (string or regexp).
261
- # * <tt>:count</tt> - Assertion is true if the number of selected elements
262
- # is equal to this value.
263
- # * <tt>:minimum</tt> - Assertion is true if the number of selected
264
- # elements is at least this value.
265
- # * <tt>:maximum</tt> - Assertion is true if the number of selected
266
- # elements is at most this value.
267
- #
268
- # If the method is called with a block, once all equality tests are
269
- # evaluated the block is called with an array of all matched elements.
270
- #
271
- # # At least one form element
272
- # assert_select "form"
273
- #
274
- # # Form element includes four input fields
275
- # assert_select "form input", 4
276
- #
277
- # # Page title is "Welcome"
278
- # assert_select "title", "Welcome"
279
- #
280
- # # Page title is "Welcome" and there is only one title element
281
- # assert_select "title", {count: 1, text: "Welcome"},
282
- # "Wrong title or more than one title element"
283
- #
284
- # # Page contains no forms
285
- # assert_select "form", false, "This page must contain no forms"
286
- #
287
- # # Test the content and style
288
- # assert_select "body div.header ul.menu"
289
- #
290
- # # Use substitution values
291
- # assert_select "ol>li#?", /item-\d+/
292
- #
293
- # # All input fields in the form have a name
294
- # assert_select "form input" do
295
- # assert_select "[name=?]", /.+/ # Not empty
296
- # end
297
- #
298
- # See also Minitest::Rails::Expectations#must_select
299
- #
300
- # :method: assert_select
301
- # :call-seq: assert_select(*args, &block)
302
-
303
- # Extracts the body of an email and runs nested assertions on it.
304
- #
305
- # You must enable deliveries for this assertion to work, use:
306
- # ActionMailer::Base.perform_deliveries = true
307
- #
308
- # assert_select_email do
309
- # assert_select "h1", "Email alert"
310
- # end
311
- #
312
- # assert_select_email do
313
- # items = assert_select "ol>li"
314
- # items.each do
315
- # # Work with items here...
316
- # end
317
- # end
318
- #
319
- # See also Minitest::Rails::Expectations#must_select_email
320
- #
321
- # :method: assert_select_email
322
- # :call-seq: assert_select_email(&block)
323
-
324
- # Extracts the content of an element, treats it as encoded HTML and runs
325
- # nested assertion on it.
326
- #
327
- # You typically call this method within another assertion to operate on
328
- # all currently selected elements. You can also pass an element or array
329
- # of elements.
330
- #
331
- # The content of each element is un-encoded, and wrapped in the root
332
- # element +encoded+. It then calls the block with all un-encoded elements.
333
- #
334
- # # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)
335
- # assert_select "feed[xmlns='http://www.w3.org/2005/Atom']" do
336
- # # Select each entry item and then the title item
337
- # assert_select "entry>title" do
338
- # # Run assertions on the encoded title elements
339
- # assert_select_encoded do
340
- # assert_select "b"
341
- # end
342
- # end
343
- # end
344
- #
345
- #
346
- # # Selects all paragraph tags from within the description of an RSS feed
347
- # assert_select "rss[version=2.0]" do
348
- # # Select description element of each feed item.
349
- # assert_select "channel>item>description" do
350
- # # Run assertions on the encoded elements.
351
- # assert_select_encoded do
352
- # assert_select "p"
353
- # end
354
- # end
355
- # end
356
- #
357
- # See also Minitest::Rails::Expectations#must_select_encoded
358
- #
359
- # :method: assert_select_encoded
360
- # :call-seq: assert_select_encoded(element = nil, &block)
361
-
362
- ##
363
- # Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values.
364
- #
365
- # assert_dom_equal '<a href="http://www.example.com">Apples</a>',
366
- # link_to("Apples", "http://www.example.com")
367
- #
368
- # See also Minitest::Rails::Expectations#must_dom_equal
369
- #
370
- # :method: assert_dom_equal
371
- # :call-seq: assert_dom_equal(expected, actual, message = nil)
372
-
373
- ##
374
- # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
375
- #
376
- # assert_dom_not_equal '<a href="http://www.example.com">Oranges</a>',
377
- # link_to("Apples", "http://www.example.com")
378
- #
379
- # See also Minitest::Rails::Expectations#wont_dom_equal
380
- #
381
- # :method: assert_dom_not_equal
382
- # :call-seq: assert_dom_not_equal(expected, actual, message = nil)
383
-
384
- ##
385
- # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
386
- #
387
- # refute_dom_equal '<a href="http://www.example.com">Oranges</a>',
388
- # link_to("Apples", "http://www.example.com")
389
- #
390
- # See also Minitest::Rails::Expectations#wont_dom_equal
391
- #
392
- # :method: assert_dom_equal
393
- # :call-seq: assert_dom_equal(expected, actual, message = nil)
394
- alias :refute_dom_equal :assert_dom_not_equal
395
- end
396
-
397
- class ActionDispatch::IntegrationTest
398
- ##
399
- # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
400
- #
401
- # assert_difference "User.count", +1 do
402
- # User.create
403
- # end
404
- #
405
- # See also Minitest::Rails::Expectations#must_change
406
- #
407
- # :method: assert_difference
408
- # :call-seq: assert_difference(expression, difference = 1, message = nil, &block)
409
-
410
- ##
411
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
412
- #
413
- # assert_no_difference "User.count" do
414
- # User.new
415
- # end
416
- #
417
- # See also Minitest::Rails::Expectations#wont_change
418
- #
419
- # :method: assert_no_difference
420
- # :call-seq: assert_no_difference(expression, message = nil, &block)
421
-
422
- ##
423
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
424
- #
425
- # refute_difference "User.count", do
426
- # User.new
427
- # end
428
- #
429
- # See also Minitest::Rails::Expectations#wont_change
430
- #
431
- # :args: expression, message = nil, &block
432
- alias :refute_difference :assert_no_difference
433
-
434
- # Asserts that the response is one of the following types:
435
- #
436
- # * <tt>:success</tt> - Status code was in the 200-299 range
437
- # * <tt>:redirect</tt> - Status code was in the 300-399 range
438
- # * <tt>:missing</tt> - Status code was 404
439
- # * <tt>:error</tt> - Status code was in the 500-599 range
440
- #
441
- # You can also pass an explicit status number like <tt>assert_response(501)</tt>
442
- # or its symbolic equivalent <tt>assert_response(:not_implemented)</tt>.
443
- # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list.
444
- #
445
- # # assert that the response was a redirection
446
- # assert_response :redirect
447
- #
448
- # # assert that the response code was status code 401 (unauthorized)
449
- # assert_response 401
450
- #
451
- # See also Minitest::Rails::Expectations#must_respond_with
452
- #
453
- # :method: assert_response
454
- # :call-seq: assert_response(type, message = nil)
455
-
456
- ##
457
- # Assert that the redirection options passed in match those of the redirect called in the latest action.
458
- # This match can be partial, such that <tt>assert_redirected_to(controller: "weblog")</tt> will also
459
- # match the redirection of <tt>redirect_to(controller: "weblog", action: "show")</tt> and so on.
460
- #
461
- # # assert that the redirection was to the "index" action on the WeblogController
462
- # assert_redirected_to controller: "weblog", action: "index"
463
- #
464
- # # assert that the redirection was to the named route login_url
465
- # assert_redirected_to login_url
466
- #
467
- # # assert that the redirection was to the url for @customer
468
- # assert_redirected_to @customer
469
- #
470
- # # asserts that the redirection matches the regular expression
471
- # assert_redirected_to %r(\Ahttp://example.org)
472
- #
473
- # See also Minitest::Rails::Expectations#must_redirect_to
474
- #
475
- # :method: assert_redirected_to
476
- # :call-seq: assert_redirected_to(options = {}, message=nil)
477
-
478
- ##
479
- # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
480
- # The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
481
- # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
482
- #
483
- # The +defaults+ parameter is unused.
484
- #
485
- # # Asserts that the default action is generated for a route with no action
486
- # assert_generates "/items", controller: "items", action: "index"
487
- #
488
- # # Tests that the list action is properly routed
489
- # assert_generates "/items/list", controller: "items", action: "list"
490
- #
491
- # # Tests the generation of a route with a parameter
492
- # assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
493
- #
494
- # # Asserts that the generated route gives us our custom route
495
- # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
496
- #
497
- # See also Minitest::Rails::Expectations#must_route_to
498
- #
499
- # :method: assert_generates
500
- # :call-seq: assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
501
-
502
- ##
503
- # Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
504
- # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
505
- #
506
- # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
507
- # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
508
- # and a :method containing the required HTTP verb.
509
- #
510
- # # assert that POSTing to /items will call the create action on ItemsController
511
- # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
512
- #
513
- # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
514
- # 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
515
- # extras argument, appending the query string on the path directly will not work. For example:
516
- #
517
- # # assert that a path of '/items/list/1?view=print' returns the correct options
518
- # assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
519
- #
520
- # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
521
- #
522
- # # Check the default route (i.e., the index action)
523
- # assert_recognizes({controller: 'items', action: 'index'}, 'items')
524
- #
525
- # # Test a specific action
526
- # assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
527
- #
528
- # # Test an action with a parameter
529
- # assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
530
- #
531
- # # Test a custom route
532
- # assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
533
- #
534
- # See also Minitest::Rails::Expectations#must_route_from
535
- #
536
- # :method: assert_recognizes
537
- # :call-seq: assert_recognizes(expected_options, path, extras={}, msg=nil)
538
-
539
- ##
540
- # Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
541
- # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
542
- # and +assert_generates+ into one step.
543
- #
544
- # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
545
- # +message+ parameter allows you to specify a custom error message to display upon failure.
546
- #
547
- # # Assert a basic route: a controller with the default action (index)
548
- # assert_routing '/home', controller: 'home', action: 'index'
549
- #
550
- # # Test a route generated with a specific controller, action, and parameter (id)
551
- # assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
552
- #
553
- # # Assert a basic route (controller + default action), with an error message if it fails
554
- # assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
555
- #
556
- # # Tests a route, providing a defaults hash
557
- # assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
558
- #
559
- # # Tests a route with a HTTP method
560
- # assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
561
- #
562
- # See also Minitest::Rails::Expectations#must_route
563
- #
564
- # :method: assert_routing
565
- # :call-seq: assert_routing(path, options, defaults={}, extras={}, message=nil)
566
-
567
- # An assertion that selects elements and makes one or more equality tests.
568
- #
569
- # If the first argument is an element, selects all matching elements
570
- # starting from (and including) that element and all its children in
571
- # depth-first order.
572
- #
573
- # If no element if specified, calling +assert_select+ selects from the
574
- # response HTML unless +assert_select+ is called from within an +assert_select+ block.
575
- #
576
- # When called with a block +assert_select+ passes an array of selected elements
577
- # to the block. Calling +assert_select+ from the block, with no element specified,
578
- # runs the assertion on the complete set of elements selected by the enclosing assertion.
579
- # Alternatively the array may be iterated through so that +assert_select+ can be called
580
- # separately for each element.
581
- #
582
- #
583
- # ==== Example
584
- # If the response contains two ordered lists, each with four list elements then:
585
- # assert_select "ol" do |elements|
586
- # elements.each do |element|
587
- # assert_select element, "li", 4
588
- # end
589
- # end
590
- #
591
- # will pass, as will:
592
- # assert_select "ol" do
593
- # assert_select "li", 8
594
- # end
595
- #
596
- # The selector may be a CSS selector expression (String), an expression
597
- # with substitution values, or an HTML::Selector object.
598
- #
599
- # === Equality Tests
600
- #
601
- # The equality test may be one of the following:
602
- # * <tt>true</tt> - Assertion is true if at least one element selected.
603
- # * <tt>false</tt> - Assertion is true if no element selected.
604
- # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
605
- # one element matches the string or regular expression.
606
- # * <tt>Integer</tt> - Assertion is true if exactly that number of
607
- # elements are selected.
608
- # * <tt>Range</tt> - Assertion is true if the number of selected
609
- # elements fit the range.
610
- # If no equality test specified, the assertion is true if at least one
611
- # element selected.
612
- #
613
- # To perform more than one equality tests, use a hash with the following keys:
614
- # * <tt>:text</tt> - Narrow the selection to elements that have this text
615
- # value (string or regexp).
616
- # * <tt>:html</tt> - Narrow the selection to elements that have this HTML
617
- # content (string or regexp).
618
- # * <tt>:count</tt> - Assertion is true if the number of selected elements
619
- # is equal to this value.
620
- # * <tt>:minimum</tt> - Assertion is true if the number of selected
621
- # elements is at least this value.
622
- # * <tt>:maximum</tt> - Assertion is true if the number of selected
623
- # elements is at most this value.
624
- #
625
- # If the method is called with a block, once all equality tests are
626
- # evaluated the block is called with an array of all matched elements.
627
- #
628
- # # At least one form element
629
- # assert_select "form"
630
- #
631
- # # Form element includes four input fields
632
- # assert_select "form input", 4
633
- #
634
- # # Page title is "Welcome"
635
- # assert_select "title", "Welcome"
636
- #
637
- # # Page title is "Welcome" and there is only one title element
638
- # assert_select "title", {count: 1, text: "Welcome"},
639
- # "Wrong title or more than one title element"
640
- #
641
- # # Page contains no forms
642
- # assert_select "form", false, "This page must contain no forms"
643
- #
644
- # # Test the content and style
645
- # assert_select "body div.header ul.menu"
646
- #
647
- # # Use substitution values
648
- # assert_select "ol>li#?", /item-\d+/
649
- #
650
- # # All input fields in the form have a name
651
- # assert_select "form input" do
652
- # assert_select "[name=?]", /.+/ # Not empty
653
- # end
654
- #
655
- # See also Minitest::Rails::Expectations#must_select
656
- #
657
- # :method: assert_select
658
- # :call-seq: assert_select(*args, &block)
659
-
660
- # Extracts the body of an email and runs nested assertions on it.
661
- #
662
- # You must enable deliveries for this assertion to work, use:
663
- # ActionMailer::Base.perform_deliveries = true
664
- #
665
- # assert_select_email do
666
- # assert_select "h1", "Email alert"
667
- # end
668
- #
669
- # assert_select_email do
670
- # items = assert_select "ol>li"
671
- # items.each do
672
- # # Work with items here...
673
- # end
674
- # end
675
- #
676
- # See also Minitest::Rails::Expectations#must_select_email
677
- #
678
- # :method: assert_select_email
679
- # :call-seq: assert_select_email(&block)
680
-
681
- # Extracts the content of an element, treats it as encoded HTML and runs
682
- # nested assertion on it.
683
- #
684
- # You typically call this method within another assertion to operate on
685
- # all currently selected elements. You can also pass an element or array
686
- # of elements.
687
- #
688
- # The content of each element is un-encoded, and wrapped in the root
689
- # element +encoded+. It then calls the block with all un-encoded elements.
690
- #
691
- # # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)
692
- # assert_select "feed[xmlns='http://www.w3.org/2005/Atom']" do
693
- # # Select each entry item and then the title item
694
- # assert_select "entry>title" do
695
- # # Run assertions on the encoded title elements
696
- # assert_select_encoded do
697
- # assert_select "b"
698
- # end
699
- # end
700
- # end
701
- #
702
- #
703
- # # Selects all paragraph tags from within the description of an RSS feed
704
- # assert_select "rss[version=2.0]" do
705
- # # Select description element of each feed item.
706
- # assert_select "channel>item>description" do
707
- # # Run assertions on the encoded elements.
708
- # assert_select_encoded do
709
- # assert_select "p"
710
- # end
711
- # end
712
- # end
713
- #
714
- # See also Minitest::Rails::Expectations#must_select_encoded
715
- #
716
- # :method: assert_select_encoded
717
- # :call-seq: assert_select_encoded(element = nil, &block)
718
-
719
- ##
720
- # Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values.
721
- #
722
- # assert_dom_equal '<a href="http://www.example.com">Apples</a>',
723
- # link_to("Apples", "http://www.example.com")
724
- #
725
- # See also Minitest::Rails::Expectations#must_dom_equal
726
- #
727
- # :method: assert_dom_equal
728
- # :call-seq: assert_dom_equal(expected, actual, message = nil)
729
-
730
- ##
731
- # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
732
- #
733
- # assert_dom_not_equal '<a href="http://www.example.com">Oranges</a>',
734
- # link_to("Apples", "http://www.example.com")
735
- #
736
- # See also Minitest::Rails::Expectations#wont_dom_equal
737
- #
738
- # :method: assert_dom_not_equal
739
- # :call-seq: assert_dom_not_equal(expected, actual, message = nil)
740
-
741
- ##
742
- # Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
743
- #
744
- # refute_dom_equal '<a href="http://www.example.com">Oranges</a>',
745
- # link_to("Apples", "http://www.example.com")
746
- #
747
- # See also Minitest::Rails::Expectations#wont_dom_equal
748
- #
749
- # :method: assert_dom_equal
750
- # :call-seq: assert_dom_equal(expected, actual, message = nil)
751
- alias :refute_dom_equal :assert_dom_not_equal
752
- end
753
-
754
- if defined? ActiveJob
755
- class ActiveJob::TestCase
756
- # Asserts that the number of enqueued jobs matches the given number.
757
- #
758
- # def test_jobs
759
- # assert_enqueued_jobs 0
760
- # HelloJob.perform_later('david')
761
- # assert_enqueued_jobs 1
762
- # HelloJob.perform_later('abdelkader')
763
- # assert_enqueued_jobs 2
764
- # end
765
- #
766
- # If a block is passed, that block should cause the specified number of
767
- # jobs to be enqueued.
768
- #
769
- # def test_jobs_again
770
- # assert_enqueued_jobs 1 do
771
- # HelloJob.perform_later('cristian')
772
- # end
773
- #
774
- # assert_enqueued_jobs 2 do
775
- # HelloJob.perform_later('aaron')
776
- # HelloJob.perform_later('rafael')
777
- # end
778
- # end
779
- #
780
- # See also Minitest::Rails::Expectations#must_enqueue_jobs
781
- #
782
- # :method: assert_enqueued_jobs
783
- # :call-seq: assert_enqueued_jobs(number)
784
-
785
- ##
786
- # Asserts that no jobs have been enqueued.
787
- #
788
- # def test_jobs
789
- # assert_no_enqueued_jobs
790
- # HelloJob.perform_later('jeremy')
791
- # assert_enqueued_jobs 1
792
- # end
793
- #
794
- # If a block is passed, that block should not cause any job to be enqueued.
795
- #
796
- # def test_jobs_again
797
- # assert_no_enqueued_jobs do
798
- # # No job should be enqueued from this block
799
- # end
800
- # end
801
- #
802
- # Note: This assertion is simply a shortcut for:
803
- #
804
- # assert_enqueued_jobs 0, &block
805
- #
806
- # See also Minitest::Rails::Expectations#wont_enqueue_jobs
807
- #
808
- # :method: assert_no_enqueued_jobs
809
- # :call-seq: assert_no_enqueued_jobs(number)
810
-
811
- ##
812
- # Asserts that the number of performed jobs matches the given number.
813
- # If no block is passed, <tt>perform_enqueued_jobs</tt>d
814
- # must be called around the job call.
815
- #
816
- # def test_jobs
817
- # assert_performed_jobs 0
818
- #
819
- # perform_enqueued_jobs do
820
- # HelloJob.perform_later('xavier')
821
- # end
822
- # assert_performed_jobs 1
823
- #
824
- # perform_enqueued_jobs do
825
- # HelloJob.perform_later('yves')
826
- # assert_performed_jobs 2
827
- # end
828
- # end
829
- #
830
- # If a block is passed, that block should cause the specified number of
831
- # jobs to be performed.
832
- #
833
- # def test_jobs_again
834
- # assert_performed_jobs 1 do
835
- # HelloJob.perform_later('robin')
836
- # end
837
- #
838
- # assert_performed_jobs 2 do
839
- # HelloJob.perform_later('carlos')
840
- # HelloJob.perform_later('sean')
841
- # end
842
- # end
843
- #
844
- # See also Minitest::Rails::Expectations#must_perform_jobs
845
- #
846
- # :method: assert_performed_jobs
847
- # :call-seq: assert_performed_jobs(number)
848
-
849
- ##
850
- # Asserts that no jobs have been performed.
851
- #
852
- # def test_jobs
853
- # assert_no_performed_jobs
854
- #
855
- # perform_enqueued_jobs do
856
- # HelloJob.perform_later('matthew')
857
- # assert_performed_jobs 1
858
- # end
859
- # end
860
- #
861
- # If a block is passed, that block should not cause any job to be performed.
862
- #
863
- # def test_jobs_again
864
- # assert_no_performed_jobs do
865
- # # No job should be performed from this block
866
- # end
867
- # end
868
- #
869
- # Note: This assertion is simply a shortcut for:
870
- #
871
- # assert_performed_jobs 0, &block
872
- #
873
- # See also Minitest::Rails::Expectations#wont_perform_jobs
874
- #
875
- # :method: assert_no_performed_jobs
876
- # :call-seq: assert_no_performed_jobs(number)
877
-
878
- ##
879
- # Asserts that the job passed in the block has been enqueued with the given arguments.
880
- #
881
- # def test_assert_enqueued_with
882
- # assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low') do
883
- # MyJob.perform_later(1,2,3)
884
- # end
885
- # end
886
- #
887
- # See also Minitest::Rails::Expectations#must_enqueue_with
888
- #
889
- # :method: assert_enqueued_with
890
- # :call-seq: assert_enqueued_with(args)
891
-
892
- ##
893
- # Asserts that the job passed in the block has been performed with the given arguments.
894
- #
895
- # def test_assert_performed_with
896
- # assert_performed_with(job: MyJob, args: [1,2,3], queue: 'high') do
897
- # MyJob.perform_later(1,2,3)
898
- # end
899
- # end
900
- #
901
- # See also Minitest::Rails::Expectations#must_perform_with
902
- #
903
- # :method: assert_performed_with
904
- # :call-seq: assert_performed_with(args)
905
- end
906
- end
1
+ require "minitest/rails/assertions/active_support"
2
+ require "minitest/rails/assertions/action_view"
3
+ require "minitest/rails/assertions/action_dispatch"
4
+ require "minitest/rails/assertions/active_job" if defined? ActiveJob
5
+ require "minitest/rails/assertions/action_cable" if defined? ActionCable
6
+ require "minitest/rails/assertions/action_mailer" if defined? ActionMailer