Flag to disable running tests

This is needed for testing Spectator.
This commit is contained in:
Michael Miller 2018-10-15 00:32:29 -06:00
parent cd86687dfb
commit c77a85c97a
2 changed files with 29 additions and 16 deletions

View file

@ -1,2 +1,5 @@
require "spec" require "spec"
require "../src/spectator" require "../src/spectator"
# Prevent Spectator from trying to run tests.
Spectator.autorun = false

View file

@ -45,7 +45,14 @@ module Spectator
end end
end end
# Flag indicating whether Spectator should automatically run tests.
# This should be left alone (set to true) in typical usage.
# There are times when Spectator shouldn't run tests.
# One of those is testing Spectator.
class_property? autorun = true
# All tests are ran just before the executable exits. # All tests are ran just before the executable exits.
# Tests will be skipped, however, if `#autorun?` is set to false.
# There are a couple of reasons for this. # There are a couple of reasons for this.
# #
# First is that we want a clean interface for the end-user. # First is that we want a clean interface for the end-user.
@ -62,7 +69,11 @@ module Spectator
# Crystal doesn't display much information about what happened. # Crystal doesn't display much information about what happened.
# That issue is handled by putting a begin/rescue block to show a custom error message. # That issue is handled by putting a begin/rescue block to show a custom error message.
at_exit do at_exit do
begin run if autorun?
end
# Builds the tests and runs the framework.
private def self.run
# Build the root-level example group and run it. # Build the root-level example group and run it.
group = ::Spectator::DSL::Builder.build group = ::Spectator::DSL::Builder.build
Runner.new(group).run Runner.new(group).run
@ -78,5 +89,4 @@ module Spectator
puts ex.backtrace.join("\n") puts ex.backtrace.join("\n")
exit(1) exit(1)
end end
end
end end