Avoid duplicated sections in a generated TODO file

This commit is contained in:
Vitalii Elenhaupt 2019-10-27 22:15:04 +02:00
parent 19d9223ec1
commit 111596541b
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
3 changed files with 38 additions and 0 deletions

View file

@ -73,5 +73,15 @@ module Ameba::Rule
DummyRule.parsed_doc.should eq "Dummy Rule which does nothing."
end
end
describe "#==" do
it "returns true if rule has the same name" do
DummyRule.new.should eq(DummyRule.new)
end
it "returns false if rule has a different name" do
DummyRule.new.should_not eq(NoProperties.new)
end
end
end
end

View file

@ -76,6 +76,30 @@ module Ameba
create_todo.should contain "Excluded:\n - source.cr"
end
context "with multiple issues" do
formatter = Formatter::TODOFormatter.new IO::Memory.new
s1 = Source.new "a = 1", "source1.cr"
s2 = Source.new "a = 1", "source2.cr"
s1.add_issue DummyRule.new, {1, 2}, "message1"
s1.add_issue DummyRule.new, {2, 2}, "message1"
s2.add_issue DummyRule.new, {2, 2}, "message2"
file = formatter.finished([s1, s2])
content = File.read(file.not_nil!.path)
content.should contain <<-CONTENT
# Problems found: 3
# Run `ameba --only Ameba/DummyRule` for details
Ameba/DummyRule:
Description: Dummy rule that does nothing.
Enabled: true
Severity: Convention
Excluded:
- source1.cr
- source2.cr
CONTENT
end
context "when invalid syntax" do
it "does generate todo file" do
formatter = Formatter::TODOFormatter.new IO::Memory.new

View file

@ -105,6 +105,10 @@ module Ameba::Rule
SPECIAL.includes? name
end
def ==(other)
self.name == other.name
end
macro issue_for(*args)
source.add_issue self, {{*args}}
end