shard-ameba/spec/ameba/formatter/flycheck_formatter_spec.cr

49 lines
1.3 KiB
Crystal
Raw Normal View History

2017-12-08 14:57:40 +00:00
require "../../spec_helper"
private def flycheck
output = IO::Memory.new
Ameba::Formatter::FlycheckFormatter.new output
end
module Ameba::Formatter
describe FlycheckFormatter do
context "problems not found" do
it "reports nothing" do
subject = flycheck
subject.source_finished Source.new ""
subject.output.to_s.empty?.should be_true
end
end
context "when problems found" do
2018-06-10 21:15:12 +00:00
it "reports an issue" do
2017-12-08 14:57:40 +00:00
s = Source.new "a = 1", "source.cr"
2018-06-10 21:15:12 +00:00
s.add_issue DummyRule.new, {1, 2}, "message"
2017-12-08 14:57:40 +00:00
subject = flycheck
subject.source_finished s
2018-01-31 11:30:59 +00:00
subject.output.to_s.should eq(
"source.cr:1:2: C: [#{DummyRule.rule_name}] message\n"
2018-01-31 11:30:59 +00:00
)
2017-12-08 14:57:40 +00:00
end
it "properly reports multi-line message" do
s = Source.new "a = 1", "source.cr"
2018-06-10 21:15:12 +00:00
s.add_issue DummyRule.new, {1, 2}, "multi\nline"
2017-12-08 14:57:40 +00:00
subject = flycheck
subject.source_finished s
2018-01-31 11:30:59 +00:00
subject.output.to_s.should eq(
"source.cr:1:2: C: [#{DummyRule.rule_name}] multi line\n"
2018-01-31 11:30:59 +00:00
)
2017-12-08 14:57:40 +00:00
end
it "reports nothing if location was not set" do
s = Source.new "a = 1", "source.cr"
2018-06-10 21:15:12 +00:00
s.add_issue DummyRule.new, Crystal::Nop.new, "message"
2017-12-08 14:57:40 +00:00
subject = flycheck
subject.source_finished s
subject.output.to_s.should eq ""
end
end
end
end