Sha256: 1f1502edf638fdb20148793c1c4dc43a96012bbc5425034a5238a84b5721a620

Contents?: true

Size: 1.79 KB

Versions: 13

Compression:

Stored size: 1.79 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe RuboCop::ConfigStore do
  subject(:config_store) { described_class.new }

  before do
    allow(RuboCop::ConfigLoader).to receive(:configuration_file_for) do |arg|
      # File tree:
      # file1
      # dir/.rubocop.yml
      # dir/file2
      # dir/subdir/file3
      (arg =~ /dir/ ? 'dir' : '.') + '/.rubocop.yml'
    end
    allow(RuboCop::ConfigLoader)
      .to receive(:configuration_from_file) { |arg| arg }
    allow(RuboCop::ConfigLoader)
      .to receive(:load_file) { |arg| RuboCop::Config.new(arg) }
    allow(RuboCop::ConfigLoader)
      .to receive(:merge_with_default) { |config| "merged #{config}" }
  end

  describe '.for' do
    it 'always uses config specified in command line' do
      config_store.options_config = :options_config
      expect(config_store.for('file1')).to eq('merged options_config')
    end

    context 'when no config specified in command line' do
      it 'gets config path and config from cache if available' do
        expect(RuboCop::ConfigLoader).to receive(:configuration_file_for).once
          .with('dir')
        expect(RuboCop::ConfigLoader).to receive(:configuration_file_for).once
          .with('dir/subdir')
        # The stub returns the same config path for dir and dir/subdir.
        expect(RuboCop::ConfigLoader).to receive(:configuration_from_file).once
          .with('dir/.rubocop.yml')

        config_store.for('dir/file2')
        config_store.for('dir/file2')
        config_store.for('dir/subdir/file3')
      end

      it 'searches for config path if not available in cache' do
        expect(RuboCop::ConfigLoader).to receive(:configuration_file_for).once
        expect(RuboCop::ConfigLoader).to receive(:configuration_from_file).once
        config_store.for('file1')
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/config_store_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/spec/rubocop/config_store_spec.rb
rubocop-0.29.1 spec/rubocop/config_store_spec.rb
rubocop-0.29.0 spec/rubocop/config_store_spec.rb
rubocop-0.28.0 spec/rubocop/config_store_spec.rb
rubocop-0.27.1 spec/rubocop/config_store_spec.rb
rubocop-0.27.0 spec/rubocop/config_store_spec.rb
rubocop-0.26.1 spec/rubocop/config_store_spec.rb
rubocop-0.26.0 spec/rubocop/config_store_spec.rb
rubocop-0.25.0 spec/rubocop/config_store_spec.rb
rubocop-0.24.1 spec/rubocop/config_store_spec.rb
rubocop-0.24.0 spec/rubocop/config_store_spec.rb
rubocop-0.23.0 spec/rubocop/config_store_spec.rb