DEV: support --fail-fast in bin/turbo_rspec (#8170)

* [WIP] - default turbo spec env to test

* FEATURE: support for --fast-fail in bin/turbo_rspec

* fast-fail -> fail_fast to match rspec

* Moved thread killing outside of fail-fast check

* Removed failure_count incrementation from fast_fail_met
This commit is contained in:
Mark VanLandingham 2019-10-09 09:40:06 -05:00 committed by GitHub
parent 074ce70c28
commit 9b4aba0d39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -1,12 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
ENV['RAILS_ENV'] ||= 'test'
require './lib/turbo_tests'
require 'optparse'
requires = []
formatters = []
verbose = false
fail_fast = nil
OptionParser.new do |opts|
opts.on("-r", "--require PATH", "Require a file.") do |filename|
@ -33,6 +36,12 @@ OptionParser.new do |opts|
opts.on("-v", "--verbose", "More output") do
verbose = true
end
opts.on("--fail-fast=[N]") do |n|
n = Integer(n) rescue nil
fail_fast = (n.nil? || n < 1) ? 1 : n
end
end.parse!(ARGV)
requires.each { |f| require(f) }
@ -54,7 +63,8 @@ success =
TurboTests::Runner.run(
formatters: formatters,
files: ARGV.empty? ? ["spec"] : ARGV,
verbose: verbose
verbose: verbose,
fail_fast: fail_fast
)
if success

View File

@ -7,6 +7,7 @@ module TurboTests
formatters = opts[:formatters]
start_time = opts.fetch(:start_time) { Time.now }
verbose = opts.fetch(:verbose, false)
fail_fast = opts.fetch(:fail_fast, nil)
if verbose
STDERR.puts "VERBOSE"
@ -17,7 +18,8 @@ module TurboTests
new(
reporter: reporter,
files: files,
verbose: verbose
verbose: verbose,
fail_fast: fail_fast
).run
end
@ -25,6 +27,8 @@ module TurboTests
@reporter = opts[:reporter]
@files = opts[:files]
@verbose = opts[:verbose]
@fail_fast = opts[:fail_fast]
@failure_count = 0
@messages = Queue.new
@threads = []
@ -215,6 +219,11 @@ module TurboTests
when 'example_failed'
example = FakeExample.from_obj(message[:example])
@reporter.example_failed(example)
@failure_count += 1
if fail_fast_met
@threads.each(&:kill)
break
end
when 'seed'
when 'close'
when 'exit'
@ -231,5 +240,9 @@ module TurboTests
rescue Interrupt
end
end
def fail_fast_met
!@fail_fast.nil? && @fail_fast >= @failure_count
end
end
end