Skip to content

Commit

Permalink
Include test details in ShoesSpec test output
Browse files Browse the repository at this point in the history
  • Loading branch information
noahgibbs committed Jul 7, 2024
1 parent 98f40d6 commit 2868651
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/space_shoes/guest/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def e.start; end
JS.global[:document][:shoes_spec_passed] = result
elt = JS.global[:document].createElement("div")
elt[:className] = "minitest_result"
elt[:innerHTML] = "<p>#{result ? "passed" : "failed"}</p>"
test_details = ShoesSpec.test_class.results # Should only be one test class
elt[:innerHTML] = "<p>#{result ? "passed" : "failed"}</p><p>#{test_details}</p>"
JS.global[:document][:body].appendChild(elt)

Shoes.APPS.each(&:destroy) # Need more recent version of Lacci with multi-app
Expand Down
25 changes: 25 additions & 0 deletions lib/space_shoes/guest/shoes-spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

module SpaceShoes
class ShoesSpec
class << self
attr_accessor :test_class
end

def self.run_shoes_spec_test_code(code, class_name: nil, test_name: nil)
if @shoes_spec_init
raise Shoes::Errors::MultipleShoesSpecRunsError, "SpaceShoes can only run a single Shoes spec per process!"
Expand All @@ -14,9 +18,30 @@ def self.run_shoes_spec_test_code(code, class_name: nil, test_name: nil)
test_name ||= ENV["SHOES_MINITEST_METHOD_NAME"] || "test_shoes_spec"

test_class = Class.new(SpaceShoes::ShoesSpecTest)
ShoesSpec.test_class = test_class
Object.const_set(Scarpe::Components::StringHelpers.camelize(class_name), test_class)
test_name = "test_" + test_name unless test_name.start_with?("test_")
test_class.class_eval(<<~CLASS_EVAL)
attr_reader :reporter
attr_reader :summary
def self.run(reporter, options)
@reporter = reporter # When run, save a copy of reporter
@summary = reporter.reporters.grep(Minitest::SummaryReporter).first
super
end
def self.results
{
cases: @summary.count,
assertions: @summary.assertions, # number of assertions
failures: @summary.failures, # number of failures
errors: @summary.errors, # number of errors
skips: @summary.skips, # number of skips
results: @summary.results, # actual failure exception objects
}
end
def #{test_name}
#{code}
end
Expand Down

0 comments on commit 2868651

Please sign in to comment.