forked from rubocop/rubocop-minitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix rubocop#301] Add new Minitest/NoFocus cop
- Loading branch information
1 parent
eb196db
commit 11abb1e
Showing
5 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#301](https://github.com/rubocop/rubocop-minitest/issues/301): Add new Minitest/NoFocus cop. ([@jaredmoody][]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
module Minitest | ||
# Enforces tests are not focused | ||
# | ||
# @example | ||
# # bad | ||
# focus | ||
# test 'foo' do | ||
# end | ||
# | ||
# # good | ||
# test 'foo' do | ||
# end | ||
# | ||
class NoFocus < Base | ||
MSG = 'Remove `focus` from tests.' | ||
RESTRICT_ON_SEND = [:focus].freeze | ||
|
||
def_node_matcher :focused?, <<~PATTERN | ||
(send nil? :focus ...) | ||
PATTERN | ||
|
||
def on_send(node) | ||
return unless focused?(node) | ||
|
||
add_offense node | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../test_helper' | ||
|
||
class NoFocusTest < Minitest::Test | ||
def test_registers_offense_when_using_direct_focus | ||
assert_offense(<<~RUBY) | ||
class FooTest < Minitest::Test | ||
focus test 'foo' do | ||
^^^^^^^^^^^^^^^^ Remove `focus` from tests. | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
def test_registers_offense_when_using_indirect_focus | ||
assert_offense(<<~RUBY) | ||
class FooTest < Minitest::Test | ||
focus | ||
^^^^^ Remove `focus` from tests. | ||
test 'foo' do | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
def test_does_not_register_offense_when_no_focus | ||
assert_no_offenses(<<~RUBY) | ||
class FooTest < Minitest::Test | ||
test 'foo' do | ||
end | ||
end | ||
RUBY | ||
end | ||
end |