Syntax rule running priorities

This commit is contained in:
Vitalii Elenhaupt 2018-01-25 11:50:11 +02:00 committed by V. Elenhaupt
parent c9db63bf34
commit 4c85ad7c75
8 changed files with 64 additions and 12 deletions

View file

@ -7,6 +7,19 @@ module Ameba::Rule
end
describe Base do
context ".rules" do
it "returns a list of all rules" do
rules = Rule.rules
rules.should_not be_nil
rules.should contain DummyRule
rules.should contain NoProperties
end
it "should not include syntax rule" do
Rule.rules.should_not contain Rule::Syntax
end
end
context "properties" do
subject = DummyRule.new

View file

@ -50,6 +50,21 @@ module Ameba
it "excludes source from this rule" do
create_todo.should contain "Excluded:\n - source.cr"
end
context "when invalid syntax" do
it "does not exclude Syntax rule" do
file = IO::Memory.new
formatter = Formatter::TODOFormatter.new IO::Memory.new, file
s = Source.new "def invalid_syntax"
s.error Rule::Syntax.new, s.location(1, 2), "message"
formatter.finished [s]
content = file.to_s
content.should_not contain "Syntax"
end
end
end
end
end

View file

@ -9,7 +9,6 @@ module Ameba::Rule
def hello
puts "totally valid"
rescue e: Exception
#
end
)
subject.catch(s).should be_valid
@ -20,7 +19,6 @@ module Ameba::Rule
def hello
puts "invalid"
rescue Exception => e
#
end
)
subject.catch(s).should_not be_valid

View file

@ -51,6 +51,30 @@ module Ameba
Runner.new(rules, [source], formatter).run.success?.should be_true
end
context "invalid syntax" do
it "reports a syntax error" do
rules = [Rule::Syntax.new] of Rule::Base
source = Source.new "def bad_syntax"
Runner.new(rules, [source], formatter).run
source.should_not be_valid
source.errors.first.rule.name.should eq "Syntax"
end
it "does not run other rules" do
rules = [Rule::Syntax.new, Rule::ConstantNames.new] of Rule::Base
source = Source.new %q(
MyBadConstant = 1
when my_bad_syntax
)
Runner.new(rules, [source], formatter).run
source.should_not be_valid
source.errors.size.should eq 1
end
end
end
describe "#success?" do