Skip to content

Commit

Permalink
[Fixes rubocop#8077] Restore compatibility for Team.new
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Jun 2, 2020
1 parent 898b996 commit af67c19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rubocop/cop/team.rb
Expand Up @@ -31,6 +31,14 @@ def initialize(cops, config = nil, options = nil)
validate_config
end

# @return [Team]
def self.new(cop_or_classes, config, options = nil)
# Support v0 api:
return mobilize(cop_or_classes, config, options) if cop_or_classes.first.is_a?(Class)

super
end

# @return [Team] with cops assembled from the given `cop_classes`
def self.mobilize(cop_classes, config, options = nil)
options ||= DEFAULT_OPTIONS
Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/cop/team_spec.rb
Expand Up @@ -370,4 +370,17 @@ def external_dependency_checksum
end
end
end

describe '.new' do
it 'calls mobilize when passed classes' do
expect(described_class).to receive(:mobilize).with(cop_classes, config, options)
described_class.new(cop_classes, config, options)
end

it 'accepts cops directly classes' do
cop = RuboCop::Cop::Metrics::AbcSize.new
team = described_class.new([cop], config, options)
expect(team.cops.first).to equal(cop)
end
end
end

0 comments on commit af67c19

Please sign in to comment.