Skip to content
Permalink
Browse files

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
  • Loading branch information...
markvanlan committed Oct 9, 2019
1 parent 074ce70 commit 9b4aba0d390c2d1143109be0ca54fb45e22883ee
Showing with 25 additions and 2 deletions.
  1. +11 −1 bin/turbo_rspec
  2. +14 −1 lib/turbo_tests/runner.rb
@@ -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
@@ -7,6 +7,7 @@ def self.run(opts = {})
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,14 +18,17 @@ def self.run(opts = {})
new(
reporter: reporter,
files: files,
verbose: verbose
verbose: verbose,
fail_fast: fail_fast
).run
end

def initialize(opts)
@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 @@ def handle_messages
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 @@ def handle_messages
rescue Interrupt
end
end

def fail_fast_met
!@fail_fast.nil? && @fail_fast >= @failure_count
end
end
end

0 comments on commit 9b4aba0

Please sign in to comment.
You can’t perform that action at this time.