From c27f72c83ea3c2aaea757990e87aaa39f152807c Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 7 Oct 2018 16:13:17 -0600 Subject: [PATCH] Add enum for example status --- src/spectator/example_status.cr | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/spectator/example_status.cr diff --git a/src/spectator/example_status.cr b/src/spectator/example_status.cr new file mode 100644 index 0000000..93a2c09 --- /dev/null +++ b/src/spectator/example_status.cr @@ -0,0 +1,59 @@ +module Spectator + # Various outcomes that an example can be in. + enum ExampleStatus + # The example was intentionally not run. + # This is different than `Pending`. + # This value means the example was not pending + # and was not run due to filtering or other means. + Skipped, + + # The example finished successfully. + Successful, + + # The example ran, but failed. + Failed, + + # An error occurred while executing the example. + Errored, + + # The example is marked as pending and was not run. + Pending, + + # The example finished successfully, + # but something may be wrong with it. + Warning + + # Indicates whether an example was skipped. + def skipped? + self == Skipped + end + + # Indicates that an example was run and it was successful. + # NOTE: Examples with warnings count as successful. + def successful? + !failed? && !pending? + end + + # Indicates that an example was run, but it failed. + # Errors count as failures. + def failed? + self == Failed || errored? + end + + # Indicates whether an error was encountered while running the example. + def errored? + self == Errored + end + + # Indicates that an example was marked as pending. + def pending? + self == Pending + end + + # Indicates that the example finished successfully, + # but something may be wrong with it. + def warning? + self == Warning + end + end +end