From 4e0c821b8fd8a32b951bb06b62e9957d1f76f152 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Mon, 10 Dec 2018 14:07:14 -0700 Subject: [PATCH] Add FinishedResult intermediary class --- src/spectator/failed_result.cr | 15 +++------------ src/spectator/finished_result.cr | 21 +++++++++++++++++++++ src/spectator/includes.cr | 1 + src/spectator/successful_result.cr | 17 ++++------------- 4 files changed, 29 insertions(+), 25 deletions(-) create mode 100644 src/spectator/finished_result.cr diff --git a/src/spectator/failed_result.cr b/src/spectator/failed_result.cr index a24f461..a2304dd 100644 --- a/src/spectator/failed_result.cr +++ b/src/spectator/failed_result.cr @@ -2,24 +2,21 @@ require "./result" module Spectator # Outcome that indicates running an example was a failure. - class FailedResult < Result + class FailedResult < FinishedResult # Error that occurred while running the example. getter error : Exception # The expectations that were run in the example. getter expectations : Expectations::ExampleExpectations - # Length of time it took to run the example. - getter elapsed : Time::Span - # Creates a failed result. # The `example` should refer to the example that was run # and that this result is for. # The `elapsed` argument is the length of time it took to run the example. # The `expectations` references the expectations that were checked in the example. # The `error` is the exception that was raised to cause the failure. - def initialize(example, @elapsed, @expectations, @error) - super(example) + def initialize(example, elapsed, @expectations, @error) + super(example, elapsed) end # Indicates that an example was run and it was successful. @@ -41,11 +38,5 @@ module Spectator def errored? false end - - # Indicates that an example was marked as pending. - # This will always be false for this type of result. - def pending? - false - end end end diff --git a/src/spectator/finished_result.cr b/src/spectator/finished_result.cr new file mode 100644 index 0000000..4fdabd6 --- /dev/null +++ b/src/spectator/finished_result.cr @@ -0,0 +1,21 @@ +module Spectator + # Abstract class for all results by examples + abstract class FinishedResult < Result + # Length of time it took to run the example. + getter elapsed : Time::Span + + # Creates a successful result. + # The `example` should refer to the example that was run + # and that this result is for. + # The `elapsed` argument is the length of time it took to run the example. + def initialize(example, @elapsed) + super(example) + end + + # Indicates that an example was marked as pending. + # This will always be false for this type of result. + def pending? + false + end + end +end diff --git a/src/spectator/includes.cr b/src/spectator/includes.cr index f22e091..4d893c2 100644 --- a/src/spectator/includes.cr +++ b/src/spectator/includes.cr @@ -29,6 +29,7 @@ require "./test_results" require "./runner" require "./result" +require "./finished_result" require "./successful_result" require "./pending_result" require "./failed_result" diff --git a/src/spectator/successful_result.cr b/src/spectator/successful_result.cr index dadecc2..b665767 100644 --- a/src/spectator/successful_result.cr +++ b/src/spectator/successful_result.cr @@ -1,21 +1,18 @@ -require "./result" +require "./finished_result" module Spectator # Outcome that indicates running an example was successful. - class SuccessfulResult < Result + class SuccessfulResult < FinishedResult # The expectations that were run in the example. getter expectations : Expectations::ExampleExpectations - # Length of time it took to run the example. - getter elapsed : Time::Span - # Creates a successful result. # The `example` should refer to the example that was run # and that this result is for. # The `elapsed` argument is the length of time it took to run the example. # The `expectations` references the expectations that were checked in the example. - def initialize(example, @elapsed, @expectations) - super(example) + def initialize(example, elapsed, @expectations) + super(example, elapsed) end # Indicates that an example was run and it was successful. @@ -37,11 +34,5 @@ module Spectator def errored? false end - - # Indicates that an example was marked as pending. - # This will always be false for this type of result. - def pending? - false - end end end