Add ability to mark example skipped/pending mid-test

This commit is contained in:
Michael Miller 2021-06-09 21:57:17 -06:00
parent ab6487cbfa
commit 8d73434e0b
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436
3 changed files with 22 additions and 0 deletions

View file

@ -1,4 +1,5 @@
require "../block"
require "../example_pending"
require "../expectation"
require "../expectation_failed"
require "../location"
@ -13,6 +14,18 @@ module Spectator::DSL
raise ExpectationFailed.new(Location.new(_file, _line), message)
end
# Mark the current test as pending and immediately abort.
# A reason can be specified with *message*.
def pending(message = "No reason given")
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")
raise ExamplePending.new(message)
end
# Starts an expectation.
# This should be followed up with `Assertion::Target#to` or `Assertion::Target#to_not`.
# The value passed in will be checked to see if it satisfies the conditions of the specified matcher.

View file

@ -0,0 +1,6 @@
module Spectator
# Exception that indicates an example is pending and should be skipped.
# When raised within a test, the test should abort.
class ExamplePending < Exception
end
end

View file

@ -1,4 +1,5 @@
require "./error_result"
require "./example_pending"
require "./expectation"
require "./mocks"
require "./pass_result"
@ -119,6 +120,8 @@ module Spectator
PassResult.new(elapsed, @expectations)
when ExpectationFailed
FailResult.new(elapsed, error, @expectations)
when ExamplePending
PendingResult.new(elapsed, @expectations)
else
ErrorResult.new(elapsed, error, @expectations)
end