| 
7 | 7 | 
 
  | 
8 | 8 |   let(:configuration) { RuboCop::Config.new(hash, loaded_path) }  | 
9 | 9 |   let(:loaded_path) { 'example/.rubocop.yml' }  | 
 | 10 | +  let(:requires) { [] }  | 
 | 11 | + | 
 | 12 | +  before { allow(configuration).to receive(:loaded_features).and_return(requires) }  | 
10 | 13 | 
 
  | 
11 | 14 |   describe '#validate', :isolated_environment do  | 
12 | 15 |     context 'when the configuration includes any obsolete cop name' do  | 
 | 
225 | 228 |         }  | 
226 | 229 |       end  | 
227 | 230 | 
 
  | 
228 |  | -      let(:expected_message) do  | 
229 |  | -        <<~OUTPUT.chomp  | 
230 |  | -          `Performance` cops have been extracted to the `rubocop-performance` gem.  | 
231 |  | -          (obsolete configuration found in example/.rubocop.yml, please update it)  | 
232 |  | -          `Rails` cops have been extracted to the `rubocop-rails` gem.  | 
233 |  | -          (obsolete configuration found in example/.rubocop.yml, please update it)  | 
234 |  | -        OUTPUT  | 
235 |  | -      end  | 
236 |  | - | 
237 |  | -      context 'when the gems are installed' do  | 
238 |  | -        before do  | 
239 |  | -          allow_any_instance_of(RuboCop::ConfigObsoletion::ExtractedCop)  | 
240 |  | -            .to receive(:gem_installed?).and_return(true)  | 
241 |  | -        end  | 
 | 231 | +      context 'when the extensions are loaded' do  | 
 | 232 | +        let(:requires) { %w[rubocop-rails rubocop-performance] }  | 
242 | 233 | 
 
  | 
243 | 234 |         it 'does not print a warning message' do  | 
244 | 235 |           expect { config_obsoletion.reject_obsolete! }.not_to raise_error  | 
245 | 236 |         end  | 
246 | 237 |       end  | 
247 | 238 | 
 
  | 
248 |  | -      context 'when only one gem is installed' do  | 
249 |  | -        before do  | 
250 |  | -          allow_any_instance_of(RuboCop::Lockfile)  | 
251 |  | -            .to receive(:includes_gem?).and_return(false)  | 
252 |  | -          allow_any_instance_of(RuboCop::Lockfile)  | 
253 |  | -            .to receive(:includes_gem?).with('rubocop-performance').and_return(true)  | 
254 |  | -        end  | 
 | 239 | +      context 'when only one extension is loaded' do  | 
 | 240 | +        let(:requires) { %w[rubocop-performance] }  | 
255 | 241 | 
 
  | 
256 | 242 |         let(:expected_message) do  | 
257 | 243 |           <<~OUTPUT.chomp  | 
 | 
270 | 256 |         end  | 
271 | 257 |       end  | 
272 | 258 | 
 
  | 
273 |  | -      context 'when the gems are not installed' do  | 
274 |  | -        before do  | 
275 |  | -          allow_any_instance_of(RuboCop::ConfigObsoletion::ExtractedCop)  | 
276 |  | -            .to receive(:gem_installed?).and_return(false)  | 
 | 259 | +      context 'when the extensions are not loaded' do  | 
 | 260 | +        let(:expected_message) do  | 
 | 261 | +          <<~OUTPUT.chomp  | 
 | 262 | +            `Performance` cops have been extracted to the `rubocop-performance` gem.  | 
 | 263 | +            (obsolete configuration found in example/.rubocop.yml, please update it)  | 
 | 264 | +            `Rails` cops have been extracted to the `rubocop-rails` gem.  | 
 | 265 | +            (obsolete configuration found in example/.rubocop.yml, please update it)  | 
 | 266 | +          OUTPUT  | 
277 | 267 |         end  | 
278 | 268 | 
 
  | 
279 | 269 |         it 'prints a warning message' do  | 
 | 
285 | 275 |           end  | 
286 | 276 |         end  | 
287 | 277 |       end  | 
 | 278 | + | 
 | 279 | +      context 'when the extensions are loaded via inherit_gem' do  | 
 | 280 | +        let(:resolver) { RuboCop::ConfigLoaderResolver.new }  | 
 | 281 | +        let(:gem_root) { File.expand_path('gems') }  | 
 | 282 | + | 
 | 283 | +        let(:hash) do  | 
 | 284 | +          {  | 
 | 285 | +            'inherit_gem' => { 'rubocop-includes' => '.rubocop.yml' },  | 
 | 286 | +            'Performance/Casecmp' => { 'Enabled': true }  | 
 | 287 | +          }  | 
 | 288 | +        end  | 
 | 289 | + | 
 | 290 | +        around do |example|  | 
 | 291 | +          RuboCop::Cop::Registry.with_temporary_global(RuboCop::Cop::Registry.new) { example.run }  | 
 | 292 | +        end  | 
 | 293 | + | 
 | 294 | +        before do  | 
 | 295 | +          create_file("#{gem_root}/rubocop-includes/.rubocop.yml", <<~YAML)  | 
 | 296 | +            require:  | 
 | 297 | +              - rubocop-performance  | 
 | 298 | +          YAML  | 
 | 299 | + | 
 | 300 | +          # Mock out a gem in order to test `inherit_gem`.  | 
 | 301 | +          gem_class = Struct.new(:gem_dir)  | 
 | 302 | +          mock_spec = gem_class.new(File.join(gem_root, 'rubocop-includes'))  | 
 | 303 | +          allow(Gem::Specification).to receive(:find_by_name)  | 
 | 304 | +            .with('rubocop-includes').and_return(mock_spec)  | 
 | 305 | + | 
 | 306 | +          # Resolve `inherit_gem`  | 
 | 307 | +          resolver.resolve_inheritance_from_gems(hash)  | 
 | 308 | +          resolver.resolve_inheritance(loaded_path, hash, loaded_path, false)  | 
 | 309 | + | 
 | 310 | +          allow(configuration).to receive(:loaded_features).and_call_original  | 
 | 311 | +        end  | 
 | 312 | + | 
 | 313 | +        it 'does not raise a ValidationError' do  | 
 | 314 | +          expect { config_obsoletion.reject_obsolete! }.not_to raise_error  | 
 | 315 | +        end  | 
 | 316 | +      end  | 
288 | 317 |     end  | 
289 | 318 | 
 
  | 
290 | 319 |     context 'when the configuration includes any obsolete parameters' do  | 
291 | 320 |       before do  | 
292 |  | -        allow_any_instance_of(RuboCop::Lockfile).to receive(:includes_gem?).and_return(true)  | 
 | 321 | +        allow(configuration).to receive(:loaded_features).and_return(%w[rubocop-rails])  | 
293 | 322 |       end  | 
294 | 323 | 
 
  | 
295 | 324 |       let(:hash) do  | 
 | 
0 commit comments