diff --git a/changelog/fix_a_false_negative_for_rails_action_controller_test_case.md b/changelog/fix_a_false_negative_for_rails_action_controller_test_case.md new file mode 100644 index 0000000000..546326fb02 --- /dev/null +++ b/changelog/fix_a_false_negative_for_rails_action_controller_test_case.md @@ -0,0 +1 @@ +* [#824](https://github.com/rubocop/rubocop-rails/pull/824): Fix a false negative for `Rails/ActionControllerTestCase` when the class is namespaced. ([@vlad-pisanov][]) diff --git a/lib/rubocop/cop/rails/action_controller_test_case.rb b/lib/rubocop/cop/rails/action_controller_test_case.rb index 92959c771c..a78d1d12f4 100644 --- a/lib/rubocop/cop/rails/action_controller_test_case.rb +++ b/lib/rubocop/cop/rails/action_controller_test_case.rb @@ -30,7 +30,7 @@ class ActionControllerTestCase < Base def_node_matcher :action_controller_test_case?, <<~PATTERN (class - (const nil? _) + (const _ _) (const (const {nil? cbase} :ActionController) :TestCase) _) PATTERN diff --git a/spec/rubocop/cop/rails/action_controller_test_case_spec.rb b/spec/rubocop/cop/rails/action_controller_test_case_spec.rb index a9ac35989d..0ad152c3e8 100644 --- a/spec/rubocop/cop/rails/action_controller_test_case_spec.rb +++ b/spec/rubocop/cop/rails/action_controller_test_case_spec.rb @@ -53,6 +53,19 @@ def test_foo RUBY end + it 'adds offense when extending `ActionController::TestCase` with a namespace' do + expect_offense(<<~RUBY) + class Foo::Bar::MyControllerTest < ActionController::TestCase + ^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `ActionDispatch::IntegrationTest` instead. + end + RUBY + + expect_correction(<<~RUBY) + class Foo::Bar::MyControllerTest < ActionDispatch::IntegrationTest + end + RUBY + end + it 'does not add offense when extending `ActionDispatch::IntegrationTest`' do expect_no_offenses(<<~RUBY) class MyControllerTest < ActionDispatch::IntegrationTest