Add "fail-blank" config option

This commit is contained in:
Michael Miller 2019-03-22 13:21:37 -06:00
parent d22b628526
commit 31d58fea25
3 changed files with 22 additions and 0 deletions

View File

@ -15,6 +15,7 @@ module Spectator
OptionParser.parse(@args) do |parser|
parser.on("-v", "--verbose", "Verbose output using document formatter") { builder.formatter = Formatting::DocumentFormatter.new }
parser.on("-f", "--fail-fast", "Stop testing on first failure") { builder.fail_fast }
parser.on("-b", "--fail-blank", "Fail if there are no examples") { builder.fail_blank }
parser.on("-h", "--help", "Show this help") { puts parser; exit }
parser.on("-e", "--example STRING", "Run examples whose full nested names include STRING") { |pattern| raise NotImplementedError.new("-e") }
parser.on("-l", "--line LINE", "Run examples whose line matches LINE") { |line| raise NotImplementedError.new("-l") }

View File

@ -7,10 +7,14 @@ module Spectator
# Indicates whether the test should abort on first failure.
getter? fail_fast : Bool
# Indicates whether the test should fail if there are no examples.
getter? fail_blank : Bool
# Creates a new configuration.
def initialize(builder)
@formatter = builder.formatter
@fail_fast = builder.fail_fast?
@fail_blank = builder.fail_blank?
end
end
end

View File

@ -10,6 +10,7 @@ module Spectator
@formatter : Formatting::Formatter? = nil
@fail_fast = false
@fail_blank = false
# Sets the formatter to use for reporting test progress and results.
def formatter=(formatter : Formatting::Formatter)
@ -44,6 +45,22 @@ module Spectator
@fail_fast
end
# Enables fail-blank mode (fail on no tests).
def fail_blank
self.fail_blank = true
end
# Sets teh fail-blank mode.
def fail_blank=(flag)
@fail_blank = flag
end
# Indicates whether fail-fast mode is enabled.
# That is, it is a failure if there are no tests.
def fail_blank?
@fail_blank
end
# Creates a configuration.
def build : Config
Config.new(self)