Allow to select forking rspec killer via subclass

This commit is contained in:
Markus Schirp 2012-08-28 19:14:10 +02:00
parent c211a2e065
commit d6a3ecb00f

View file

@ -1,6 +1,6 @@
module Mutant module Mutant
class Killer class Killer
# Simple runner for rspec tests # Runner for rspec tests
class Rspec < self class Rspec < self
# Run block in clean rspec environment # Run block in clean rspec environment
@ -57,17 +57,26 @@ module Mutant
# @api private # @api private
# #
def run def run
!run_rspec.zero?
end
# Run rspec with some wired compat stuff
#
# FIXME: This extra stuff needs to be configurable per project
#
# @return [Fixnum]
# returns the exit status from rspec runner
#
# @api private
#
def run_rspec
require 'rspec'
self.class.nest do self.class.nest do
argv = command_line_arguments
fork do
require './spec/spec_helper.rb' require './spec/spec_helper.rb'
if RSpec.world.shared_example_groups.empty? if RSpec.world.shared_example_groups.empty?
Dir['spec/{support,shared}/**/*.rb'].each { |f| load(f) } Dir['spec/{support,shared}/**/*.rb'].each { |f| load(f) }
end end
exit ::RSpec::Core::Runner.run(argv, @error_stream, @output_stream) ::RSpec::Core::Runner.run(command_line_arguments, @error_stream, @output_stream)
end
pid, status = Process.wait2
!status.exitstatus.zero?
end end
end end
@ -94,6 +103,23 @@ module Mutant
def filename_pattern def filename_pattern
'spec/unit/**/*_spec.rb' 'spec/unit/**/*_spec.rb'
end end
class Forking < self
# Run rspec in subprocess
#
# @return [Fixnum]
# returns the exit status from rspec runner
#
# @api private
#
def run_rspec
fork do
exit run_rspec
end
pid, status = Process.wait2
status.exitstatus
end
end
end end
end end
end end