Consolidate default pending reason

This commit is contained in:
Michael Miller 2021-06-11 18:59:10 -06:00
parent 4f2df78c34
commit 14d45756e9
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
4 changed files with 8 additions and 5 deletions

View file

@ -3,6 +3,7 @@ require "../example_pending"
require "../expectation" require "../expectation"
require "../expectation_failed" require "../expectation_failed"
require "../location" require "../location"
require "../pending_result"
require "../value" require "../value"
module Spectator::DSL module Spectator::DSL
@ -16,13 +17,13 @@ module Spectator::DSL
# Mark the current test as pending and immediately abort. # Mark the current test as pending and immediately abort.
# A reason can be specified with *message*. # A reason can be specified with *message*.
def pending(message = "No reason given") def pending(message = PendingResult::DEFAULT_REASON)
raise ExamplePending.new(message) raise ExamplePending.new(message)
end end
# Mark the current test as skipped and immediately abort. # Mark the current test as skipped and immediately abort.
# A reason can be specified with *message*. # A reason can be specified with *message*.
def skip(message = "No reason given") def skip(message = PendingResult::DEFAULT_REASON)
raise ExamplePending.new(message) raise ExamplePending.new(message)
end end

View file

@ -89,7 +89,7 @@ module Spectator
if pending? if pending?
Log.debug { "Skipping example #{self} - marked pending" } Log.debug { "Skipping example #{self} - marked pending" }
@finished = true @finished = true
return @result = PendingResult.new(tags[:pending] || "No reason given") return @result = PendingResult.new(tags[:pending] || PendingResult::DEFAULT_REASON)
end end
previous_example = @@current previous_example = @@current

View file

@ -121,7 +121,7 @@ module Spectator
when ExpectationFailed when ExpectationFailed
FailResult.new(elapsed, error, @expectations) FailResult.new(elapsed, error, @expectations)
when ExamplePending when ExamplePending
PendingResult.new(error.message || "No reason given", elapsed, @expectations) PendingResult.new(error.message || PendingResult::DEFAULT_REASON, elapsed, @expectations)
else else
ErrorResult.new(elapsed, error, @expectations) ErrorResult.new(elapsed, error, @expectations)
end end

View file

@ -5,13 +5,15 @@ module Spectator
# A pending result means the example is not ready to run yet. # 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. # This can happen when the functionality to be tested is not implemented yet.
class PendingResult < Result class PendingResult < Result
DEFAULT_REASON = "No reason given"
# Reason the example was skipped or marked pending. # Reason the example was skipped or marked pending.
getter reason : String getter reason : String
# Creates the result. # Creates the result.
# *elapsed* is the length of time it took to run the example. # *elapsed* is the length of time it took to run the example.
# A *reason* for the skip/pending result can be specified. # 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) super(elapsed, expectations)
end end