Skip to content

Commit

Permalink
Cleanup with_presenter helper method implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed Oct 11, 2024
1 parent f89a4b0 commit d9e994f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
8 changes: 2 additions & 6 deletions spec/ameba/presenter/rule_collection_presenter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ 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
rules = Config.load.rules

with_presenter(Presenter::RuleCollectionPresenter, rules) do |presenter, output|
yield rules, output, presenter
end
end
Expand Down
10 changes: 3 additions & 7 deletions spec/ameba/presenter/rule_presenter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ 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
rules = Config.load.rules

rules.each do |rule|
with_presenter(Presenter::RulePresenter, rule) do |presenter, output|
yield rule, output, presenter
end
end
Expand Down
8 changes: 2 additions & 6 deletions spec/ameba/presenter/rule_versions_presenter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ require "../../spec_helper"

module Ameba
private def with_rule_versions_presenter(&)
with_presenter(Presenter::RuleVersionsPresenter) do |presenter, io|
rules = Config.load.rules
presenter.run(rules)

output = io.to_s
output = Formatter::Util.deansify(output).to_s
rules = Config.load.rules

with_presenter(Presenter::RuleVersionsPresenter, rules) do |presenter, output|
yield rules, output, presenter
end
end
Expand Down
9 changes: 7 additions & 2 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,16 @@ module Ameba
end
end

def with_presenter(klass, &)
def with_presenter(klass, *args, deansify = true, **kwargs, &)
io = IO::Memory.new

presenter = klass.new(io)
presenter.run(*args, **kwargs)

output = io.to_s
output = Ameba::Formatter::Util.deansify(output).to_s if deansify

yield presenter, io
yield presenter, output
end

def as_node(source)
Expand Down

0 comments on commit d9e994f

Please sign in to comment.