2017-10-30 20:35:11 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
|
|
|
module Ameba::Rules
|
|
|
|
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-10-30 20:35:11 +00:00
|
|
|
subject.catch(source).valid?.should be_true
|
|
|
|
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-10-30 20:35:11 +00:00
|
|
|
subject.catch(source).valid?.should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, pos and message" do
|
2017-10-31 18:29:30 +00:00
|
|
|
source = Source.new "a = 1\n b = 2 "
|
2017-10-30 20:35:11 +00:00
|
|
|
subject.catch(source).valid?.should be_false
|
|
|
|
|
|
|
|
error = source.errors.first
|
|
|
|
error.rule.should_not be_nil
|
|
|
|
error.pos.should eq 2
|
|
|
|
error.message.should eq "Trailing whitespace detected"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|