From b8e125e38f9436106cdbcd2e2ddedc8380b0e2b5 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 31 Aug 2019 13:12:17 -0600 Subject: [PATCH] Add test wrapper --- src/spectator/test_wrapper.cr | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/spectator/test_wrapper.cr diff --git a/src/spectator/test_wrapper.cr b/src/spectator/test_wrapper.cr new file mode 100644 index 0000000..761d4f4 --- /dev/null +++ b/src/spectator/test_wrapper.cr @@ -0,0 +1,30 @@ +require "../spectator_test" +require "./source" + +module Spectator + # Stores information about a end-user test. + # Used to instantiate tests and run them. + struct TestWrapper + # Location of the test in source code. + getter source : Source + + # Description the user provided for the test. + getter description : String + + # Creates a wrapper for the test. + # The *builder* creates an instance of the test. + # The *runner* takes the test created by *builder* and runs it. + def initialize(@description, @source, @builder : -> SpectatorTest, @runner : SpectatorTest ->) + end + + # Instantiates and runs the test. + # This method yields twice - before and after the test. + # The test instance is yielded. + def run : Nil + test = @builder.call + yield test + @runner.call(test) + yield test + end + end +end