diff --git a/src/spectator/example.cr b/src/spectator/example.cr index d8185ef..d7c2d18 100644 --- a/src/spectator/example.cr +++ b/src/spectator/example.cr @@ -2,7 +2,7 @@ require "./example_component" module Spectator # Base class for all types of examples. - # Concrete types must implement the `#run_impl, `#what`, `#instance`, and `#source` methods. + # Concrete types must implement the `#run_impl` method. abstract class Example < ExampleComponent # Indicates whether the example has already been run. getter? finished = false @@ -11,10 +11,16 @@ module Spectator getter group : ExampleGroup # Retrieves the internal wrapped instance. - abstract def instance + private getter @test_wrapper : TestWrapper # Source where the example originated from. - abstract def source : Source + def source + @test_wrapper.source + end + + def what + @test_wrapper.description + end # Runs the example code. # A result is returned, which represents the outcome of the test. @@ -31,7 +37,7 @@ module Spectator # Creates the base of the example. # The group should be the example group the example belongs to. - def initialize(@group) + def initialize(@group, @test_wrapper) end # Indicates there is only one example to run. diff --git a/src/spectator/example_component.cr b/src/spectator/example_component.cr index 9c9fa95..a6aa9d9 100644 --- a/src/spectator/example_component.cr +++ b/src/spectator/example_component.cr @@ -3,6 +3,7 @@ module Spectator # This is used as the base node type for the composite design pattern. abstract class ExampleComponent # Text that describes the context or test. + # TODO: Rename to description. abstract def what : String # Indicates whether the example (or group) has been completely run. diff --git a/src/spectator/pending_example.cr b/src/spectator/pending_example.cr index f485ec4..30dc99d 100644 --- a/src/spectator/pending_example.cr +++ b/src/spectator/pending_example.cr @@ -3,7 +3,7 @@ require "./example" module Spectator # Common class for all examples marked as pending. # This class will not run example code. - abstract class PendingExample < Example + class PendingExample < Example # Returns a pending result. private def run_impl PendingResult.new(self) diff --git a/src/spectator/runnable_example.cr b/src/spectator/runnable_example.cr index 0809291..7964ff1 100644 --- a/src/spectator/runnable_example.cr +++ b/src/spectator/runnable_example.cr @@ -1,11 +1,9 @@ require "./example" module Spectator - # Common base for all examples that can be run. - # This class includes all the logic for running example hooks, + # Includes all the logic for running example hooks, # the example code, and capturing a result. - # Sub-classes need to implement the `#what` and `#run_instance` methods. - abstract class RunnableExample < Example + class RunnableExample < Example # Runs the example, hooks, and captures the result # and translates to a usable result. def run_impl @@ -14,9 +12,6 @@ module Spectator translate_result(result, expectations) end - # Runs the actual test code. - private abstract def run_instance - # Runs all hooks and the example code. # A captured result is returned. private def capture_result @@ -52,7 +47,7 @@ module Spectator # Capture how long it takes to run the test code. result.elapsed = Time.measure do begin - run_instance # Actually run the example code. + test_wrapper.run {} # Actually run the example code. rescue ex # Catch all errors and handle them later. result.error = ex end