Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`.
- Loading branch information
1 parent
64ab211
commit 6a6c7e6
Showing
10 changed files
with
52 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
activesupport/lib/active_support/testing/assertionless_tests.rb
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
activesupport/lib/active_support/testing/tests_without_assertions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveSupport | ||
module Testing | ||
# Warns when a test case does not perform any assertions. | ||
# | ||
# This is helpful in detecting broken tests that do not perform intended assertions. | ||
module TestsWithoutAssertions # :nodoc: | ||
def after_teardown | ||
super | ||
|
||
return if skipped? || error? | ||
|
||
if assertions == 0 | ||
file, line = method(name).source_location | ||
message = "Test is missing assertions: `#{name}` #{file}:#{line}" | ||
warn message | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dhh
Member
|
||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
activesupport/test/testing/test_without_assertions_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../abstract_unit" | ||
require "active_support/core_ext/object/with" | ||
|
||
module TestsWithoutAssertionsTest | ||
module Tests | ||
def test_without_assertions | ||
end | ||
end | ||
|
||
class TestsWithoutAssertionsWarnTest < ActiveSupport::TestCase | ||
module AfterTeardown | ||
def after_teardown | ||
_out, err = capture_io do | ||
super | ||
end | ||
|
||
assert_match(/Test is missing assertions: `test_without_assertions` .+test_without_assertions_test\.rb:\d+/, err) | ||
end | ||
end | ||
|
||
include Tests | ||
prepend AfterTeardown | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No need to assign message to a local var here, imo.