mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Introduce non-expectation error ExampleFailed
Used by fail method. Still todo: Output from failed example is missing because there are no expectations.
This commit is contained in:
parent
ccedcdac42
commit
aa12cdf17c
5 changed files with 21 additions and 5 deletions
|
@ -6,7 +6,7 @@ macro it_fails(description = nil, &block)
|
|||
it {{description}} do
|
||||
expect do
|
||||
{{block.body}}
|
||||
end.to raise_error(Spectator::ExpectationFailed)
|
||||
end.to raise_error(Spectator::ExampleFailed)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module Spectator::DSL
|
|||
# Immediately fail the current test.
|
||||
# A reason can be specified with *message*.
|
||||
def fail(message = "Example failed", *, _file = __FILE__, _line = __LINE__)
|
||||
raise ExpectationFailed.new(Location.new(_file, _line), message)
|
||||
raise ExampleFailed.new(Location.new(_file, _line), message)
|
||||
end
|
||||
|
||||
# Mark the current test as pending and immediately abort.
|
||||
|
|
14
src/spectator/example_failed.cr
Normal file
14
src/spectator/example_failed.cr
Normal file
|
@ -0,0 +1,14 @@
|
|||
require "./location"
|
||||
|
||||
module Spectator
|
||||
# Exception that indicates an example failed.
|
||||
# When raised within a test, the test should abort.
|
||||
class ExampleFailed < Exception
|
||||
getter! location : Location
|
||||
|
||||
# Creates the exception.
|
||||
def initialize(@location : Location?, message : String? = nil, cause : Exception? = nil)
|
||||
super(message, cause)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,15 +1,16 @@
|
|||
require "./example_failed"
|
||||
require "./expectation"
|
||||
|
||||
module Spectator
|
||||
# Exception that indicates an expectation from a test failed.
|
||||
# When raised within a test, the test should abort.
|
||||
class ExpectationFailed < Exception
|
||||
class ExpectationFailed < ExampleFailed
|
||||
# Expectation that failed.
|
||||
getter expectation : Expectation
|
||||
|
||||
# Creates the exception.
|
||||
def initialize(@expectation : Expectation, message : String? = nil, cause : Exception? = nil)
|
||||
super(message, cause)
|
||||
super(expectation.location?, message, cause)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require "./error_result"
|
||||
require "./example_failed"
|
||||
require "./example_pending"
|
||||
require "./expectation"
|
||||
require "./mocks"
|
||||
|
@ -118,7 +119,7 @@ module Spectator
|
|||
case error
|
||||
when nil
|
||||
PassResult.new(elapsed, @expectations)
|
||||
when ExpectationFailed
|
||||
when ExampleFailed
|
||||
FailResult.new(elapsed, error, @expectations)
|
||||
when ExamplePending
|
||||
PendingResult.new(error.message || PendingResult::DEFAULT_REASON, elapsed, @expectations)
|
||||
|
|
Loading…
Reference in a new issue