From 5d6e0a3590f8f8f57d8df4b7d4faa1b052a685e4 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 22 Jan 2020 23:32:21 +0900 Subject: [PATCH] Accept pending cops in the development build Follow up of https://github.com/rubocop-hq/rubocop/pull/7646#discussion_r365585616. This PR accepts pending cops in the development build. Some tests fail with the following warnings when using the `Enabled: pending` status. ```console % bundle exec rake spec (snip) 1) RuboCop::CLI --only when one cop is given accepts cop names from plugins Failure/Error: raise output RuntimeError: The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file: - Style/ZeroLengthPredicate Inspecting 2 files .. 2 files inspected, no offenses detected # ./spec/rubocop/cli/cli_options_spec.rb:213:in `block (4 levels) in ' # ./spec/support/cli_spec_behavior.rb:26:in `block (2 levels) in ' # ./lib/rubocop/rspec/shared_contexts.rb:29:in `block (4 levels) in ' # ./lib/rubocop/path_util.rb:67:in `chdir' # ./lib/rubocop/path_util.rb:67:in `chdir' # ./lib/rubocop/rspec/shared_contexts.rb:28:in `block (3 levels) in ' # ./lib/rubocop/rspec/shared_contexts.rb:8:in `block (2 levels) in ' ``` This PR prevents those tests from catching a pending cop warning. OTOH, this PR supplements the E2E test for a pending cop warning. --- spec/rubocop/cli/cli_options_spec.rb | 40 +++++++++++++++++++++++- spec/support/suppress_pending_warning.rb | 16 ++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 spec/support/suppress_pending_warning.rb diff --git a/spec/rubocop/cli/cli_options_spec.rb b/spec/rubocop/cli/cli_options_spec.rb index d3f711736c6..5dff6be37b4 100644 --- a/spec/rubocop/cli/cli_options_spec.rb +++ b/spec/rubocop/cli/cli_options_spec.rb @@ -207,9 +207,47 @@ class SomeCop < Cop # process. Otherwise, the extra cop will affect other specs. output = `ruby -I . "#{rubocop}" --require redirect.rb --only Style/SomeCop` - expect($CHILD_STATUS.success?).to be_truthy + # Excludes a warning when new `Enabled: pending` status cop is specified + # in config/default.yml. + output_excluding_warn_for_pending_cops = + output.split("\n").last(4).join("\n") << "\n" + expect(output_excluding_warn_for_pending_cops) + .to eq(<<~RESULT) + Inspecting 2 files + .. + + 2 files inspected, no offenses detected + RESULT + end + + it 'accepts cop names from plugins with a pending cop' do + create_file('.rubocop.yml', <<~YAML) + require: rubocop_ext + + Style/SomeCop: + Description: Something + Enabled: pending + YAML + create_file('rubocop_ext.rb', <<~RUBY) + module RuboCop + module Cop + module Style + class SomeCop < Cop + end + end + end + end + RUBY + create_file('redirect.rb', '$stderr = STDOUT') + rubocop = "#{RuboCop::ConfigLoader::RUBOCOP_HOME}/exe/rubocop" + # Since we define a new cop class, we have to do this in a separate + # process. Otherwise, the extra cop will affect other specs. + output = + `ruby -I . "#{rubocop}" --require redirect.rb --only Style/SomeCop` expect(output) .to eq(<<~RESULT) + The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file: + - Style/SomeCop Inspecting 2 files .. diff --git a/spec/support/suppress_pending_warning.rb b/spec/support/suppress_pending_warning.rb new file mode 100644 index 00000000000..fc4038d1188 --- /dev/null +++ b/spec/support/suppress_pending_warning.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# +# This is a file that supports testing. An open class has been applied to +# `RuboCop::ConfigLoader.warn_on_pending_cops` to suppress pending cop +# warnings during testing. +# +module RuboCop + class ConfigLoader + class << self + def warn_on_pending_cops(config) + # noop + end + end + end +end