minitest-rails 3.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +1 -1
  4. data/README.md +94 -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 +19 -8
  15. data/lib/generators/minitest/install/templates/test/test_helper.rb.tt +16 -0
  16. data/lib/generators/minitest/integration/integration_generator.rb +12 -9
  17. data/lib/generators/minitest/integration/templates/integration_spec.rb.tt +9 -0
  18. data/lib/generators/minitest/integration/templates/integration_test.rb.tt +9 -0
  19. data/lib/generators/minitest/job/job_generator.rb +13 -10
  20. data/lib/generators/minitest/job/templates/unit_spec.rb.tt +9 -0
  21. data/lib/generators/minitest/job/templates/{job_test.rb → unit_test.rb.tt} +3 -3
  22. data/lib/generators/minitest/mailer/mailer_generator.rb +8 -11
  23. data/lib/generators/minitest/mailer/templates/functional_spec.rb.tt +21 -0
  24. data/lib/generators/minitest/mailer/templates/{mailer_test.rb → functional_test.rb.tt} +3 -3
  25. data/lib/generators/minitest/mailer/templates/{preview.rb → preview.rb.tt} +0 -0
  26. data/lib/generators/minitest/model/model_generator.rb +9 -12
  27. data/lib/generators/minitest/model/templates/{fixtures.yml → fixtures.yml.tt} +3 -3
  28. data/lib/generators/minitest/model/templates/unit_spec.rb.tt +9 -0
  29. data/lib/generators/minitest/model/templates/unit_test.rb.tt +9 -0
  30. data/lib/generators/minitest/plugin/plugin_generator.rb +15 -0
  31. data/lib/generators/minitest/plugin/templates/%file_name%_test.rb.tt +15 -0
  32. data/lib/generators/minitest/plugin/templates/test_helper.rb +2 -0
  33. data/lib/generators/minitest/scaffold/scaffold_generator.rb +21 -23
  34. data/lib/generators/minitest/scaffold/templates/api_functional_spec.rb.tt +42 -0
  35. data/lib/generators/minitest/scaffold/templates/api_functional_test.rb.tt +44 -0
  36. data/lib/generators/minitest/scaffold/templates/functional_spec.rb.tt +52 -0
  37. data/lib/generators/minitest/scaffold/templates/{controller_test.rb → functional_test.rb.tt} +16 -16
  38. data/lib/minitest/rails.rb +45 -108
  39. data/lib/minitest/rails/assertions.rb +5 -906
  40. data/lib/minitest/rails/assertions/action_dispatch.rb +356 -0
  41. data/lib/minitest/rails/assertions/action_mailer.rb +115 -0
  42. data/lib/minitest/rails/assertions/action_view.rb +356 -0
  43. data/lib/minitest/rails/assertions/active_job.rb +151 -0
  44. data/lib/minitest/rails/assertions/active_support.rb +29 -0
  45. data/lib/minitest/rails/expectations.rb +4 -565
  46. data/lib/minitest/rails/expectations/action_dispatch.rb +307 -0
  47. data/lib/minitest/rails/expectations/action_mailer.rb +136 -0
  48. data/lib/minitest/rails/expectations/active_job.rb +182 -0
  49. data/lib/minitest/rails/expectations/active_support.rb +42 -0
  50. data/lib/minitest/rails/railtie.rb +3 -2
  51. data/lib/minitest/rails/version.rb +1 -1
  52. metadata +72 -89
  53. data/.autotest +0 -23
  54. data/.gemtest +0 -0
  55. data/.travis.yml +0 -25
  56. data/CHANGELOG.rdoc +0 -223
  57. data/Gemfile +0 -7
  58. data/Manifest.txt +0 -76
  59. data/README.rdoc +0 -110
  60. data/Rakefile +0 -30
  61. data/gemfiles/5.0.gemfile +0 -5
  62. data/gemfiles/head.gemfile +0 -5
  63. data/lib/generators/.document +0 -0
  64. data/lib/generators/minitest/install/templates/test_helper.rb +0 -19
  65. data/lib/generators/minitest/integration/templates/integration_spec.rb +0 -8
  66. data/lib/generators/minitest/integration/templates/integration_test.rb +0 -7
  67. data/lib/generators/minitest/job/templates/job_spec.rb +0 -9
  68. data/lib/generators/minitest/mailer/templates/mailer_spec.rb +0 -20
  69. data/lib/generators/minitest/model/templates/model_spec.rb +0 -11
  70. data/lib/generators/minitest/model/templates/model_test.rb +0 -13
  71. data/lib/generators/minitest/scaffold/templates/api_controller_spec.rb +0 -42
  72. data/lib/generators/minitest/scaffold/templates/api_controller_test.rb +0 -44
  73. data/lib/generators/minitest/scaffold/templates/controller_spec.rb +0 -52
  74. data/lib/minitest/rails/constant_lookup.rb +0 -52
  75. data/lib/minitest/rails/controller.rb +0 -14
  76. data/minitest-rails.gemspec +0 -48
  77. data/tasks/test.rake +0 -29
  78. data/test/generators/test_controller_generator.rb +0 -58
  79. data/test/generators/test_generator_generator.rb +0 -58
  80. data/test/generators/test_helper_generator.rb +0 -34
  81. data/test/generators/test_install_generator.rb +0 -27
  82. data/test/generators/test_job_generator.rb +0 -45
  83. data/test/generators/test_mailer_generator.rb +0 -42
  84. data/test/generators/test_model_generator.rb +0 -80
  85. data/test/generators/test_scaffold_generator.rb +0 -26
  86. data/test/helper.rb +0 -93
  87. data/test/rails/action_dispatch/test_assertions.rb +0 -39
  88. data/test/rails/action_dispatch/test_expectations.rb +0 -39
  89. data/test/rails/action_dispatch/test_spec_type.rb +0 -49
  90. data/test/rails/action_mailer/test_mailers.rb +0 -109
  91. data/test/rails/action_mailer/test_spec_type.rb +0 -47
  92. data/test/rails/action_view/test_helpers.rb +0 -73
  93. data/test/rails/action_view/test_spec_type.rb +0 -58
  94. data/test/rails/active_job/test_assertions.rb +0 -46
  95. data/test/rails/active_job/test_expectations.rb +0 -55
  96. data/test/rails/active_job/test_spec_type.rb +0 -49
  97. data/test/rails/active_support/test_assertions.rb +0 -31
  98. data/test/rails/active_support/test_expectations.rb +0 -21
  99. data/test/rails/active_support/test_spec_type.rb +0 -28
  100. data/test/rails/generators/test_spec_type.rb +0 -45
  101. data/test/rails/test_constant_lookup.rb +0 -58
  102. data/test/test_sanity.rb +0 -7
