mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Track source location of pending result
This commit is contained in:
parent
7cb1545e83
commit
6c6dff363b
4 changed files with 19 additions and 6 deletions
|
@ -17,14 +17,14 @@ 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 = PendingResult::DEFAULT_REASON)
|
def pending(message = PendingResult::DEFAULT_REASON, *, _file = __FILE__, _line = __LINE__)
|
||||||
raise ExamplePending.new(message)
|
raise ExamplePending.new(Location.new(_file, _line), 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 = PendingResult::DEFAULT_REASON)
|
def skip(message = PendingResult::DEFAULT_REASON, *, _file = __FILE__, _line = __LINE__)
|
||||||
raise ExamplePending.new(message)
|
raise ExamplePending.new(Location.new(_file, _line), message)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Starts an expectation.
|
# Starts an expectation.
|
||||||
|
|
|
@ -2,5 +2,13 @@ module Spectator
|
||||||
# Exception that indicates an example is pending and should be skipped.
|
# Exception that indicates an example is pending and should be skipped.
|
||||||
# When raised within a test, the test should abort.
|
# When raised within a test, the test should abort.
|
||||||
class ExamplePending < Exception
|
class ExamplePending < Exception
|
||||||
|
# Location of where the example was aborted.
|
||||||
|
getter location : Location?
|
||||||
|
|
||||||
|
# Creates the exception.
|
||||||
|
# Specify *location* to where the example was aborted.
|
||||||
|
def initialize(@location : Location? = nil, message : String? = nil, cause : Exception? = nil)
|
||||||
|
super(message, cause)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -123,7 +123,7 @@ module Spectator
|
||||||
when ExampleFailed
|
when ExampleFailed
|
||||||
FailResult.new(elapsed, error, @expectations)
|
FailResult.new(elapsed, error, @expectations)
|
||||||
when ExamplePending
|
when ExamplePending
|
||||||
PendingResult.new(error.message || PendingResult::DEFAULT_REASON, elapsed, @expectations)
|
PendingResult.new(error.message || PendingResult::DEFAULT_REASON, error.location, elapsed, @expectations)
|
||||||
else
|
else
|
||||||
ErrorResult.new(elapsed, error, @expectations)
|
ErrorResult.new(elapsed, error, @expectations)
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,10 +10,15 @@ module Spectator
|
||||||
# Reason the example was skipped or marked pending.
|
# Reason the example was skipped or marked pending.
|
||||||
getter reason : String
|
getter reason : String
|
||||||
|
|
||||||
|
# Location the pending result was triggered from.
|
||||||
|
getter location : Location?
|
||||||
|
|
||||||
# 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 = DEFAULT_REASON, elapsed = Time::Span::ZERO, expectations = [] of Expectation)
|
# If the pending result was triggered inside of an example, then *location* can be set.
|
||||||
|
def initialize(@reason = DEFAULT_REASON, @location = nil,
|
||||||
|
elapsed = Time::Span::ZERO, expectations = [] of Expectation)
|
||||||
super(elapsed, expectations)
|
super(elapsed, expectations)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue