TODO formatter

This commit is contained in:
Vitalii Elenhaupt 2017-11-30 11:27:52 +02:00 committed by V. Elenhaupt
parent bc552d0730
commit a1854c0aa3
5 changed files with 122 additions and 28 deletions

View file

@ -0,0 +1,44 @@
require "../../spec_helper"
module Ameba
private def create_todo(formatter)
s = Source.new "a = 1"
s.error DummyRule.new, s.location(1, 2), "message"
formatter.finished [s]
end
describe Formatter::TODOFormatter do
file = IO::Memory.new
subject = Formatter::TODOFormatter.new IO::Memory.new, file
context "problems not reported" do
it "does not create todo" do
subject.finished [Source.new ""]
file.to_s.empty?.should be_true
end
end
context "problems reported" do
it "creates a todo with header" do
create_todo subject
file.to_s.should contain "# This configuration file was generated by"
file.to_s.should contain "Ameba version #{VERSION}"
end
it "creates a todo with rule name" do
create_todo subject
file.to_s.should contain "DummyRule"
end
it "creates a todo with problems count" do
create_todo subject
file.to_s.should contain "Problems found: 1"
end
it "creates a valid YAML document" do
create_todo subject
YAML.parse(file.to_s).should_not be_nil
end
end
end
end