2017-10-30 20:00:01 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
|
|
|
module Ameba::Rules
|
|
|
|
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-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
|
|
|
|
|
|
|
error = source.errors.first
|
|
|
|
error.rule.should eq subject
|
|
|
|
error.pos.should eq 1
|
2017-11-06 06:54:59 +00:00
|
|
|
error.message.should eq "Line too long (81 symbols)"
|
2017-10-30 20:00:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|