2017-10-30 20:00:01 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
|
|
|
module Ameba::Rules
|
|
|
|
subject = LineLength.new
|
|
|
|
long_line = "*" * 80
|
|
|
|
|
|
|
|
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
|
|
|
|
source = Source.new "*" * 79
|
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
|
|
|
|
error.message.should eq "Line too long (80 symbols)"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|