spec/scss_lint/config_spec.rb in scss-lint-0.33.0 vs spec/scss_lint/config_spec.rb in scss-lint-0.34.0
- old
+ new
@@ -60,19 +60,19 @@
context 'with an empty config file' do
let(:config_file) { '' }
it 'returns the default configuration' do
- subject.should == described_class.default
+ subject.options.should == described_class.default.options
end
end
context 'with a config file containing only comments' do
let(:config_file) { '# This is a comment' }
it 'returns the default configuration' do
- subject.should == described_class.default
+ subject.options.should == described_class.default.options
end
end
context 'with a file configuring an unknown linter' do
let(:config_file) { 'linters: { MadeUpLinterName: { enabled: true } }' }
@@ -86,11 +86,11 @@
context 'with a config file setting the same configuration as the default' do
let(:config_file) { default_file }
it 'returns a configuration equivalent to the default' do
- subject.should == described_class.default
+ subject.options.should == described_class.default.options
end
end
context 'with a config file setting the same subset of settings as the default' do
let(:config_file) { <<-FILE }
@@ -98,166 +98,14 @@
FakeConfigLinter:
enabled: true
FILE
it 'returns a configuration equivalent to the default' do
- subject.should == described_class.default
+ subject.options.should == described_class.default.options
end
end
- context 'with a file that includes another configuration file' do
- let(:included_file_path) { '../included_file.yml' }
-
- let(:config_file) { <<-FILE }
- inherit_from: #{included_file_path}
-
- linters:
- FakeConfigLinter:
- enabled: true
- some_other_option: some_other_value
- FILE
-
- before do
- described_class.stub(:load_file_contents)
- .with("#{config_dir}/" + included_file_path)
- .and_return(included_file)
- end
-
- context 'and the included file has a different setting from the default' do
- let(:included_file) { <<-FILE }
- linters:
- OtherFakeConfigLinter:
- enabled: true
- some_option: some_value
- FILE
-
- it 'reflects the different setting of the included file' do
- subject.options['linters']['OtherFakeConfigLinter']
- .should == { 'enabled' => true, 'some_option' => 'some_value' }
- end
-
- it 'reflects the different setting of the file that included the file' do
- subject.options['linters']['FakeConfigLinter']
- .should == { 'enabled' => true, 'some_other_option' => 'some_other_value' }
- end
- end
-
- context 'and the included file has the same setting as the default' do
- let(:included_file) { <<-FILE }
- linters:
- OtherFakeConfigLinter:
- enabled: false
- FILE
-
- it 'does not alter the default configuration' do
- subject.options['linters']['OtherFakeConfigLinter']
- .should == { 'enabled' => false }
- end
-
- it 'reflects the different setting of the file that included the file' do
- subject.options['linters']['FakeConfigLinter']
- .should == { 'enabled' => true, 'some_other_option' => 'some_other_value' }
- end
- end
-
- context 'and the included file includes another file' do
- let(:other_included_file_path) { '/some/abs/other_included_file.yml' }
-
- let(:other_included_file) { <<-FILE }
- linters:
- OtherFakeConfigLinter:
- yet_another_option: yet_another_value
- FILE
-
- let(:included_file) { <<-FILE }
- inherit_from: #{other_included_file_path}
-
- linters:
- OtherFakeConfigLinter:
- enabled: true
- some_option: some_value
- FILE
-
- before do
- described_class.stub(:load_file_contents)
- .with(other_included_file_path)
- .and_return(other_included_file)
- end
-
- it "reflects the different setting of the included file's included file" do
- subject.options['linters']['OtherFakeConfigLinter']
- .should == {
- 'enabled' => true,
- 'some_option' => 'some_value',
- 'yet_another_option' => 'yet_another_value',
- }
- end
-
- it 'reflects the different setting of the file that included the file' do
- subject.options['linters']['FakeConfigLinter']
- .should == { 'enabled' => true, 'some_other_option' => 'some_other_value' }
- end
- end
- end
-
- context 'with a file that includes multiple configuration files' do
- let(:included_file_path) { '../included_file.yml' }
- let(:other_included_file_path) { '/some/dir/other_included_file.yml' }
-
- let(:config_file) { <<-FILE }
- inherit_from:
- - #{included_file_path}
- - #{other_included_file_path}
-
- linters:
- FakeConfigLinter:
- enabled: true
- some_other_option: some_other_value
- FILE
-
- before do
- described_class.stub(:load_file_contents)
- .with("#{config_dir}/" + included_file_path)
- .and_return(included_file)
-
- described_class.stub(:load_file_contents)
- .with(other_included_file_path)
- .and_return(other_included_file)
- end
-
- context 'and the included files have settings different from each other' do
- let(:included_file) { <<-FILE }
- linters:
- OtherFakeConfigLinter:
- enabled: true
- some_option: earlier_value
- some_other_option: value
- FILE
-
- let(:other_included_file) { <<-FILE }
- linters:
- OtherFakeConfigLinter:
- enabled: true
- some_option: later_value
- FILE
-
- it 'uses the value of the file that was included last' do
- subject.options['linters']['OtherFakeConfigLinter']['some_option']
- .should == 'later_value'
- end
-
- it 'loads settings from both included files' do
- subject.options['linters']['OtherFakeConfigLinter']
- .should == {
- 'enabled' => true,
- 'some_option' => 'later_value',
- 'some_other_option' => 'value',
- }
- end
- end
- end
-
context 'when a wildcard is used for a namespaced linter' do
let(:default_file) { <<-FILE }
linters:
SomeNamespace::*:
enabled: false
@@ -278,56 +126,9 @@
it 'returns the same options for all linters under that namespace' do
subject.linter_options(SCSSLint::Linter::SomeNamespace::FakeLinter1)
.should eq('enabled' => true)
subject.linter_options(SCSSLint::Linter::SomeNamespace::FakeLinter2)
.should eq('enabled' => true)
- end
- end
- end
-
- describe '.for_file' do
- include_context 'isolated environment'
-
- let(:linted_file) { File.join('foo', 'bar', 'baz', 'file-being-linted.scss') }
- subject { described_class.for_file(linted_file) }
-
- before do
- described_class.instance_variable_set(:@dir_to_config, nil) # Clear cache
- FileUtils.mkpath(File.dirname(linted_file))
- FileUtils.touch(linted_file)
- end
-
- context 'when there are no configuration files in the directory hierarchy' do
- it { should be_nil }
- end
-
- context 'when there is a configuration file in the same directory' do
- let(:config_file) { File.join('foo', 'bar', 'baz', '.scss-lint.yml') }
- before { FileUtils.touch(config_file) }
-
- it 'loads that configuration file' do
- described_class.should_receive(:load).with(File.expand_path(config_file))
- subject
- end
- end
-
- context 'when there is a configuration file in the parent directory' do
- let(:config_file) { File.join('foo', 'bar', '.scss-lint.yml') }
- before { FileUtils.touch(config_file) }
-
- it 'loads that configuration file' do
- described_class.should_receive(:load).with(File.expand_path(config_file))
- subject
- end
- end
-
- context 'when there is a configuration file in some ancestor directory' do
- let(:config_file) { File.join('foo', '.scss-lint.yml') }
- before { FileUtils.touch(config_file) }
-
- it 'loads that configuration file' do
- described_class.should_receive(:load).with(File.expand_path(config_file))
- subject
end
end
end
describe '#linter_options' do