@@ -0,0 +1,29 @@
1
+ class ActiveSupport::TestCase
2
+ ##
3
+ # Test numeric difference between the return value of an expression as a
4
+ # result of what is evaluated in the yielded block.
5
+ #
6
+ # assert_difference "Article.count" do
7
+ # post :create, params: { article: {...} }
8
+ # end
9
+ #
10
+ # See also Minitest::Rails::Expectations::ActiveSupport#must_change
11
+ # See https://api.rubyonrails.org/v5.0/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_difference
12
+ #
13
+ # :method: assert_difference
14
+ # :call-seq: assert_difference(expression, *args, &block)
15
+
16
+ ##
17
+ # Assertion that the numeric result of evaluating an expression is not changed
18
+ # before and after invoking the passed in block.
19
+ #
20
+ # refute_difference "Article.count" do
21
+ # post :create, params: { article: invalid_attributes }
22
+ # end
23
+ #
24
+ # See also Minitest::Rails::Expectations::ActiveSupport#wont_change
25
+ # See https://api.rubyonrails.org/v5.0/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_no_difference
26
+ #
27
+ # :args: expression, message = nil, &block
28
+ alias refute_difference assert_no_difference
29
+ end
@@ -1,565 +1,4 @@
1
- require "active_support/concern"
2
-
3
- module Minitest::Rails::Expectations
4
-
5
- ##############################################################################
6
- # ActiveSupport Expectations
7
- ##############################################################################
8
-
9
- ##
10
- # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
11
- #
12
- # value { User.create password: "valid" }.must_change "User.count"
13
- # value { 3.times do
14
- # User.create password: "valid"
15
- # end }.must_change "User.count", 3
16
- #
17
- # See also ActiveSupport::TestCase#assert_difference
18
- #
19
- # :method: must_change
20
- # :args: expression, difference = 1, message = nil
21
- infect_an_assertion :assert_difference, :must_change, :block
22
-
23
- ##
24
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
25
- #
26
- # value { User.new }.wont_change "User.count"
27
- #
28
- # See also ActiveSupport::TestCase#refute_difference
29
- #
30
- # :method: wont_change
31
- # :args: expression, message = nil
32
- infect_an_assertion :refute_difference, :wont_change, :block
33
-
34
- ##############################################################################
35
- # ActionController/ActionView/ActionDispatch Expectations
36
- ##############################################################################
37
-
38
- # Expects that the response is one of the following types:
39
- #
40
- # * <tt>:success</tt> - Status code was in the 200-299 range
41
- # * <tt>:redirect</tt> - Status code was in the 300-399 range
42
- # * <tt>:missing</tt> - Status code was 404
43
- # * <tt>:error</tt> - Status code was in the 500-599 range
44
- #
45
- # You can also pass an explicit status number like <tt>assert_response(501)</tt>
46
- # or its symbolic equivalent <tt>assert_response(:not_implemented)</tt>.
47
- # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list.
48
- #
49
- # # expect that the response was a redirection
50
- # must_respond_with :redirect
51
- # value(response).must_respond_with :redirect
52
- #
53
- # # expect that the response code was status code 401 (unauthorized)
54
- # must_respond_with 401
55
- # value(response).must_respond_with 401
56
- #
57
- # See also ActionView::TestCase#assert_response
58
- # See also ActionDispatch::IntegrationTest#assert_response
59
- #
60
- # :method: must_respond_with
61
- # :call-seq: must_respond_with(type, message = nil)
62
-
63
- ##
64
- # Expects that the redirection options passed in match those of the redirect called in the latest action.
65
- # This match can be partial, such that <tt>assert_redirected_to(controller: "weblog")</tt> will also
66
- # match the redirection of <tt>redirect_to(controller: "weblog", action: "show")</tt> and so on.
67
- #
68
- # # expect that the redirection was to the "index" action on the WeblogController
69
- # must_redirect_to controller: "weblog", action: "index"
70
- #
71
- # # expect that the redirection was to the named route login_url
72
- # must_redirect_to login_url
73
- #
74
- # # expect that the redirection was to the url for @customer
75
- # must_redirect_to @customer
76
- #
77
- # # expect that the redirection matches the regular expression
78
- # must_redirect_to %r(\Ahttp://example.org)
79
- #
80
- # See also ActionView::TestCase#assert_redirected_to
81
- # See also ActionDispatch::IntegrationTest#assert_redirected_to
82
- #
83
- # :method: must_redirect_to
84
- # :call-seq: must_redirect_to(options = {}, message=nil)
85
-
86
- ##
87
- # Expects that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
88
- # The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
89
- # a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
90
- #
91
- # The +defaults+ parameter is unused.
92
- #
93
- # # Expects that the default action is generated for a route with no action
94
- # value({controller: "items", action: "index"}).must_route_from "/items"
95
- #
96
- # # Tests that the list action is properly routed
97
- # value({controller: "items", action: "list"}).must_route_to "/items/list"
98
- #
99
- # # Tests the generation of a route with a parameter
100
- # value({ controller: "items", action: "list", id: "1" }).must_route_from "/items/list/1"
101
- #
102
- # # Expects that the generated route gives us our custom route
103
- # value({ controller: 'scm', action: 'show_diff', revision: "12" }).must_route_from "changesets/12"
104
- #
105
- # See also ActionView::TestCase#assert_generates
106
- # See also ActionDispatch::IntegrationTest#assert_generates
107
- #
108
- # :method: must_route_from
109
- # :call-seq: options.must_route_from(expected_path, defaults={}, extras = {}, message=nil)
110
- infect_an_assertion :assert_generates, :must_route_to
111
-
112
- ##
113
- # Expects that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
114
- # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
115
- #
116
- # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
117
- # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
118
- # and a :method containing the required HTTP verb.
119
- #
120
- # # assert that POSTing to /items will call the create action on ItemsController
121
- # assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
122
- #
123
- # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
124
- # 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
125
- # extras argument, appending the query string on the path directly will not work. For example:
126
- #
127
- # # Expect that a path of '/items/list/1?view=print' returns the correct options
128
- # value('items/list/1').must_route_from({controller: 'items', action: 'list', id: '1', view: 'print'}, { view: "print" })
129
- #
130
- # The +message+ parameter allows you to pass in an error message that is displayed upon failure.
131
- #
132
- # # Check the default route (i.e., the index action)
133
- # value('items').must_route_from({controller: 'items', action: 'index'})
134
- #
135
- # # Test a specific action
136
- # value('items/list').must_route_from({controller: 'items', action: 'list'})
137
- #
138
- # # Test an action with a parameter
139
- # value('items/destroy/1').must_route_from({controller: 'items', action: 'destroy', id: '1'})
140
- #
141
- # # Test a custom route
142
- # value('view/item1').must_route_from({controller: 'items', action: 'show', id: '1'})
143
- #
144
- # See also ActionView::TestCase#assert_recognizes
145
- # See also ActionDispatch::IntegrationTest#assert_recognizes
146
- #
147
- # :method: must_route_from
148
- # :call-seq: path.must_route_from(expected_options, extras={}, msg=nil)
149
- infect_an_assertion :assert_recognizes, :must_route_from
150
-
151
- ##
152
- # Expects that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
153
- # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
154
- # and +assert_generates+ into one step.
155
- #
156
- # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
157
- # +message+ parameter allows you to specify a custom error message to display upon failure.
158
- #
159
- # # Expect a basic route: a controller with the default action (index)
160
- # value({ controller: 'home', action: 'index' }).must_route_for '/home'
161
- #
162
- # # Test a route generated with a specific controller, action, and parameter (id)
163
- # value({ controller: 'entries', action: 'show', id: 23 }).must_route_for '/entries/show/23'
164
- #
165
- # # Expect a basic route (controller + default action), with an error message if it fails
166
- # value({ controller: 'store', action: 'index' }).must_route_for '/store'
167
- #
168
- # # Tests a route, providing a defaults hash
169
- # value({id: "9", item: "square"}).must_route_for 'controller/action/9', {controller: "controller", action: "action"}, {}, {item: "square"}
170
- #
171
- # # Tests a route with a HTTP method
172
- # value({ controller: "product", action: "update", id: "321" }).must_route_for({ method: 'put', path: '/product/321' })
173
- #
174
- # See also ActionView::TestCase#assert_routing
175
- # See also ActionDispatch::IntegrationTest#assert_routing
176
- #
177
- # :method: must_route_for
178
- # :call-seq: options.must_route_for(path, defaults={}, extras={}, message=nil)
179
- infect_an_assertion :assert_routing, :must_route_for
180
-
181
- # An expectation that selects elements and makes one or more equality tests.
182
- #
183
- # If the first argument is an element, selects all matching elements
184
- # starting from (and including) that element and all its children in
185
- # depth-first order.
186
- #
187
- # If no element if specified, calling +must_select+ selects from the
188
- # response HTML unless +must_select+ is called from within an +must_select+ block.
189
- #
190
- # When called with a block +must_select+ passes an array of selected elements
191
- # to the block. Calling +must_select+ from the block, with no element specified,
192
- # runs the expectation on the complete set of elements selected by the enclosing expectation.
193
- # Alternatively the array may be iterated through so that +must_select+ can be called
194
- # separately for each element.
195
- #
196
- #
197
- # ==== Example
198
- # If the response contains two ordered lists, each with four list elements then:
199
- # must_select "ol" do |elements|
200
- # elements.each do |element|
201
- # must_select element, "li", 4
202
- # end
203
- # end
204
- #
205
- # will pass, as will:
206
- # must_select "ol" do
207
- # must_select "li", 8
208
- # end
209
- #
210
- # The selector may be a CSS selector expression (String), an expression
211
- # with substitution values, or an HTML::Selector object.
212
- #
213
- # === Equality Tests
214
- #
215
- # The equality test may be one of the following:
216
- # * <tt>true</tt> - Assertion is true if at least one element selected.
217
- # * <tt>false</tt> - Assertion is true if no element selected.
218
- # * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
219
- # one element matches the string or regular expression.
220
- # * <tt>Integer</tt> - Assertion is true if exactly that number of
221
- # elements are selected.
222
- # * <tt>Range</tt> - Assertion is true if the number of selected
223
- # elements fit the range.
224
- # If no equality test specified, the expectation is true if at least one
225
- # element selected.
226
- #
227
- # To perform more than one equality tests, use a hash with the following keys:
228
- # * <tt>:text</tt> - Narrow the selection to elements that have this text
229
- # value (string or regexp).
230
- # * <tt>:html</tt> - Narrow the selection to elements that have this HTML
231
- # content (string or regexp).
232
- # * <tt>:count</tt> - Assertion is true if the number of selected elements
233
- # is equal to this value.
234
- # * <tt>:minimum</tt> - Assertion is true if the number of selected
235
- # elements is at least this value.
236
- # * <tt>:maximum</tt> - Assertion is true if the number of selected
237
- # elements is at most this value.
238
- #
239
- # If the method is called with a block, once all equality tests are
240
- # evaluated the block is called with an array of all matched elements.
241
- #
242
- # # At least one form element
243
- # must_select "form"
244
- #
245
- # # Form element includes four input fields
246
- # must_select "form input", 4
247
- #
248
- # # Page title is "Welcome"
249
- # must_select "title", "Welcome"
250
- #
251
- # # Page title is "Welcome" and there is only one title element
252
- # must_select "title", {count: 1, text: "Welcome"},
253
- # "Wrong title or more than one title element"
254
- #
255
- # # Page contains no forms
256
- # must_select "form", false, "This page must contain no forms"
257
- #
258
- # # Test the content and style
259
- # must_select "body div.header ul.menu"
260
- #
261
- # # Use substitution values
262
- # must_select "ol>li#?", /item-\d+/
263
- #
264
- # # All input fields in the form have a name
265
- # must_select "form input" do
266
- # must_select "[name=?]", /.+/ # Not empty
267
- # end
268
- #
269
- # See also ActionView::TestCase#assert_select
270
- # See also ActionDispatch::IntegrationTest#assert_select
271
- #
272
- # :method: must_select
273
- # :call-seq: must_select(*args, &block)
274
-
275
- # Extracts the body of an email and runs nested expectations on it.
276
- #
277
- # You must enable deliveries for this expectation to work, use:
278
- # ActionMailer::Base.perform_deliveries = true
279
- #
280
- # must_select_email do
281
- # must_select "h1", "Email alert"
282
- # end
283
- #
284
- # must_select_email do
285
- # items = must_select "ol>li"
286
- # items.each do
287
- # # Work with items here...
288
- # end
289
- # end
290
- #
291
- # See also ActionView::TestCase#assert_select_email
292
- # See also ActionDispatch::IntegrationTest#assert_select_email
293
- #
294
- # :method: must_select_email
295
- # :call-seq: must_select_email(&block)
296
-
297
- # Extracts the content of an element, treats it as encoded HTML and runs
298
- # nested expectation on it.
299
- #
300
- # You typically call this method within another expectation to operate on
301
- # all currently selected elements. You can also pass an element or array
302
- # of elements.
303
- #
304
- # The content of each element is un-encoded, and wrapped in the root
305
- # element +encoded+. It then calls the block with all un-encoded elements.
306
- #
307
- # # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)
308
- # must_select "feed[xmlns='http://www.w3.org/2005/Atom']" do
309
- # # Select each entry item and then the title item
310
- # must_select "entry>title" do
311
- # # Run expectations on the encoded title elements
312
- # must_select_encoded do
313
- # must_select "b"
314
- # end
315
- # end
316
- # end
317
- #
318
- #
319
- # # Selects all paragraph tags from within the description of an RSS feed
320
- # must_select "rss[version=2.0]" do
321
- # # Select description element of each feed item.
322
- # must_select "channel>item>description" do
323
- # # Run expectations on the encoded elements.
324
- # must_select_encoded do
325
- # must_select "p"
326
- # end
327
- # end
328
- # end
329
- #
330
- # See also ActionView::TestCase#assert_select_encoded
331
- # See also ActionDispatch::IntegrationTest#assert_select_encoded
332
- #
333
- # :method: must_select_encoded
334
- # :call-seq: must_select_encoded(element = nil, &block)
335
-
336
- ##
337
- # Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values.
338
- # Checks the numeric difference between the return value of an expression as a result of what is evaluated.
339
- #
340
- # apple_link = '<a href="http://www.example.com">Apples</a>'
341
- # value(link_to("Apples", "http://www.example.com")).must_dom_equal apple_link
342
- #
343
- # See also ActionView::TestCase#assert_dom_equal
344
- # See also ActionDispatch::IntegrationTest#assert_dom_equal
345
- #
346
- # :method: must_dom_equal
347
- # :args: expected, message = nil
348
- infect_an_assertion :assert_dom_equal, :must_dom_equal
349
-
350
- ##
351
- # Checks that the numeric result of evaluating an expression is not changed before and after invoking.
352
- #
353
- # orange_link = '<a href="http://www.example.com">Oranges</a>'
354
- # link_to("Apples", "http://www.example.com").wont_dom_equal orange_link
355
- #
356
- # See also ActionView::TestCase#refute_dom_equal
357
- # See also ActionDispatch::IntegrationTest#refute_dom_equal
358
- # See also ActionView::TestCase#assert_dom_not_equal
359
- # See also ActionDispatch::IntegrationTest#assert_dom_not_equal
360
- #
361
- # :method: wont_dom_equal
362
- # :args: expected, message = nil
363
- infect_an_assertion :refute_dom_equal, :wont_dom_equal
364
-
365
- if defined?(::ActiveJob)
366
- ##############################################################################
367
- # ActiveJob Expectations
368
- ##############################################################################
369
-
370
- ##
371
- # Expects that the number of enqueued jobs matches the given number.
372
- #
373
- # def test_jobs
374
- # must_enqueue_jobs 0
375
- # HelloJob.perform_later('david')
376
- # must_enqueue_jobs 1
377
- # HelloJob.perform_later('abdelkader')
378
- # must_enqueue_jobs 2
379
- # end
380
- #
381
- # If a block is passed, that block should cause the specified number of
382
- # jobs to be enqueued.
383
- #
384
- # def test_jobs_again
385
- # must_enqueue_jobs 1 do
386
- # HelloJob.perform_later('cristian')
387
- # end
388
- #
389
- # must_enqueue_jobs 2 do
390
- # HelloJob.perform_later('aaron')
391
- # HelloJob.perform_later('rafael')
392
- # end
393
- # end
394
- #
395
- # See also ActiveJob::TestCase#assert_enqueued_jobs
396
- #
397
- # :method: must_enqueue_jobs
398
- # :call-seq: must_enqueue_jobs(number)
399
-
400
- ##
401
- # Expects that no jobs have been enqueued.
402
- #
403
- # def test_jobs
404
- # wont_enqueue_jobs
405
- # HelloJob.perform_later('jeremy')
406
- # must_enqueue_jobs 1
407
- # end
408
- #
409
- # If a block is passed, that block should not cause any job to be enqueued.
410
- #
411
- # def test_jobs_again
412
- # wont_enqueue_jobs do
413
- # # No job should be enqueued from this block
414
- # end
415
- # end
416
- #
417
- # Note: This expectation is simply a shortcut for:
418
- #
419
- # must_enqueue_jobs 0, &block
420
- #
421
- # See also ActiveJob::TestCase#assert_no_enqueued_jobs
422
- #
423
- # :method: wont_enqueue_jobs
424
- # :call-seq: wont_enqueue_jobs(number)
425
-
426
- ##
427
- # Expects that the number of performed jobs matches the given number.
428
- # If no block is passed, <tt>perform_enqueued_jobs</tt>d
429
- # must be called around the job call.
430
- #
431
- # def test_jobs
432
- # must_perform_jobs 0
433
- #
434
- # perform_enqueued_jobs do
435
- # HelloJob.perform_later('xavier')
436
- # end
437
- # must_perform_jobs 1
438
- #
439
- # perform_enqueued_jobs do
440
- # HelloJob.perform_later('yves')
441
- # must_perform_jobs 2
442
- # end
443
- # end
444
- #
445
- # If a block is passed, that block should cause the specified number of
446
- # jobs to be performed.
447
- #
448
- # def test_jobs_again
449
- # must_perform_jobs 1 do
450
- # HelloJob.perform_later('robin')
451
- # end
452
- #
453
- # must_perform_jobs 2 do
454
- # HelloJob.perform_later('carlos')
455
- # HelloJob.perform_later('sean')
456
- # end
457
- # end
458
- #
459
- # See also ActiveJob::TestCase#assert_performed_jobs
460
- #
461
- # :method: must_perform_jobs
462
- # :call-seq: must_perform_jobs(number)
463
-
464
- ##
465
- # Expects that no jobs have been performed.
466
- #
467
- # def test_jobs
468
- # wont_perform_jobs
469
- #
470
- # perform_enqueued_jobs do
471
- # HelloJob.perform_later('matthew')
472
- # must_perform_jobs 1
473
- # end
474
- # end
475
- #
476
- # If a block is passed, that block should not cause any job to be performed.
477
- #
478
- # def test_jobs_again
479
- # wont_perform_jobs do
480
- # # No job should be performed from this block
481
- # end
482
- # end
483
- #
484
- # Note: This assertion is simply a shortcut for:
485
- #
486
- # must_perform_jobs 0, &block
487
- #
488
- # See also ActiveJob::TestCase#assert_no_performed_jobs
489
- #
490
- # :method: wont_perform_jobs
491
- # :call-seq: wont_perform_jobs(number)
492
-
493
- ##
494
- # Expects that the job passed in the block has been enqueued with the given arguments.
495
- #
496
- # def test_must_enqueue_with
497
- # must_enqueue_with(job: MyJob, args: [1,2,3], queue: 'low') do
498
- # MyJob.perform_later(1,2,3)
499
- # end
500
- # end
501
- #
502
- # See also Minitest::Rails::Expectations#assert_enqueued_with
503
- #
504
- # :method: must_enqueue_with
505
- # :call-seq: must_enqueue_with(args)
506
-
507
- ##
508
- # Expects that the job passed in the block has been performed with the given arguments.
509
- #
510
- # def test_must_perform_with
511
- # must_perform_with(job: MyJob, args: [1,2,3], queue: 'high') do
512
- # MyJob.perform_later(1,2,3)
513
- # end
514
- # end
515
- #
516
- # See also Minitest::Rails::Expectations#assert_performed_with
517
- #
518
- # :method: must_perform_with
519
- # :call-seq: must_perform_with(args)
520
-
521
-
522
- # This exists as a module to allow easy mixing into classes
523
- # other than ActiveJob::TestCase where you might want to do
524
- # job testing e.g. in an Active Record model which triggers
525
- # jobs in a callback.
526
- module ActiveJob
527
- extend ActiveSupport::Concern
528
- include ::ActiveJob::TestHelper
529
-
530
- included do
531
- alias :must_enqueue_jobs :assert_enqueued_jobs
532
- alias :must_perform_jobs :assert_performed_jobs
533
- alias :wont_enqueue_jobs :assert_no_enqueued_jobs
534
- alias :wont_perform_jobs :assert_no_performed_jobs
535
- alias :must_enqueue_with :assert_enqueued_with
536
- alias :must_perform_with :assert_performed_with
537
- end
538
- end
539
- end
540
- end
541
-
542
- unless ENV["MT_NO_EXPECTATIONS"]
543
- class Object # :nodoc:
544
- include Minitest::Rails::Expectations
545
- end
546
- # Not real expectations, just aliases
547
- # The error messages don't get messed up this way
548
- class ActionView::TestCase # :nodoc:
549
- alias :must_respond_with :assert_response
550
- alias :must_redirect_to :assert_redirected_to
551
- alias :must_select :assert_select
552
- alias :must_select_email :assert_select_email
553
- alias :must_select_encoded :assert_select_encoded
554
- end
555
- class ActiveJob::TestCase # :nodoc:
556
- include Minitest::Rails::Expectations::ActiveJob
557
- end if defined?(ActiveJob)
558
- class ActionDispatch::IntegrationTest # :nodoc:
559
- alias :must_respond_with :assert_response
560
- alias :must_redirect_to :assert_redirected_to
561
- alias :must_select :assert_select
562
- alias :must_select_email :assert_select_email
563
- alias :must_select_encoded :assert_select_encoded
564
- end
565
- end
1
+ require "minitest/rails/expectations/active_support"
2
+ require "minitest/rails/expectations/action_dispatch"
3
+ require "minitest/rails/expectations/active_job" if defined? ActiveJob
4
+ require "minitest/rails/expectations/action_mailer" if defined? ActionMailer