diff --git a/lib/rubocop/cop/internal_affairs/cop_description.rb b/lib/rubocop/cop/internal_affairs/cop_description.rb index 769be81acfde..d5097d4d3bc9 100644 --- a/lib/rubocop/cop/internal_affairs/cop_description.rb +++ b/lib/rubocop/cop/internal_affairs/cop_description.rb @@ -114,7 +114,7 @@ def comment_index(node, comment_line) end def relevant_file?(file) - file.match?(%r{/cop/.*\.rb\z}) + file.match?(%r{/cop/.*\.rb\z}) && super end end end diff --git a/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb b/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb index c31a4b571a6a..bb0193b40d59 100644 --- a/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +++ b/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb @@ -46,7 +46,7 @@ def assertions_using_described_class_msg # Only process spec files def relevant_file?(file) - file.end_with?('_spec.rb') + file.end_with?('_spec.rb') && super end end end diff --git a/spec/rubocop/cop/internal_affairs/cop_description_spec.rb b/spec/rubocop/cop/internal_affairs/cop_description_spec.rb index 65b973a4d688..26136ec57142 100644 --- a/spec/rubocop/cop/internal_affairs/cop_description_spec.rb +++ b/spec/rubocop/cop/internal_affairs/cop_description_spec.rb @@ -152,4 +152,33 @@ class Foo < Base RUBY end end + + context 'when the file is excluded' do + before do + allow_any_instance_of(described_class).to receive(:relevant_file?).and_call_original # rubocop:disable RSpec/AnyInstance + end + + let(:config) do + RuboCop::Config.new( + 'InternalAffairs/CopDescription' => { 'Exclude' => ['**/example_cop.rb'] } + ) + end + + it 'does not register an offense' do + expect_no_offenses(<<~RUBY, 'lib/rubocop/cop/example_cop.rb') + module RuboCop + module Cop + module Lint + # + # Checks some problem + # + # ... + class Foo < Base + end + end + end + end + RUBY + end + end end diff --git a/spec/rubocop/cop/internal_affairs/useless_message_assertion_spec.rb b/spec/rubocop/cop/internal_affairs/useless_message_assertion_spec.rb index 80bc2c889de3..c822d7bd1831 100644 --- a/spec/rubocop/cop/internal_affairs/useless_message_assertion_spec.rb +++ b/spec/rubocop/cop/internal_affairs/useless_message_assertion_spec.rb @@ -41,4 +41,18 @@ it 'does not register an offense and no error when empty file' do expect_no_offenses('', 'example_spec.rb') end + + context 'when the file is excluded' do + let(:config) do + RuboCop::Config.new( + 'InternalAffairs/UselessMessageAssertion' => { 'Exclude' => ['**/example_spec.rb'] } + ) + end + + it 'does not register an offense' do + expect_no_offenses(<<~RUBY, 'example_spec.rb') + let(:msg) { described_class::MSG } + RUBY + end + end end