require 'spec_helper'

describe SCSSLint::LinterRegistry do
  context 'when including the LinterRegistry module' do
    it 'adds the linter to the set of registered linters' do
      expect do
        class FakeLinter < SCSSLint::Linter
          include SCSSLint::LinterRegistry
        end
      end.to change { SCSSLint::LinterRegistry.linters.count }.by(1)
    end
  end

  describe '.extract_linters_from' do
    module SCSSLint
      class Linter::SomeLinter < Linter; include LinterRegistry; end
      class Linter::SomeOtherLinter < Linter::SomeLinter; end
    end
    let(:linters) do
      [SCSSLint::Linter::SomeLinter, SCSSLint::Linter::SomeOtherLinter]
    end

    context 'when the linters exist' do
      let(:linter_names) { %w[SomeLinter SomeOtherLinter] }

      it 'returns the linters' do
        subject.extract_linters_from(linter_names).should == linters
      end
    end

    context "when the linters don't exist" do
      let(:linter_names) { ['SomeRandomLinter'] }

      it 'raises an error' do
        expect do
          subject.extract_linters_from(linter_names)
        end.to raise_error(SCSSLint::NoSuchLinter)
      end
    end
  end
end

require 'spec_helper'

describe SCSSLint::LinterRegistry do
  context 'when including the LinterRegistry module' do
    after do
      described_class.linters.delete(FakeLinter)
    end

    it 'adds the linter to the set of registered linters' do
      expect do
        class FakeLinter < SCSSLint::Linter
          include SCSSLint::LinterRegistry
        end
      end.to change { described_class.linters.count }.by(1)
    end
  end

  describe '.extract_linters_from' do
    module SCSSLint
      class Linter::SomeLinter < Linter; end
      class Linter::SomeOtherLinter < Linter; end
    end

    let(:linters) do
      [SCSSLint::Linter::SomeLinter, SCSSLint::Linter::SomeOtherLinter]
    end

    before do
      described_class.stub(:linters).and_return(linters)
    end

    context 'when the linters exist' do
      let(:linter_names) { %w[SomeLinter SomeOtherLinter] }

      it 'returns the linters' do
        subject.extract_linters_from(linter_names).should == linters
      end
    end

    context "when the linters don't exist" do
      let(:linter_names) { ['SomeRandomLinter'] }

      it 'raises an error' do
        expect do
          subject.extract_linters_from(linter_names)
        end.to raise_error(SCSSLint::NoSuchLinter)
      end
    end
  end
end

Fix LinterRegistry specs to not pollute actual registry
Fix LinterRegistry specs to not pollute actual registry

In the process of writing some other specs, there was a problem where
the linters inserted into the registry by this spec were breaking other
specs.

Fix by modifying the specs to not modify the global linter registry.

Change-Id: I22c0e282003da4f6ebc8f52758654f338e64bd5f
Reviewed-on: https://gerrit.causes.com/30918
Tested-by: jenkins <d95b56ce41a2e1ac4cecdd398defd7414407cc08@causes.com>
Reviewed-by: Shane da Silva <6f6e68d1df92f30cb4b3ce35260ddf94a402f33d@causes.com>
