Sha256: 67f56f386c1bad6abc6d7f8cc4149bc6cd98ef1b700a5e0fe1e07367b49bcb81

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

require_relative '../../spec_helper'
require_lib 'reek/smells/smell_detector'

RSpec.describe Reek::Smells::SmellDetector do
  describe '.todo_configuration_for' do
    it 'returns exclusion configuration for the given smells' do
      detector = described_class.new
      smell = create(:smell_warning, smell_detector: detector, context: 'Foo#bar')
      result = described_class.todo_configuration_for([smell])
      expect(result).to eq('SmellDetector' => { 'exclude' => ['Foo#bar'] })
    end

    it 'merges identical contexts' do
      detector = described_class.new
      smell = create(:smell_warning, smell_detector: detector, context: 'Foo#bar')
      result = described_class.todo_configuration_for([smell, smell])
      expect(result).to eq('SmellDetector' => { 'exclude' => ['Foo#bar'] })
    end

    context 'with default exclusions present' do
      let(:subclass) { Reek::Smells::TooManyStatements }

      before do
        expect(subclass.default_config['exclude']).to eq ['initialize']
      end

      it 'includes default exclusions' do
        detector = subclass.new
        smell = create(:smell_warning, smell_detector: detector, context: 'Foo#bar')
        result = subclass.todo_configuration_for([smell])

        expect(result).to eq('TooManyStatements' => { 'exclude' => ['initialize', 'Foo#bar'] })
      end
    end
  end

  describe '.valid_detector?' do
    it 'returns true for a valid detector' do
      expect(described_class.valid_detector?('DuplicateMethodCall')).to be true
    end

    it 'returns false for an invalid detector' do
      expect(described_class.valid_detector?('Unknown')).to be false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reek-4.4.2 spec/reek/smells/smell_detector_spec.rb