Add fail-fast to config

This commit is contained in:
Michael Miller 2019-03-21 23:40:00 -06:00
parent fe81586527
commit 9e63c20df2
4 changed files with 24 additions and 1 deletions

View file

@ -2,7 +2,9 @@ require "./spec_helper"
# Creates a `Config` for Spectator that is suited for testing it.
def spectator_test_config(formatter : Spectator::Formatting::Formatter? = nil)
Spectator::Config.new(formatter || Spectator::Formatting::SilentFormatter.new)
builder = Spectator::ConfigBuilder.new
builder.formatter = formatter || Spectator::Formatting::SilentFormatter.new
builder.build
end
def new_test_suite

View file

@ -14,6 +14,7 @@ module Spectator
def apply_to(builder : ConfigBuilder) : Nil
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 }
end
end
end

View file

@ -4,9 +4,13 @@ module Spectator
# Used to report test progress and results.
getter formatter : Formatting::Formatter
# Indicates whether the test should abort on first failure.
getter? fail_fast : Bool
# Creates a new configuration.
def initialize(builder)
@formatter = builder.formatter
@fail_fast = builder.fail_fast?
end
end
end

View file

@ -9,6 +9,7 @@ module Spectator
end
@formatter : Formatting::Formatter? = nil
@fail_fast = false
# Sets the formatter to use for reporting test progress and results.
def formatter=(formatter : Formatting::Formatter)
@ -28,6 +29,21 @@ module Spectator
Formatting::DotsFormatter.new
end
# Enables fail-fast mode.
def fail_fast
self.fail_fast = true
end
# Sets the fail-fast flag.
def fail_fast=(flag)
@fail_fast = flag
end
# Indicates whether fail-fast mode is enabled.
def fail_fast?
@fail_fast
end
# Creates a configuration.
def build : Config
Config.new(self)