Skip to content

Commit

Permalink
Accept pending cops in the development build
Browse files Browse the repository at this point in the history
Follow up of rubocop#7646 (comment).

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 <top (required)>'
     # ./spec/support/cli_spec_behavior.rb:26:in `block (2 levels) in
<top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:29:in `block (4 levels) in
<top (required)>'
     # ./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
<top (required)>'
     # ./lib/rubocop/rspec/shared_contexts.rb:8:in `block (2 levels) in
<top (required)>'
```

This PR prevents those tests from catching a pending cop warning.
OTOH, this PR supplements the E2E test for a pending cop warning.
  • Loading branch information
koic committed Jan 23, 2020
1 parent 8246647 commit 5d6e0a3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
40 changes: 39 additions & 1 deletion spec/rubocop/cli/cli_options_spec.rb
Expand Up @@ -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
..
Expand Down
16 changes: 16 additions & 0 deletions 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

0 comments on commit 5d6e0a3

Please sign in to comment.