Skip to content

Commit 6a6c7e6

Browse files
committed
Remove configuration to control what we do with tests without assertions
This is too much complexity for something low value. Let's just always warn when a test doesn't have any assertions. If people want to raise an error or ignore them, they can do so by overriding `Warning.warn`.
1 parent 64ab211 commit 6a6c7e6

File tree

10 files changed

+52
-162
lines changed

10 files changed

+52
-162
lines changed

activesupport/CHANGELOG.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
* Allow assertionless tests to be reported.
1+
* Warn on tests without assertions.
22

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.
44
This is helpful in detecting broken tests that do not perform intended assertions.
55

6-
```ruby
7-
config.active_support.assertionless_tests_behavior = :raise
8-
```
9-
106
*fatkodima*
117

128
* Support `hexBinary` type in `ActiveSupport::XmlMini`.

activesupport/lib/active_support/railtie.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ class Railtie < Rails::Railtie # :nodoc:
124124
ActiveSupport.deprecator.warn("config.active_support.remove_deprecated_time_with_zone_name is deprecated and will be removed in Rails 7.2.")
125125
elsif k == :use_rfc4122_namespaced_uuids
126126
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
131127
else
132128
k = "#{k}="
133129
ActiveSupport.public_send(k, v) if ActiveSupport.respond_to? k

activesupport/lib/active_support/test_case.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require "minitest"
44
require "active_support/testing/tagged_logging"
55
require "active_support/testing/setup_and_teardown"
6-
require "active_support/testing/assertionless_tests"
6+
require "active_support/testing/tests_without_assertions"
77
require "active_support/testing/assertions"
88
require "active_support/testing/error_reporter_assertions"
99
require "active_support/testing/deprecation"
@@ -143,7 +143,7 @@ def parallelize_teardown(&block)
143143

144144
include ActiveSupport::Testing::TaggedLogging
145145
prepend ActiveSupport::Testing::SetupAndTeardown
146-
prepend ActiveSupport::Testing::AssertionlessTests
146+
prepend ActiveSupport::Testing::TestsWithoutAssertions
147147
include ActiveSupport::Testing::Assertions
148148
include ActiveSupport::Testing::ErrorReporterAssertions
149149
include ActiveSupport::Testing::Deprecation

activesupport/lib/active_support/testing/assertionless_tests.rb

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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

activesupport/test/testing/assertionless_tests_test.rb

Lines changed: 0 additions & 66 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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

guides/source/configuring.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Below are the default values associated with each target version. In cases of co
6464
- [`config.active_record.automatically_invert_plural_associations`](#config-active-record-automatically-invert-plural-associations): `true`
6565
- [`config.active_record.validate_migration_timestamps`](#config-active-record-validate-migration-timestamps): `true`
6666
- [`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`
6867

6968
#### Default Values for Target Version 7.1
7069

@@ -2657,18 +2656,6 @@ The default value depends on the `config.load_defaults` target version:
26572656
| (original) | `false` |
26582657
| 7.0 | `true` |
26592658

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-
26722659
#### `ActiveSupport::Logger.silencer`
26732660

26742661
Is set to `false` to disable the ability to silence logging in a block. The default is `true`.

railties/lib/rails/application/configuration.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,6 @@ def load_defaults(target_version)
334334
active_record.validate_migration_timestamps = true
335335
active_record.automatically_invert_plural_associations = true
336336
end
337-
338-
if respond_to?(:active_support)
339-
if Rails.env.local?
340-
active_support.assertionless_tests_behavior = :log
341-
end
342-
end
343337
else
344338
raise "Unknown version #{target_version.to_s.inspect}"
345339
end

railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_2.rb.tt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,3 @@
6666
# on `Post`. With this option enabled, it will also look for a `:comments` association.
6767
#++
6868
# 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

0 commit comments

Comments
 (0)