Skip to content

Commit 80c0902

Browse files
authored
Merge pull request rubocop#788 from koic/fix_a_false_negative_for_rails_action_controller_test_case
[Fix rubocop#786] Fix a false negative for `Rails/ActionControllerTestCase`
2 parents 86f2182 + 054e4ef commit 80c0902

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#786](https://github.com/rubocop/rubocop-rails/issues/786): Fix a false negative for `Rails/ActionControllerTestCase` when extending `ActionController::TestCase` and having a method definition. ([@koic][])

lib/rubocop/cop/rails/action_controller_test_case.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ActionControllerTestCase < Base
3131
def_node_matcher :action_controller_test_case?, <<~PATTERN
3232
(class
3333
(const nil? _)
34-
(const (const {nil? cbase} :ActionController) :TestCase) nil?)
34+
(const (const {nil? cbase} :ActionController) :TestCase) _)
3535
PATTERN
3636

3737
def on_class(node)

spec/rubocop/cop/rails/action_controller_test_case_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,23 @@ class MyControllerTest < ActionDispatch::IntegrationTest
3636
RUBY
3737
end
3838

39+
it 'adds offense when extending `ActionController::TestCase` and having a method definition' do
40+
expect_offense(<<~RUBY)
41+
class MyControllerTest < ActionController::TestCase
42+
^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `ActionDispatch::IntegrationTest` instead.
43+
def test_foo
44+
end
45+
end
46+
RUBY
47+
48+
expect_correction(<<~RUBY)
49+
class MyControllerTest < ActionDispatch::IntegrationTest
50+
def test_foo
51+
end
52+
end
53+
RUBY
54+
end
55+
3956
it 'does not add offense when extending `ActionDispatch::IntegrationTest`' do
4057
expect_no_offenses(<<~RUBY)
4158
class MyControllerTest < ActionDispatch::IntegrationTest

0 commit comments

Comments
 (0)