2018-06-16 11:50:59 +00:00
|
|
|
require "../../../spec_helper"
|
2017-10-30 20:00:01 +00:00
|
|
|
|
2018-06-16 11:50:59 +00:00
|
|
|
module Ameba::Rule::Layout
|
2017-10-30 20:00:01 +00:00
|
|
|
subject = LineLength.new
|
2018-07-04 12:20:35 +00:00
|
|
|
long_line = "*" * (subject.max_length + 1)
|
2017-10-30 20:00:01 +00:00
|
|
|
|
|
|
|
describe LineLength do
|
2018-07-04 12:20:35 +00:00
|
|
|
it "passes if all lines are shorter than MaxLength 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
|
|
|
|
|
2018-07-04 12:20:35 +00:00
|
|
|
it "passes if line consists of MaxLength symbols" do
|
|
|
|
source = Source.new "*" * subject.max_length
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(source).should be_valid
|
2017-11-01 10:23:12 +00:00
|
|
|
end
|
|
|
|
|
2018-07-04 12:20:35 +00:00
|
|
|
it "fails if there is at least one line longer than MaxLength 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
|
2018-07-04 12:20:35 +00:00
|
|
|
issue.location.to_s.should eq "source.cr:1:#{subject.max_length + 1}"
|
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 "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
|