diff --git a/spec/ameba/presenter/rule_collection_presenter_spec.cr b/spec/ameba/presenter/rule_collection_presenter_spec.cr new file mode 100644 index 00000000..cba4129b --- /dev/null +++ b/spec/ameba/presenter/rule_collection_presenter_spec.cr @@ -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 diff --git a/spec/ameba/presenter/rule_presenter_spec.cr b/spec/ameba/presenter/rule_presenter_spec.cr new file mode 100644 index 00000000..5f76007a --- /dev/null +++ b/spec/ameba/presenter/rule_presenter_spec.cr @@ -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 diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 365febd1..34621852 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -282,6 +282,13 @@ module Ameba end end +def with_presenter(klass, &) + io = IO::Memory.new + presenter = klass.new(io) + + yield presenter, io +end + def as_node(source) Crystal::Parser.new(source).parse end