diff --git a/lib/rubocop/cop/team.rb b/lib/rubocop/cop/team.rb index c39bc13e3f2..543b6b854b4 100644 --- a/lib/rubocop/cop/team.rb +++ b/lib/rubocop/cop/team.rb @@ -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 diff --git a/spec/rubocop/cop/team_spec.rb b/spec/rubocop/cop/team_spec.rb index 963a8836b97..d02db9e6c69 100644 --- a/spec/rubocop/cop/team_spec.rb +++ b/spec/rubocop/cop/team_spec.rb @@ -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