File tree Expand file tree Collapse file tree 10 files changed +52
-162
lines changed
generators/rails/app/templates/config/initializers Expand file tree Collapse file tree 10 files changed +52
-162
lines changed Original file line number Diff line number Diff line change 1
- * Allow assertionless tests to be reported .
1
+ * Warn on tests without assertions .
2
2
3
- ` ActiveSupport::TestCase ` can be configured to report tests that do not run any assertions.
3
+ ` ActiveSupport::TestCase ` now warns when tests do not run any assertions.
4
4
This is helpful in detecting broken tests that do not perform intended assertions.
5
5
6
- ``` ruby
7
- config.active_support.assertionless_tests_behavior = :raise
8
- ```
9
-
10
6
* fatkodima*
11
7
12
8
* Support ` hexBinary ` type in ` ActiveSupport::XmlMini ` .
Original file line number Diff line number Diff line change @@ -124,10 +124,6 @@ class Railtie < Rails::Railtie # :nodoc:
124
124
ActiveSupport . deprecator . warn ( "config.active_support.remove_deprecated_time_with_zone_name is deprecated and will be removed in Rails 7.2." )
125
125
elsif k == :use_rfc4122_namespaced_uuids
126
126
ActiveSupport . deprecator . warn ( "config.active_support.use_rfc4122_namespaced_uuids is deprecated and will be removed in Rails 7.2." )
127
- elsif k == :assertionless_tests_behavior
128
- ActiveSupport . on_load ( :active_support_test_case ) do
129
- ActiveSupport ::TestCase . assertionless_tests_behavior = v
130
- end
131
127
else
132
128
k = "#{ k } ="
133
129
ActiveSupport . public_send ( k , v ) if ActiveSupport . respond_to? k
Original file line number Diff line number Diff line change 3
3
require "minitest"
4
4
require "active_support/testing/tagged_logging"
5
5
require "active_support/testing/setup_and_teardown"
6
- require "active_support/testing/assertionless_tests "
6
+ require "active_support/testing/tests_without_assertions "
7
7
require "active_support/testing/assertions"
8
8
require "active_support/testing/error_reporter_assertions"
9
9
require "active_support/testing/deprecation"
@@ -143,7 +143,7 @@ def parallelize_teardown(&block)
143
143
144
144
include ActiveSupport ::Testing ::TaggedLogging
145
145
prepend ActiveSupport ::Testing ::SetupAndTeardown
146
- prepend ActiveSupport ::Testing ::AssertionlessTests
146
+ prepend ActiveSupport ::Testing ::TestsWithoutAssertions
147
147
include ActiveSupport ::Testing ::Assertions
148
148
include ActiveSupport ::Testing ::ErrorReporterAssertions
149
149
include ActiveSupport ::Testing ::Deprecation
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveSupport
4
+ module Testing
5
+ # Warns when a test case does not perform any assertions.
6
+ #
7
+ # This is helpful in detecting broken tests that do not perform intended assertions.
8
+ module TestsWithoutAssertions # :nodoc:
9
+ def after_teardown
10
+ super
11
+
12
+ return if skipped? || error?
13
+
14
+ if assertions == 0
15
+ file , line = method ( name ) . source_location
16
+ message = "Test is missing assertions: `#{ name } ` #{ file } :#{ line } "
17
+ warn message
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../abstract_unit"
4
+ require "active_support/core_ext/object/with"
5
+
6
+ module TestsWithoutAssertionsTest
7
+ module Tests
8
+ def test_without_assertions
9
+ end
10
+ end
11
+
12
+ class TestsWithoutAssertionsWarnTest < ActiveSupport ::TestCase
13
+ module AfterTeardown
14
+ def after_teardown
15
+ _out , err = capture_io do
16
+ super
17
+ end
18
+
19
+ assert_match ( /Test is missing assertions: `test_without_assertions` .+test_without_assertions_test\. rb:\d +/ , err )
20
+ end
21
+ end
22
+
23
+ include Tests
24
+ prepend AfterTeardown
25
+ end
26
+ end
Original file line number Diff line number Diff line change @@ -64,7 +64,6 @@ Below are the default values associated with each target version. In cases of co
64
64
- [ ` config.active_record.automatically_invert_plural_associations ` ] ( #config-active-record-automatically-invert-plural-associations ) : ` true `
65
65
- [ ` config.active_record.validate_migration_timestamps ` ] ( #config-active-record-validate-migration-timestamps ) : ` true `
66
66
- [ ` config.active_storage.web_image_content_types ` ] ( #config-active-storage-web-image-content-types ) : ` %w[image/png image/jpeg image/gif image/webp] `
67
- - [ ` config.active_support.assertionless_tests_behavior ` ] ( #config-active-support-assertionless-tests-behavior ) : ` :log `
68
67
69
68
#### Default Values for Target Version 7.1
70
69
@@ -2657,18 +2656,6 @@ The default value depends on the `config.load_defaults` target version:
2657
2656
| (original) | ` false` |
2658
2657
| 7.0 | ` true` |
2659
2658
2660
- # ### `config.active_support.assertionless_tests_behavior`
2661
-
2662
- Controls the behavior when a test do not run any assertions. The following options are available:
2663
-
2664
- * ` :ignore` - Assertionless tests will be ignored. This is the default.
2665
-
2666
- * ` :log` - Assertionless tests will be logged via ` Rails.logger` at the ` :warn` level.
2667
-
2668
- * ` :raise` - Assertionless tests will be considered as failed and raise an error.
2669
-
2670
- * Custom proc - A custom proc can be provided. It should accept an error message.
2671
-
2672
2659
# ### `ActiveSupport::Logger.silencer`
2673
2660
2674
2661
Is set to ` false` to disable the ability to silence logging in a block. The default is ` true` .
Original file line number Diff line number Diff line change @@ -334,12 +334,6 @@ def load_defaults(target_version)
334
334
active_record . validate_migration_timestamps = true
335
335
active_record . automatically_invert_plural_associations = true
336
336
end
337
-
338
- if respond_to? ( :active_support )
339
- if Rails . env . local?
340
- active_support . assertionless_tests_behavior = :log
341
- end
342
- end
343
337
else
344
338
raise "Unknown version #{ target_version . to_s . inspect } "
345
339
end
Original file line number Diff line number Diff line change 66
66
# on `Post`. With this option enabled, it will also look for a `:comments` association.
67
67
#++
68
68
# Rails.application.config.active_record.automatically_invert_plural_associations = true
69
-
70
- ###
71
- # Controls whether Active Support should log tests without assertions.
72
- # This is helpful in detecting broken tests that do not perform intended assertions.
73
- # To disable this behavior, set the value to `:ignore` inside the `config/application.rb` (NOT this file).
74
- #
75
- #++
76
- # Rails.application.config.active_support.assertionless_tests_behavior = :log
You can’t perform that action at this time.
0 commit comments