File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -257,6 +257,33 @@ See the [Testing Rails Applications](https://edgeguides.rubyonrails.org/testing.
257
257
258
258
If you run a single file's tests (` bin/rails test test/models/user_test.rb ` ), ` test:prepare ` will not run before it.
259
259
260
+ ### ` ActionView::TestCase#rendered ` no longer returns a ` String `
261
+
262
+ Starting from Rails 7.1, ` ActionView::TestCase#rendered ` returns an object that
263
+ responds to various format methods (for example, ` rendered.html ` and
264
+ ` rendered.json ` ). To preserve backward compatibility, the object returned from
265
+ ` rendered ` will delegate missing methods to the ` String ` rendered during the
266
+ test. For example, the following [ assert_match] [ ] assertion will pass:
267
+
268
+ ``` ruby
269
+ assert_match /some content/i , rendered
270
+ ```
271
+
272
+ However, if your tests rely on ` ActionView::TestCase#rendered ` returning an
273
+ instance of ` String ` , they will fail. To restore the original behavior, you can
274
+ override the ` #rendered ` method to read from the ` @rendered ` instance variable:
275
+
276
+ ``` ruby
277
+ # config/initializers/action_view.rb
278
+
279
+ ActiveSupport .on_load :action_view_test_case do
280
+ attr_reader :rendered
281
+ end
282
+ ```
283
+
284
+ [ assert_match ] : https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-assert_match
285
+
286
+
260
287
Upgrading from Rails 6.1 to Rails 7.0
261
288
-------------------------------------
262
289
You can’t perform that action at this time.
0 commit comments