From 14d45756e9ffca6637a2fcf5695882691d39cb6c Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 11 Jun 2021 18:59:10 -0600 Subject: [PATCH] Consolidate default pending reason --- src/spectator/dsl/expectations.cr | 5 +++-- src/spectator/example.cr | 2 +- src/spectator/harness.cr | 2 +- src/spectator/pending_result.cr | 4 +++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/spectator/dsl/expectations.cr b/src/spectator/dsl/expectations.cr index 92aaa1a..290c716 100644 --- a/src/spectator/dsl/expectations.cr +++ b/src/spectator/dsl/expectations.cr @@ -3,6 +3,7 @@ require "../example_pending" require "../expectation" require "../expectation_failed" require "../location" +require "../pending_result" require "../value" module Spectator::DSL @@ -16,13 +17,13 @@ module Spectator::DSL # Mark the current test as pending and immediately abort. # A reason can be specified with *message*. - def pending(message = "No reason given") + def pending(message = PendingResult::DEFAULT_REASON) raise ExamplePending.new(message) end # Mark the current test as skipped and immediately abort. # A reason can be specified with *message*. - def skip(message = "No reason given") + def skip(message = PendingResult::DEFAULT_REASON) raise ExamplePending.new(message) end diff --git a/src/spectator/example.cr b/src/spectator/example.cr index 8cb921e..9c06135 100644 --- a/src/spectator/example.cr +++ b/src/spectator/example.cr @@ -89,7 +89,7 @@ module Spectator if pending? Log.debug { "Skipping example #{self} - marked pending" } @finished = true - return @result = PendingResult.new(tags[:pending] || "No reason given") + return @result = PendingResult.new(tags[:pending] || PendingResult::DEFAULT_REASON) end previous_example = @@current diff --git a/src/spectator/harness.cr b/src/spectator/harness.cr index 0813758..08ccb2e 100644 --- a/src/spectator/harness.cr +++ b/src/spectator/harness.cr @@ -121,7 +121,7 @@ module Spectator when ExpectationFailed FailResult.new(elapsed, error, @expectations) when ExamplePending - PendingResult.new(error.message || "No reason given", elapsed, @expectations) + PendingResult.new(error.message || PendingResult::DEFAULT_REASON, elapsed, @expectations) else ErrorResult.new(elapsed, error, @expectations) end diff --git a/src/spectator/pending_result.cr b/src/spectator/pending_result.cr index 83fc689..0854fdc 100644 --- a/src/spectator/pending_result.cr +++ b/src/spectator/pending_result.cr @@ -5,13 +5,15 @@ module Spectator # A pending result means the example is not ready to run yet. # This can happen when the functionality to be tested is not implemented yet. class PendingResult < Result + DEFAULT_REASON = "No reason given" + # Reason the example was skipped or marked pending. getter reason : String # Creates the result. # *elapsed* is the length of time it took to run the example. # A *reason* for the skip/pending result can be specified. - def initialize(@reason = "No reason given", elapsed = Time::Span::ZERO, expectations = [] of Expectation) + def initialize(@reason = DEFAULT_REASON, elapsed = Time::Span::ZERO, expectations = [] of Expectation) super(elapsed, expectations) end