2017-10-30 20:00:01 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
2017-11-07 21:50:25 +00:00
|
|
|
module Ameba::Rule
|
2017-10-30 20:00:01 +00:00
|
|
|
subject = LineLength.new
|
2017-11-06 06:54:59 +00:00
|
|
|
long_line = "*" * 81
|
2017-10-30 20:00:01 +00:00
|
|
|
|
|
|
|
describe LineLength do
|
|
|
|
it "passes if all lines are shorter than 80 symbols" do
|
2017-10-31 18:29:30 +00:00
|
|
|
source = Source.new "short line"
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(source).should be_valid
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
|
|
|
|
2017-11-01 10:23:12 +00:00
|
|
|
it "passes if line consists of 79 symbols" do
|
2017-11-06 06:54:59 +00:00
|
|
|
source = Source.new "*" * 80
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(source).should be_valid
|
2017-11-01 10:23:12 +00:00
|
|
|
end
|
|
|
|
|
2017-10-30 20:00:01 +00:00
|
|
|
it "fails if there is at least one line longer than 79 symbols" do
|
2017-10-31 18:29:30 +00:00
|
|
|
source = Source.new long_line
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(source).should_not be_valid
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, pos and message" do
|
2017-11-07 20:02:51 +00:00
|
|
|
source = Source.new long_line, "source.cr"
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(source).should_not be_valid
|
2017-10-30 20:00:01 +00:00
|
|
|
|
2018-06-10 21:15:12 +00:00
|
|
|
issue = source.issues.first
|
|
|
|
issue.rule.should eq subject
|
|
|
|
issue.location.to_s.should eq "source.cr:1:81"
|
|
|
|
issue.message.should eq "Line too long"
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
2017-11-22 06:44:29 +00:00
|
|
|
|
|
|
|
context "properties" do
|
|
|
|
it "allows to configure max length of the line" do
|
|
|
|
source = Source.new long_line
|
|
|
|
rule = LineLength.new
|
|
|
|
rule.max_length = long_line.size
|
|
|
|
rule.catch(source).should be_valid
|
|
|
|
end
|
|
|
|
end
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
|
|
|
end
|