-
-
Save sam0x17/bad71979d2d9f401abea72c72d764ffd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Spec::Methods | |
def it(description = "assert", file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block) | |
description = description.to_s | |
Spec::RootContext.check_nesting_spec(file, line) do | |
return unless Spec.split_filter_matches | |
return unless Spec.matches?(description, file, line, end_line) | |
Spec.formatters.each(&.before_example(description)) | |
start = Time.monotonic | |
begin | |
Spec.run_before_each_hooks | |
Spec.run_around_each do | |
block.call | |
end | |
Spec::RootContext.report(:success, description, file, line, Time.monotonic - start) | |
rescue ex : Spec::AssertionFailed | |
Spec::RootContext.report(:fail, description, file, line, Time.monotonic - start, ex) | |
Spec.abort! if Spec.fail_fast? | |
rescue ex | |
Spec::RootContext.report(:error, description, file, line, Time.monotonic - start, ex) | |
Spec.abort! if Spec.fail_fast? | |
ensure | |
Spec.run_after_each_hooks | |
# We do this to give a chance for signals (like CTRL+C) to be handled, | |
# which currently are only handled when there's a fiber switch | |
# (IO stuff, sleep, etc.). Without it the user might wait more than needed | |
# after pressing CTRL+C to quit the tests. | |
Fiber.yield | |
end | |
end | |
end | |
end | |
module Spec | |
def self.run_around_each(&block) | |
@@around_each.nil? ? block.call : @@around_each.not_nil!.call(block) | |
end | |
def self.around_each(&block : Proc(Proc(Nil), Nil)) | |
@@around_each = block | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment