mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add presenter specs
This commit is contained in:
parent
1b57e2cad5
commit
ef16ad6471
3 changed files with 69 additions and 0 deletions
32
spec/ameba/presenter/rule_collection_presenter_spec.cr
Normal file
32
spec/ameba/presenter/rule_collection_presenter_spec.cr
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
require "../../spec_helper"
|
||||||
|
|
||||||
|
module Ameba
|
||||||
|
private def with_rule_collection_presenter(&)
|
||||||
|
with_presenter(Presenter::RuleCollectionPresenter) do |presenter, io|
|
||||||
|
rules = Config.load.rules
|
||||||
|
presenter.run(rules)
|
||||||
|
|
||||||
|
output = io.to_s
|
||||||
|
output = Formatter::Util.deansify(output).to_s
|
||||||
|
|
||||||
|
yield rules, output, presenter
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe Presenter::RuleCollectionPresenter do
|
||||||
|
it "outputs rule collection details" do
|
||||||
|
with_rule_collection_presenter do |rules, output|
|
||||||
|
rules.each do |rule|
|
||||||
|
output.should contain rule.name
|
||||||
|
output.should contain rule.severity.symbol
|
||||||
|
|
||||||
|
if description = rule.description
|
||||||
|
output.should contain description
|
||||||
|
end
|
||||||
|
end
|
||||||
|
output.should contain "Total rules: #{rules.size}"
|
||||||
|
output.should match /\d+ enabled/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
30
spec/ameba/presenter/rule_presenter_spec.cr
Normal file
30
spec/ameba/presenter/rule_presenter_spec.cr
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
require "../../spec_helper"
|
||||||
|
|
||||||
|
module Ameba
|
||||||
|
private def rule_presenter_each_rule(&)
|
||||||
|
with_presenter(Presenter::RulePresenter) do |presenter, io|
|
||||||
|
rules = Config.load.rules
|
||||||
|
rules.each do |rule|
|
||||||
|
presenter.run(rule)
|
||||||
|
|
||||||
|
output = io.to_s
|
||||||
|
output = Formatter::Util.deansify(output).to_s
|
||||||
|
|
||||||
|
yield rule, output, presenter
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe Presenter::RulePresenter do
|
||||||
|
it "outputs rule details" do
|
||||||
|
rule_presenter_each_rule do |rule, output|
|
||||||
|
output.should contain rule.name
|
||||||
|
output.should contain rule.severity.to_s
|
||||||
|
|
||||||
|
if description = rule.description
|
||||||
|
output.should contain description
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -282,6 +282,13 @@ module Ameba
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_presenter(klass, &)
|
||||||
|
io = IO::Memory.new
|
||||||
|
presenter = klass.new(io)
|
||||||
|
|
||||||
|
yield presenter, io
|
||||||
|
end
|
||||||
|
|
||||||
def as_node(source)
|
def as_node(source)
|
||||||
Crystal::Parser.new(source).parse
|
Crystal::Parser.new(source).parse
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue