diff --git a/src/spectator/example.cr b/src/spectator/example.cr index 3cf7051..cc955d1 100644 --- a/src/spectator/example.cr +++ b/src/spectator/example.cr @@ -6,6 +6,9 @@ module Spectator # Concrete types must implement the `#run_impl` method. abstract class Example < ExampleComponent @finished = false + @description : String? = nil + + protected setter description # Indicates whether the example has already been run. def finished? : Bool @@ -23,11 +26,13 @@ module Spectator @test_wrapper.source end - def description : String | Symbol? - @test_wrapper.description + def description : String | Symbol + @description || @test_wrapper.description end def symbolic? : Bool + return false unless @test_wrapper.description? + description = @test_wrapper.description description.starts_with?('#') || description.starts_with?('.') end diff --git a/src/spectator/expectations/expectation.cr b/src/spectator/expectations/expectation.cr index 300f134..72d3dbd 100644 --- a/src/spectator/expectations/expectation.cr +++ b/src/spectator/expectations/expectation.cr @@ -44,6 +44,10 @@ module Spectator::Expectations values?.not_nil! end + def description + @match_data.description + end + # Creates the JSON representation of the expectation. def to_json(json : ::JSON::Builder) json.object do diff --git a/src/spectator/harness.cr b/src/spectator/harness.cr index 33ed2f0..5268edc 100644 --- a/src/spectator/harness.cr +++ b/src/spectator/harness.cr @@ -46,6 +46,7 @@ module Spectator # Reports the outcome of an expectation. # An exception will be raised when a failing result is given. def report_expectation(expectation : Expectations::Expectation) : Nil + @example.description = expectation.description unless @example.test_wrapper.description? @reporter.report(expectation) end