shard-ameba/spec/ameba/rule/trailing_blank_lines_spec.cr
2017-11-08 00:02:32 +02:00

37 lines
1 KiB
Crystal

require "../../spec_helper"
module Ameba::Rule
subject = TrailingBlankLines.new
describe TrailingBlankLines do
it "passes if there is no blank lines at the end" do
source = Source.new "no-blankline"
subject.catch(source).should be_valid
end
it "fails if there is a blank line at the end of a source" do
source = Source.new "a = 1\n \n "
subject.catch(source).should_not be_valid
end
it "passes if source is empty" do
source = Source.new ""
subject.catch(source).should be_valid
end
it "passes if last line is not blank" do
source = Source.new "\n\n\n puts 22"
subject.catch(source).should be_valid
end
it "reports rule, pos and message" do
source = Source.new "a = 1\n\n ", "source.cr"
subject.catch(source).should_not be_valid
error = source.errors.first
error.rule.should_not be_nil
error.location.to_s.should eq "source.cr:3:1"
error.message.should eq "Blank lines detected at the end of the file"
end
end
end