2013-11-01 18:57:50 -04:00
|
|
|
require "autospec/rspec_runner"
|
|
|
|
|
2013-10-23 19:06:05 -04:00
|
|
|
module Autospec
|
2013-11-01 18:57:50 -04:00
|
|
|
|
|
|
|
class SimpleRunner < RspecRunner
|
|
|
|
|
|
|
|
def run(specs)
|
|
|
|
puts "Running Rspec: " << specs
|
|
|
|
# kill previous rspec instance
|
2017-04-13 17:24:58 -04:00
|
|
|
self.abort
|
2013-11-01 18:57:50 -04:00
|
|
|
# we use our custom rspec formatter
|
|
|
|
args = ["-r", "#{File.dirname(__FILE__)}/formatter.rb",
|
|
|
|
"-f", "Autospec::Formatter", specs.split].flatten.join(" ")
|
|
|
|
# launch rspec
|
2017-04-13 17:24:58 -04:00
|
|
|
Dir.chdir(Rails.root) do
|
2017-07-27 21:20:09 -04:00
|
|
|
env = { "RAILS_ENV" => "test" }
|
|
|
|
if specs.split(' ').any? { |s| s =~ /^(.\/)?plugins/ }
|
2017-06-08 18:02:30 -04:00
|
|
|
env["LOAD_PLUGINS"] = "1"
|
|
|
|
puts "Loading plugins while running specs"
|
|
|
|
end
|
|
|
|
@pid = Process.spawn(env, "bin/rspec #{args}")
|
2017-04-13 17:24:58 -04:00
|
|
|
_, status = Process.wait2(@pid)
|
|
|
|
status.exitstatus
|
|
|
|
end
|
2013-11-01 18:57:50 -04:00
|
|
|
end
|
2013-10-23 19:06:05 -04:00
|
|
|
|
|
|
|
def abort
|
|
|
|
if @pid
|
2013-11-01 18:57:50 -04:00
|
|
|
Process.kill("INT", @pid) rescue nil
|
|
|
|
while (Process.getpgid(@pid) rescue nil)
|
2013-10-23 19:06:05 -04:00
|
|
|
sleep 0.001
|
|
|
|
end
|
|
|
|
@pid = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
2013-11-01 18:57:50 -04:00
|
|
|
abort
|
2013-10-23 19:06:05 -04:00
|
|
|
end
|
2013-11-01 18:57:50 -04:00
|
|
|
|
2013-10-23 19:06:05 -04:00
|
|
|
end
|
2013-11-01 18:57:50 -04:00
|
|
|
|
2013-10-23 19:06:05 -04:00
|
|
|
end
|