2018-06-16 11:50:59 +00:00
|
|
|
require "../../../spec_helper"
|
2017-10-30 20:35:11 +00:00
|
|
|
|
2018-06-16 11:50:59 +00:00
|
|
|
module Ameba::Rule::Layout
|
2017-10-30 20:35:11 +00:00
|
|
|
subject = TrailingWhitespace.new
|
|
|
|
|
|
|
|
describe TrailingWhitespace do
|
|
|
|
it "passes if all lines do not have trailing whitespace" do
|
2017-10-31 18:29:30 +00:00
|
|
|
source = Source.new "no-whispace"
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(source).should be_valid
|
2017-10-30 20:35:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is a line with trailing whitespace" do
|
2017-10-31 18:29:30 +00:00
|
|
|
source = Source.new "whitespace at the end "
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(source).should_not be_valid
|
2017-10-30 20:35:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, pos and message" do
|
2017-11-07 20:02:51 +00:00
|
|
|
source = Source.new "a = 1\n b = 2 ", "source.cr"
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(source).should_not be_valid
|
2017-10-30 20:35:11 +00:00
|
|
|
|
2018-06-10 21:15:12 +00:00
|
|
|
issue = source.issues.first
|
|
|
|
issue.rule.should_not be_nil
|
|
|
|
issue.location.to_s.should eq "source.cr:2:7"
|
2018-11-24 17:38:13 +00:00
|
|
|
issue.end_location.should be_nil
|
2018-06-10 21:15:12 +00:00
|
|
|
issue.message.should eq "Trailing whitespace detected"
|
2017-10-30 20:35:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|