forked from sds/scss-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix non-multiple match report_lint failure message
- Loading branch information
Showing
4 changed files
with
281 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,7 @@ | |
SCSS | ||
|
||
it 'does not loop forever' do | ||
subject.should_not report_lint | ||
should_not report_lint | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,268 @@ | ||
require 'spec_helper' | ||
require 'rspec/matchers/fail_matchers' | ||
|
||
RSpec.configure do |config| | ||
config.include RSpec::Matchers::FailMatchers | ||
end | ||
|
||
RSpec::Matchers.define_negated_matcher :succeed, :raise_error | ||
|
||
# In these tests, we cover all of the combinations of successful and failed | ||
# matches, expecting and _not_ expecting lints, specified and unspecified line | ||
# numbers, specified and unspecified lint counts, and singular and multiple | ||
# lints. | ||
describe 'report_lint' do | ||
let(:subject) { SCSSLint::Linter::LeadingZero.new } | ||
|
||
def run_with(scss) | ||
subject.run(SCSSLint::Engine.new(code: scss), SCSSLint::Config.default.linter_options(subject)) | ||
end | ||
|
||
context 'when expecting no lints' do | ||
it 'matches zero expected lints' do | ||
run_with('p { margin: .5em; }') | ||
|
||
expect do | ||
should_not report_lint | ||
end.to succeed | ||
end | ||
|
||
it 'fails to match one lint with a meaningful message' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should_not report_lint | ||
end.to fail_with 'expected that a lint would not be reported' | ||
end | ||
end | ||
|
||
context 'when expecting no lints on a certain line' do | ||
it 'matches zero expected lints' do | ||
run_with('p { margin: .5em; }') | ||
|
||
expect do | ||
should_not report_lint line: 1 | ||
end.to succeed | ||
end | ||
|
||
it 'matches zero expected lints on the specified line' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should_not report_lint line: 10 | ||
end.to succeed | ||
end | ||
|
||
it 'fails to match one lint on the specified line with a meaningful message' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should_not report_lint line: 1 | ||
end.to fail_with 'expected that a lint would not be reported' | ||
end | ||
end | ||
|
||
context 'when expecting a lint' do | ||
it 'matches one expected lint' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should report_lint | ||
end.to succeed | ||
end | ||
|
||
it 'matches multiple lints' do | ||
run_with('p { margin: 0.5em 0.5em; }') | ||
|
||
expect do | ||
should report_lint | ||
end.to succeed | ||
end | ||
|
||
it 'fails to match zero lints with a meaningful message' do | ||
run_with('p { margin: .5em; }') | ||
|
||
expect do | ||
should report_lint | ||
end.to fail_with 'expected that a lint would be reported' | ||
end | ||
end | ||
|
||
context 'when expecting a lint on a certain line' do | ||
it 'matches one expected lint' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 1 | ||
end.to succeed | ||
end | ||
|
||
it 'matches multiple lints' do | ||
run_with('p { margin: 0.5em 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 1 | ||
end.to succeed | ||
end | ||
|
||
it 'fails to match zero lints with a meaningful message' do | ||
run_with('p { margin: .5em; }') | ||
|
||
expect do | ||
should report_lint line: 1 | ||
end.to fail_with 'expected that a lint would be reported on line 1' | ||
end | ||
|
||
it 'fails to match lints on the wrong line with a meaningful message' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 10 | ||
end.to fail_with 'expected that a lint would be reported on line 10, ' \ | ||
'but one lint was reported on line 1' | ||
end | ||
end | ||
|
||
context 'when expecting exactly one lint' do | ||
it 'matches one expected lint' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should report_lint count: 1 | ||
end.to succeed | ||
end | ||
|
||
it 'fails to match zero lints with a meaningful message' do | ||
run_with('p { margin: .5em; }') | ||
|
||
expect do | ||
should report_lint count: 1 | ||
end.to fail_with 'expected that exactly 1 lint would be reported' | ||
end | ||
|
||
it 'fails to match multiple lints with a meaningful message' do | ||
run_with('p { margin: 0.5em 0.5em; }') | ||
|
||
expect do | ||
should report_lint count: 1 | ||
end.to fail_with 'expected that exactly 1 lint would be reported, ' \ | ||
'but lints were reported on lines 1 and 1' | ||
end | ||
|
||
it 'fails to match lints on the wrong line with a meaningful message' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 10, count: 1 | ||
end.to fail_with 'expected that exactly 1 lint would be reported on ' \ | ||
'line 10, but one lint was reported on line 1' | ||
end | ||
end | ||
|
||
context 'when expecting multiple lints' do | ||
it 'matches multiple lints' do | ||
run_with('p { margin: 0.5em 0.5em; }') | ||
|
||
expect do | ||
should report_lint count: 2 | ||
end.to succeed | ||
end | ||
|
||
it 'fails to match zero lints with a meaningful message' do | ||
run_with('p { margin: .5em; }') | ||
|
||
expect do | ||
should report_lint count: 2 | ||
end.to fail_with 'expected that exactly 2 lints would be reported' | ||
end | ||
|
||
it 'fails to match one lint with a meaningful message' do | ||
run_with('p { margin: .5em; }') | ||
|
||
expect do | ||
should report_lint count: 2 | ||
end.to fail_with 'expected that exactly 2 lints would be reported' | ||
end | ||
|
||
it 'fails to match lints on the wrong line with a meaningful message' do | ||
run_with('p { margin: 0.5em 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 10, count: 2 | ||
end.to fail_with 'expected that exactly 2 lints would be reported on ' \ | ||
'line 10, but lints were reported on lines 1 and 1' | ||
end | ||
end | ||
|
||
context 'when expecting exactly one lint on a certain line' do | ||
it 'matches one expected lint' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 1, count: 1 | ||
end.to succeed | ||
end | ||
|
||
it 'fails to match zero lints with a meaningful message' do | ||
run_with('p { margin: .5em; }') | ||
|
||
expect do | ||
should report_lint line: 1, count: 1 | ||
end.to fail_with 'expected that exactly 1 lint would be reported on line 1' | ||
end | ||
|
||
it 'fails to match multiple lints with a meaningful message' do | ||
run_with('p { margin: 0.5em 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 1, count: 1 | ||
end.to fail_with 'expected that exactly 1 lint would be reported on ' \ | ||
'line 1, but lints were reported on lines 1 and 1' | ||
end | ||
|
||
it 'fails to match lints on the wrong line with a meaningful message' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 10, count: 1 | ||
end.to fail_with 'expected that exactly 1 lint would be reported on ' \ | ||
'line 10, but one lint was reported on line 1' | ||
end | ||
end | ||
|
||
context 'when expecting multiple lints on a certain line' do | ||
it 'matches one expected lint' do | ||
run_with('p { margin: 0.5em 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 1, count: 2 | ||
end.to succeed | ||
end | ||
|
||
it 'fails to match zero lints with a meaningful message' do | ||
run_with('p { margin: .5em; }') | ||
|
||
expect do | ||
should report_lint line: 1, count: 2 | ||
end.to fail_with 'expected that exactly 2 lints would be reported on line 1' | ||
end | ||
|
||
it 'fails to match one lint with a meaningful message' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 1, count: 2 | ||
end.to fail_with 'expected that exactly 2 lints would be reported on ' \ | ||
'line 1, but one lint was reported on line 1' | ||
end | ||
|
||
it 'fails to match lints on the wrong line with a meaningful message' do | ||
run_with('p { margin: 0.5em; }') | ||
|
||
expect do | ||
should report_lint line: 10, count: 2 | ||
end.to fail_with 'expected that exactly 2 lints would be reported on ' \ | ||
'line 10, but one lint was reported on line 1' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters