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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +5 -0
- data/LICENSE +1 -1
- data/README.md +94 -0
- data/UPDATING.md +31 -0
- data/lib/generators/minitest.rb +17 -4
- data/lib/generators/minitest/controller/controller_generator.rb +6 -9
- data/lib/generators/minitest/controller/templates/{controller_spec.rb → functional_spec.rb.tt} +4 -4
- data/lib/generators/minitest/controller/templates/{controller_test.rb → functional_test.rb.tt} +3 -3
- data/lib/generators/minitest/generator/generator_generator.rb +3 -8
- data/lib/generators/minitest/generator/templates/{generator_spec.rb → generator_spec.rb.tt} +2 -2
- data/lib/generators/minitest/generator/templates/{generator_test.rb → generator_test.rb.tt} +1 -2
- data/lib/generators/minitest/helper/helper_generator.rb +5 -3
- data/lib/generators/minitest/install/install_generator.rb +19 -8
- data/lib/generators/minitest/install/templates/test/test_helper.rb.tt +16 -0
- data/lib/generators/minitest/integration/integration_generator.rb +12 -9
- data/lib/generators/minitest/integration/templates/integration_spec.rb.tt +9 -0
- data/lib/generators/minitest/integration/templates/integration_test.rb.tt +9 -0
- data/lib/generators/minitest/job/job_generator.rb +13 -10
- data/lib/generators/minitest/job/templates/unit_spec.rb.tt +9 -0
- data/lib/generators/minitest/job/templates/{job_test.rb → unit_test.rb.tt} +3 -3
- data/lib/generators/minitest/mailer/mailer_generator.rb +8 -11
- data/lib/generators/minitest/mailer/templates/functional_spec.rb.tt +21 -0
- data/lib/generators/minitest/mailer/templates/{mailer_test.rb → functional_test.rb.tt} +3 -3
- data/lib/generators/minitest/mailer/templates/{preview.rb → preview.rb.tt} +0 -0
- data/lib/generators/minitest/model/model_generator.rb +9 -12
- data/lib/generators/minitest/model/templates/{fixtures.yml → fixtures.yml.tt} +3 -3
- data/lib/generators/minitest/model/templates/unit_spec.rb.tt +9 -0
- data/lib/generators/minitest/model/templates/unit_test.rb.tt +9 -0
- data/lib/generators/minitest/plugin/plugin_generator.rb +15 -0
- data/lib/generators/minitest/plugin/templates/%file_name%_test.rb.tt +15 -0
- data/lib/generators/minitest/plugin/templates/test_helper.rb +2 -0
- data/lib/generators/minitest/scaffold/scaffold_generator.rb +21 -23
- data/lib/generators/minitest/scaffold/templates/api_functional_spec.rb.tt +42 -0
- data/lib/generators/minitest/scaffold/templates/api_functional_test.rb.tt +44 -0
- data/lib/generators/minitest/scaffold/templates/functional_spec.rb.tt +52 -0
- data/lib/generators/minitest/scaffold/templates/{controller_test.rb → functional_test.rb.tt} +16 -16
- data/lib/minitest/rails.rb +45 -108
- data/lib/minitest/rails/assertions.rb +5 -906
- data/lib/minitest/rails/assertions/action_dispatch.rb +356 -0
- data/lib/minitest/rails/assertions/action_mailer.rb +115 -0
- data/lib/minitest/rails/assertions/action_view.rb +356 -0
- data/lib/minitest/rails/assertions/active_job.rb +151 -0
- data/lib/minitest/rails/assertions/active_support.rb +29 -0
- data/lib/minitest/rails/expectations.rb +4 -565
- data/lib/minitest/rails/expectations/action_dispatch.rb +307 -0
- data/lib/minitest/rails/expectations/action_mailer.rb +136 -0
- data/lib/minitest/rails/expectations/active_job.rb +182 -0
- data/lib/minitest/rails/expectations/active_support.rb +42 -0
- data/lib/minitest/rails/railtie.rb +3 -2
- data/lib/minitest/rails/version.rb +1 -1
- metadata +72 -89
- data/.autotest +0 -23
- data/.gemtest +0 -0
- data/.travis.yml +0 -25
- data/CHANGELOG.rdoc +0 -223
- data/Gemfile +0 -7
- data/Manifest.txt +0 -76
- data/README.rdoc +0 -110
- data/Rakefile +0 -30
- data/gemfiles/5.0.gemfile +0 -5
- data/gemfiles/head.gemfile +0 -5
- data/lib/generators/.document +0 -0
- data/lib/generators/minitest/install/templates/test_helper.rb +0 -19
- data/lib/generators/minitest/integration/templates/integration_spec.rb +0 -8
- data/lib/generators/minitest/integration/templates/integration_test.rb +0 -7
- data/lib/generators/minitest/job/templates/job_spec.rb +0 -9
- data/lib/generators/minitest/mailer/templates/mailer_spec.rb +0 -20
- data/lib/generators/minitest/model/templates/model_spec.rb +0 -11
- data/lib/generators/minitest/model/templates/model_test.rb +0 -13
- data/lib/generators/minitest/scaffold/templates/api_controller_spec.rb +0 -42
- data/lib/generators/minitest/scaffold/templates/api_controller_test.rb +0 -44
- data/lib/generators/minitest/scaffold/templates/controller_spec.rb +0 -52
- data/lib/minitest/rails/constant_lookup.rb +0 -52
- data/lib/minitest/rails/controller.rb +0 -14
- data/minitest-rails.gemspec +0 -48
- data/tasks/test.rake +0 -29
- data/test/generators/test_controller_generator.rb +0 -58
- data/test/generators/test_generator_generator.rb +0 -58
- data/test/generators/test_helper_generator.rb +0 -34
- data/test/generators/test_install_generator.rb +0 -27
- data/test/generators/test_job_generator.rb +0 -45
- data/test/generators/test_mailer_generator.rb +0 -42
- data/test/generators/test_model_generator.rb +0 -80
- data/test/generators/test_scaffold_generator.rb +0 -26
- data/test/helper.rb +0 -93
- data/test/rails/action_dispatch/test_assertions.rb +0 -39
- data/test/rails/action_dispatch/test_expectations.rb +0 -39
- data/test/rails/action_dispatch/test_spec_type.rb +0 -49
- data/test/rails/action_mailer/test_mailers.rb +0 -109
- data/test/rails/action_mailer/test_spec_type.rb +0 -47
- data/test/rails/action_view/test_helpers.rb +0 -73
- data/test/rails/action_view/test_spec_type.rb +0 -58
- data/test/rails/active_job/test_assertions.rb +0 -46
- data/test/rails/active_job/test_expectations.rb +0 -55
- data/test/rails/active_job/test_spec_type.rb +0 -49
- data/test/rails/active_support/test_assertions.rb +0 -31
- data/test/rails/active_support/test_expectations.rb +0 -21
- data/test/rails/active_support/test_spec_type.rb +0 -28
- data/test/rails/generators/test_spec_type.rb +0 -45
- data/test/rails/test_constant_lookup.rb +0 -58
- data/test/test_sanity.rb +0 -7
@@ -0,0 +1,356 @@
|
|
1
|
+
class ActionDispatch::IntegrationTest
|
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
|
+
# Asserts 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
|
+
# # assert that the response was a redirection
|
50
|
+
# assert_response :redirect
|
51
|
+
#
|
52
|
+
# # assert that the response code was status code 401 (unauthorized)
|
53
|
+
# assert_response 401
|
54
|
+
#
|
55
|
+
# See also Minitest::Rails::Expectations#must_respond_with
|
56
|
+
#
|
57
|
+
# :method: assert_response
|
58
|
+
# :call-seq: assert_response(type, message = nil)
|
59
|
+
|
60
|
+
##
|
61
|
+
# Assert that the redirection options passed in match those of the redirect called in the latest action.
|
62
|
+
# This match can be partial, such that <tt>assert_redirected_to(controller: "weblog")</tt> will also
|
63
|
+
# match the redirection of <tt>redirect_to(controller: "weblog", action: "show")</tt> and so on.
|
64
|
+
#
|
65
|
+
# # assert that the redirection was to the "index" action on the WeblogController
|
66
|
+
# assert_redirected_to controller: "weblog", action: "index"
|
67
|
+
#
|
68
|
+
# # assert that the redirection was to the named route login_url
|
69
|
+
# assert_redirected_to login_url
|
70
|
+
#
|
71
|
+
# # assert that the redirection was to the url for @customer
|
72
|
+
# assert_redirected_to @customer
|
73
|
+
#
|
74
|
+
# # asserts that the redirection matches the regular expression
|
75
|
+
# assert_redirected_to %r(\Ahttp://example.org)
|
76
|
+
#
|
77
|
+
# See also Minitest::Rails::Expectations#must_redirect_to
|
78
|
+
#
|
79
|
+
# :method: assert_redirected_to
|
80
|
+
# :call-seq: assert_redirected_to(options = {}, message=nil)
|
81
|
+
|
82
|
+
##
|
83
|
+
# Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
|
84
|
+
# The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
|
85
|
+
# a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
|
86
|
+
#
|
87
|
+
# The +defaults+ parameter is unused.
|
88
|
+
#
|
89
|
+
# # Asserts that the default action is generated for a route with no action
|
90
|
+
# assert_generates "/items", controller: "items", action: "index"
|
91
|
+
#
|
92
|
+
# # Tests that the list action is properly routed
|
93
|
+
# assert_generates "/items/list", controller: "items", action: "list"
|
94
|
+
#
|
95
|
+
# # Tests the generation of a route with a parameter
|
96
|
+
# assert_generates "/items/list/1", { controller: "items", action: "list", id: "1" }
|
97
|
+
#
|
98
|
+
# # Asserts that the generated route gives us our custom route
|
99
|
+
# assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
|
100
|
+
#
|
101
|
+
# See also Minitest::Rails::Expectations#must_route_to
|
102
|
+
#
|
103
|
+
# :method: assert_generates
|
104
|
+
# :call-seq: assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)
|
105
|
+
|
106
|
+
##
|
107
|
+
# Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
|
108
|
+
# match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
|
109
|
+
#
|
110
|
+
# Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
|
111
|
+
# requiring a specific HTTP method. The hash should contain a :path with the incoming request path
|
112
|
+
# and a :method containing the required HTTP verb.
|
113
|
+
#
|
114
|
+
# # assert that POSTing to /items will call the create action on ItemsController
|
115
|
+
# assert_recognizes({controller: 'items', action: 'create'}, {path: 'items', method: :post})
|
116
|
+
#
|
117
|
+
# You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
|
118
|
+
# 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
|
119
|
+
# extras argument, appending the query string on the path directly will not work. For example:
|
120
|
+
#
|
121
|
+
# # assert that a path of '/items/list/1?view=print' returns the correct options
|
122
|
+
# assert_recognizes({controller: 'items', action: 'list', id: '1', view: 'print'}, 'items/list/1', { view: "print" })
|
123
|
+
#
|
124
|
+
# The +message+ parameter allows you to pass in an error message that is displayed upon failure.
|
125
|
+
#
|
126
|
+
# # Check the default route (i.e., the index action)
|
127
|
+
# assert_recognizes({controller: 'items', action: 'index'}, 'items')
|
128
|
+
#
|
129
|
+
# # Test a specific action
|
130
|
+
# assert_recognizes({controller: 'items', action: 'list'}, 'items/list')
|
131
|
+
#
|
132
|
+
# # Test an action with a parameter
|
133
|
+
# assert_recognizes({controller: 'items', action: 'destroy', id: '1'}, 'items/destroy/1')
|
134
|
+
#
|
135
|
+
# # Test a custom route
|
136
|
+
# assert_recognizes({controller: 'items', action: 'show', id: '1'}, 'view/item1')
|
137
|
+
#
|
138
|
+
# See also Minitest::Rails::Expectations#must_route_from
|
139
|
+
#
|
140
|
+
# :method: assert_recognizes
|
141
|
+
# :call-seq: assert_recognizes(expected_options, path, extras={}, msg=nil)
|
142
|
+
|
143
|
+
##
|
144
|
+
# Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
|
145
|
+
# <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
|
146
|
+
# and +assert_generates+ into one step.
|
147
|
+
#
|
148
|
+
# The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
|
149
|
+
# +message+ parameter allows you to specify a custom error message to display upon failure.
|
150
|
+
#
|
151
|
+
# # Assert a basic route: a controller with the default action (index)
|
152
|
+
# assert_routing '/home', controller: 'home', action: 'index'
|
153
|
+
#
|
154
|
+
# # Test a route generated with a specific controller, action, and parameter (id)
|
155
|
+
# assert_routing '/entries/show/23', controller: 'entries', action: 'show', id: 23
|
156
|
+
#
|
157
|
+
# # Assert a basic route (controller + default action), with an error message if it fails
|
158
|
+
# assert_routing '/store', { controller: 'store', action: 'index' }, {}, {}, 'Route for store index not generated properly'
|
159
|
+
#
|
160
|
+
# # Tests a route, providing a defaults hash
|
161
|
+
# assert_routing 'controller/action/9', {id: "9", item: "square"}, {controller: "controller", action: "action"}, {}, {item: "square"}
|
162
|
+
#
|
163
|
+
# # Tests a route with a HTTP method
|
164
|
+
# assert_routing({ method: 'put', path: '/product/321' }, { controller: "product", action: "update", id: "321" })
|
165
|
+
#
|
166
|
+
# See also Minitest::Rails::Expectations#must_route
|
167
|
+
#
|
168
|
+
# :method: assert_routing
|
169
|
+
# :call-seq: assert_routing(path, options, defaults={}, extras={}, message=nil)
|
170
|
+
|
171
|
+
# An assertion that selects elements and makes one or more equality tests.
|
172
|
+
#
|
173
|
+
# If the first argument is an element, selects all matching elements
|
174
|
+
# starting from (and including) that element and all its children in
|
175
|
+
# depth-first order.
|
176
|
+
#
|
177
|
+
# If no element if specified, calling +assert_select+ selects from the
|
178
|
+
# response HTML unless +assert_select+ is called from within an +assert_select+ block.
|
179
|
+
#
|
180
|
+
# When called with a block +assert_select+ passes an array of selected elements
|
181
|
+
# to the block. Calling +assert_select+ from the block, with no element specified,
|
182
|
+
# runs the assertion on the complete set of elements selected by the enclosing assertion.
|
183
|
+
# Alternatively the array may be iterated through so that +assert_select+ can be called
|
184
|
+
# separately for each element.
|
185
|
+
#
|
186
|
+
#
|
187
|
+
# ==== Example
|
188
|
+
# If the response contains two ordered lists, each with four list elements then:
|
189
|
+
# assert_select "ol" do |elements|
|
190
|
+
# elements.each do |element|
|
191
|
+
# assert_select element, "li", 4
|
192
|
+
# end
|
193
|
+
# end
|
194
|
+
#
|
195
|
+
# will pass, as will:
|
196
|
+
# assert_select "ol" do
|
197
|
+
# assert_select "li", 8
|
198
|
+
# end
|
199
|
+
#
|
200
|
+
# The selector may be a CSS selector expression (String), an expression
|
201
|
+
# with substitution values, or an HTML::Selector object.
|
202
|
+
#
|
203
|
+
# === Equality Tests
|
204
|
+
#
|
205
|
+
# The equality test may be one of the following:
|
206
|
+
# * <tt>true</tt> - Assertion is true if at least one element selected.
|
207
|
+
# * <tt>false</tt> - Assertion is true if no element selected.
|
208
|
+
# * <tt>String/Regexp</tt> - Assertion is true if the text value of at least
|
209
|
+
# one element matches the string or regular expression.
|
210
|
+
# * <tt>Integer</tt> - Assertion is true if exactly that number of
|
211
|
+
# elements are selected.
|
212
|
+
# * <tt>Range</tt> - Assertion is true if the number of selected
|
213
|
+
# elements fit the range.
|
214
|
+
# If no equality test specified, the assertion is true if at least one
|
215
|
+
# element selected.
|
216
|
+
#
|
217
|
+
# To perform more than one equality tests, use a hash with the following keys:
|
218
|
+
# * <tt>:text</tt> - Narrow the selection to elements that have this text
|
219
|
+
# value (string or regexp).
|
220
|
+
# * <tt>:html</tt> - Narrow the selection to elements that have this HTML
|
221
|
+
# content (string or regexp).
|
222
|
+
# * <tt>:count</tt> - Assertion is true if the number of selected elements
|
223
|
+
# is equal to this value.
|
224
|
+
# * <tt>:minimum</tt> - Assertion is true if the number of selected
|
225
|
+
# elements is at least this value.
|
226
|
+
# * <tt>:maximum</tt> - Assertion is true if the number of selected
|
227
|
+
# elements is at most this value.
|
228
|
+
#
|
229
|
+
# If the method is called with a block, once all equality tests are
|
230
|
+
# evaluated the block is called with an array of all matched elements.
|
231
|
+
#
|
232
|
+
# # At least one form element
|
233
|
+
# assert_select "form"
|
234
|
+
#
|
235
|
+
# # Form element includes four input fields
|
236
|
+
# assert_select "form input", 4
|
237
|
+
#
|
238
|
+
# # Page title is "Welcome"
|
239
|
+
# assert_select "title", "Welcome"
|
240
|
+
#
|
241
|
+
# # Page title is "Welcome" and there is only one title element
|
242
|
+
# assert_select "title", {count: 1, text: "Welcome"},
|
243
|
+
# "Wrong title or more than one title element"
|
244
|
+
#
|
245
|
+
# # Page contains no forms
|
246
|
+
# assert_select "form", false, "This page must contain no forms"
|
247
|
+
#
|
248
|
+
# # Test the content and style
|
249
|
+
# assert_select "body div.header ul.menu"
|
250
|
+
#
|
251
|
+
# # Use substitution values
|
252
|
+
# assert_select "ol>li#?", /item-\d+/
|
253
|
+
#
|
254
|
+
# # All input fields in the form have a name
|
255
|
+
# assert_select "form input" do
|
256
|
+
# assert_select "[name=?]", /.+/ # Not empty
|
257
|
+
# end
|
258
|
+
#
|
259
|
+
# See also Minitest::Rails::Expectations#must_select
|
260
|
+
#
|
261
|
+
# :method: assert_select
|
262
|
+
# :call-seq: assert_select(*args, &block)
|
263
|
+
|
264
|
+
# Extracts the body of an email and runs nested assertions on it.
|
265
|
+
#
|
266
|
+
# You must enable deliveries for this assertion to work, use:
|
267
|
+
# ActionMailer::Base.perform_deliveries = true
|
268
|
+
#
|
269
|
+
# assert_select_email do
|
270
|
+
# assert_select "h1", "Email alert"
|
271
|
+
# end
|
272
|
+
#
|
273
|
+
# assert_select_email do
|
274
|
+
# items = assert_select "ol>li"
|
275
|
+
# items.each do
|
276
|
+
# # Work with items here...
|
277
|
+
# end
|
278
|
+
# end
|
279
|
+
#
|
280
|
+
# See also Minitest::Rails::Expectations#must_select_email
|
281
|
+
#
|
282
|
+
# :method: assert_select_email
|
283
|
+
# :call-seq: assert_select_email(&block)
|
284
|
+
|
285
|
+
# Extracts the content of an element, treats it as encoded HTML and runs
|
286
|
+
# nested assertion on it.
|
287
|
+
#
|
288
|
+
# You typically call this method within another assertion to operate on
|
289
|
+
# all currently selected elements. You can also pass an element or array
|
290
|
+
# of elements.
|
291
|
+
#
|
292
|
+
# The content of each element is un-encoded, and wrapped in the root
|
293
|
+
# element +encoded+. It then calls the block with all un-encoded elements.
|
294
|
+
#
|
295
|
+
# # Selects all bold tags from within the title of an Atom feed's entries (perhaps to nab a section name prefix)
|
296
|
+
# assert_select "feed[xmlns='http://www.w3.org/2005/Atom']" do
|
297
|
+
# # Select each entry item and then the title item
|
298
|
+
# assert_select "entry>title" do
|
299
|
+
# # Run assertions on the encoded title elements
|
300
|
+
# assert_select_encoded do
|
301
|
+
# assert_select "b"
|
302
|
+
# end
|
303
|
+
# end
|
304
|
+
# end
|
305
|
+
#
|
306
|
+
#
|
307
|
+
# # Selects all paragraph tags from within the description of an RSS feed
|
308
|
+
# assert_select "rss[version=2.0]" do
|
309
|
+
# # Select description element of each feed item.
|
310
|
+
# assert_select "channel>item>description" do
|
311
|
+
# # Run assertions on the encoded elements.
|
312
|
+
# assert_select_encoded do
|
313
|
+
# assert_select "p"
|
314
|
+
# end
|
315
|
+
# end
|
316
|
+
# end
|
317
|
+
#
|
318
|
+
# See also Minitest::Rails::Expectations#must_select_encoded
|
319
|
+
#
|
320
|
+
# :method: assert_select_encoded
|
321
|
+
# :call-seq: assert_select_encoded(element = nil, &block)
|
322
|
+
|
323
|
+
##
|
324
|
+
# Checks that two HTML strings are equivalent. That they contain the same elements and attributes with the associated values.
|
325
|
+
#
|
326
|
+
# assert_dom_equal '<a href="http://www.example.com">Apples</a>',
|
327
|
+
# link_to("Apples", "http://www.example.com")
|
328
|
+
#
|
329
|
+
# See also Minitest::Rails::Expectations#must_dom_equal
|
330
|
+
#
|
331
|
+
# :method: assert_dom_equal
|
332
|
+
# :call-seq: assert_dom_equal(expected, actual, message = nil)
|
333
|
+
|
334
|
+
##
|
335
|
+
# Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
|
336
|
+
#
|
337
|
+
# assert_dom_not_equal '<a href="http://www.example.com">Oranges</a>',
|
338
|
+
# link_to("Apples", "http://www.example.com")
|
339
|
+
#
|
340
|
+
# See also Minitest::Rails::Expectations#wont_dom_equal
|
341
|
+
#
|
342
|
+
# :method: assert_dom_not_equal
|
343
|
+
# :call-seq: assert_dom_not_equal(expected, actual, message = nil)
|
344
|
+
|
345
|
+
##
|
346
|
+
# Checks that two HTML strings are not equivalent. That they do not contain the same elements and attributes with the associated values.
|
347
|
+
#
|
348
|
+
# refute_dom_equal '<a href="http://www.example.com">Oranges</a>',
|
349
|
+
# link_to("Apples", "http://www.example.com")
|
350
|
+
#
|
351
|
+
# See also Minitest::Rails::Expectations#wont_dom_equal
|
352
|
+
#
|
353
|
+
# :method: assert_dom_equal
|
354
|
+
# :call-seq: assert_dom_equal(expected, actual, message = nil)
|
355
|
+
alias refute_dom_equal assert_dom_not_equal
|
356
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
class ActionMailer::TestCase
|
2
|
+
##
|
3
|
+
# Asserts that the number of emails sent matches the given number.
|
4
|
+
#
|
5
|
+
# def test_emails
|
6
|
+
# assert_emails 0
|
7
|
+
# ContactMailer.welcome.deliver_now
|
8
|
+
# assert_emails 1
|
9
|
+
# ContactMailer.welcome.deliver_now
|
10
|
+
# assert_emails 2
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# If a block is passed, that block should cause the specified number of
|
14
|
+
# emails to be sent.
|
15
|
+
#
|
16
|
+
# def test_emails_again
|
17
|
+
# assert_emails 1 do
|
18
|
+
# ContactMailer.welcome.deliver_now
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# assert_emails 2 do
|
22
|
+
# ContactMailer.welcome.deliver_now
|
23
|
+
# ContactMailer.welcome.deliver_later
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# See also Minitest::Rails::Expectations::ActionMailer#must_have_emails
|
28
|
+
# See https://api.rubyonrails.org/v5.0/classes/ActionMailer/TestHelper.html#method-i-assert_emails
|
29
|
+
#
|
30
|
+
# :method: assert_emails
|
31
|
+
# :call-seq: assert_emails(number, &block)
|
32
|
+
|
33
|
+
# Asserts that no emails have been sent.
|
34
|
+
#
|
35
|
+
# def test_emails
|
36
|
+
# refute_emails
|
37
|
+
# ContactMailer.welcome.deliver_now
|
38
|
+
# assert_emails 1
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# If a block is passed, that block should not cause any emails to be sent.
|
42
|
+
#
|
43
|
+
# def test_emails_again
|
44
|
+
# refute_emails do
|
45
|
+
# # No emails should be sent from this block
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# Note: This assertion is simply a shortcut for:
|
50
|
+
#
|
51
|
+
# assert_emails 0, &block
|
52
|
+
#
|
53
|
+
# See also Minitest::Rails::Expectations::ActionMailer#wont_have_emails
|
54
|
+
# See https://api.rubyonrails.org/v5.0/classes/ActionMailer/TestHelper.html#method-i-assert_no_emails
|
55
|
+
#
|
56
|
+
# :method: refute_emails
|
57
|
+
# :call-seq: refute_emails(&block)
|
58
|
+
alias refute_emails assert_no_emails
|
59
|
+
|
60
|
+
##
|
61
|
+
# Asserts that the number of emails enqueued for later delivery matches
|
62
|
+
# the given number.
|
63
|
+
#
|
64
|
+
# def test_emails
|
65
|
+
# assert_enqueued_emails 0
|
66
|
+
# ContactMailer.welcome.deliver_later
|
67
|
+
# assert_enqueued_emails 1
|
68
|
+
# ContactMailer.welcome.deliver_later
|
69
|
+
# assert_enqueued_emails 2
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# If a block is passed, that block should cause the specified number of
|
73
|
+
# emails to be enqueued.
|
74
|
+
#
|
75
|
+
# def test_emails_again
|
76
|
+
# assert_enqueued_emails 1 do
|
77
|
+
# ContactMailer.welcome.deliver_later
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# assert_enqueued_emails 2 do
|
81
|
+
# ContactMailer.welcome.deliver_later
|
82
|
+
# ContactMailer.welcome.deliver_later
|
83
|
+
# end
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# See also Minitest::Rails::Expectations::ActionMailer#must_have_enqueued_emails
|
87
|
+
# See https://api.rubyonrails.org/v5.0/classes/ActionMailer/TestHelper.html#method-i-assert_enqueued_emails
|
88
|
+
#
|
89
|
+
# :method: assert_enqueued_emails
|
90
|
+
# :call-seq: assert_enqueued_emails(number, &block)
|
91
|
+
|
92
|
+
##
|
93
|
+
# Asserts that no emails are enqueued for later delivery.
|
94
|
+
#
|
95
|
+
# def test_no_emails
|
96
|
+
# refute_enqueued_emails
|
97
|
+
# ContactMailer.welcome.deliver_later
|
98
|
+
# assert_enqueued_emails 1
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
# If a block is provided, it should not cause any emails to be enqueued.
|
102
|
+
#
|
103
|
+
# def test_no_emails
|
104
|
+
# refute_enqueued_emails do
|
105
|
+
# # No emails should be enqueued from this block
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# See also Minitest::Rails::Expectations::ActionMailer#wont_have_enqueued_emails
|
110
|
+
# See https://api.rubyonrails.org/v5.0/classes/ActionMailer/TestHelper.html#method-i-assert_no_enqueued_emails
|
111
|
+
#
|
112
|
+
# :method: refute_enqueued_emails
|
113
|
+
# :call-seq: refute_enqueued_emails(&block)
|
114
|
+
alias refute_enqueued_emails assert_no_enqueued_emails
|
115
|
+
end
|