enter will either run all specs or tell you which failed

This commit is contained in:
Sam 2013-05-06 15:16:53 +10:00
parent be1ab8b275
commit b0945599b7
2 changed files with 61 additions and 13 deletions

View File

@ -4,17 +4,36 @@ module Autospec; end
class Autospec::Formatter < RSpec::Core::Formatters::BaseFormatter class Autospec::Formatter < RSpec::Core::Formatters::BaseFormatter
def dump_summary(duration, total, failures, pending) def dump_summary(duration, total, failures, pending)
failed_specs = examples.delete_if{|e| e.execution_result[:status] != "failed"}.map{|s| s.metadata[:location]} # failed_specs = examples.delete_if{|e| e.execution_result[:status] != "failed"}.map{|s| s.metadata[:location]}
# if this fails don't kill everything # # if this fails don't kill everything
begin # begin
FileUtils.mkdir_p('tmp') # FileUtils.mkdir_p('tmp')
File.open("./tmp/rspec_result","w") do |f| # File.open("./tmp/rspec_result","w") do |f|
f.puts failed_specs.join("\n") # f.puts failed_specs.join("\n")
end # end
rescue # rescue
# nothing really we can do, at least don't kill the test runner # # nothing really we can do, at least don't kill the test runner
end # end
super
end end
def start(count)
FileUtils.mkdir_p('tmp')
@fail_file = File.open("./tmp/rspec_result","w")
super(count)
end
def close
@fail_file.close
super
end
def example_failed(example)
@fail_file.puts example.metadata[:location]
@fail_file.flush
super(example)
end
end end

View File

@ -68,7 +68,36 @@ class Autospec::Runner
@signal.signal @signal.signal
end end
Process.wait(@spork_pid) spork_running = true
Thread.new do
Process.wait(@spork_pid)
spork_running = false
end
while spork_running
STDIN.gets
if @queue.length == 0
@queue << ['spec', 'spec']
@signal.signal
else
specs = failed_specs(:delete => false)
puts
puts
if specs.length == 0
puts "No specs have failed yet!"
puts
else
puts "The following specs have failed: "
specs.each do |s|
puts s
end
puts
end
end
end
puts "Spork has been terminated, exiting" puts "Spork has been terminated, exiting"
rescue => e rescue => e
@ -221,12 +250,12 @@ class Autospec::Runner
end end
end end
def failed_specs def failed_specs(opts={:delete => true})
specs = [] specs = []
path = './tmp/rspec_result' path = './tmp/rspec_result'
if File.exist?(path) if File.exist?(path)
specs = File.open(path) { |file| file.read.split("\n") } specs = File.open(path) { |file| file.read.split("\n") }
File.delete(path) File.delete(path) if opts[:delete]
end end
specs specs