2012-08-14 06:27:56 -04:00
|
|
|
module Mutant
|
|
|
|
class Killer
|
2012-08-28 13:14:10 -04:00
|
|
|
# Runner for rspec tests
|
2012-08-14 06:27:56 -04:00
|
|
|
class Rspec < self
|
|
|
|
|
|
|
|
# Run block in clean rspec environment
|
|
|
|
#
|
2012-08-15 22:10:54 -04:00
|
|
|
# @return [Object]
|
|
|
|
# returns the value of block
|
2012-08-14 06:27:56 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def self.nest
|
|
|
|
original_world, original_configuration =
|
|
|
|
::RSpec.instance_variable_get(:@world),
|
|
|
|
::RSpec.instance_variable_get(:@configuration)
|
|
|
|
|
2012-08-20 11:53:41 -04:00
|
|
|
::RSpec.reset
|
2012-08-14 06:27:56 -04:00
|
|
|
|
|
|
|
yield
|
|
|
|
ensure
|
2012-10-19 17:34:19 -04:00
|
|
|
::RSpec.instance_variable_set(:@world, original_world)
|
|
|
|
::RSpec.instance_variable_set(:@configuration, original_configuration)
|
2012-08-14 06:27:56 -04:00
|
|
|
end
|
|
|
|
|
2012-08-15 22:10:54 -04:00
|
|
|
# Return identification
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def identification
|
2012-10-26 05:24:29 -04:00
|
|
|
"rspec:#{mutation.identification}".freeze
|
2012-08-15 22:10:54 -04:00
|
|
|
end
|
2012-10-26 05:24:29 -04:00
|
|
|
memoize :identification
|
2012-08-15 22:10:54 -04:00
|
|
|
|
2012-08-14 06:27:56 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
# Initialize rspec runner
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(*)
|
|
|
|
@error_stream, @output_stream = StringIO.new, StringIO.new
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
# Run rspec test
|
|
|
|
#
|
|
|
|
# @return [true]
|
|
|
|
# returns true when test is NOT successful and the mutant was killed
|
|
|
|
#
|
|
|
|
# @return [false]
|
|
|
|
# returns false otherwise
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def run
|
2012-08-28 13:14:10 -04:00
|
|
|
!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'
|
2012-08-15 22:10:54 -04:00
|
|
|
self.class.nest do
|
2012-08-28 13:14:10 -04:00
|
|
|
require './spec/spec_helper.rb'
|
|
|
|
if RSpec.world.shared_example_groups.empty?
|
|
|
|
Dir['spec/{support,shared}/**/*.rb'].each { |f| load(f) }
|
2012-08-20 11:53:41 -04:00
|
|
|
end
|
2012-08-28 13:14:10 -04:00
|
|
|
::RSpec::Core::Runner.run(command_line_arguments, @error_stream, @output_stream)
|
2012-08-15 22:10:54 -04:00
|
|
|
end
|
2012-08-14 06:27:56 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Return command line arguments
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def command_line_arguments
|
|
|
|
%W(
|
|
|
|
--fail-fast
|
|
|
|
) + Dir[filename_pattern]
|
|
|
|
end
|
|
|
|
|
2012-11-21 16:28:08 -05:00
|
|
|
# Return filename pattern
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def filename_pattern
|
|
|
|
"test_app/spec/**/*_spec.rb"
|
|
|
|
end
|
|
|
|
|
2012-08-28 13:14:10 -04:00
|
|
|
class Forking < self
|
|
|
|
# Run rspec in subprocess
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
# returns the exit status from rspec runner
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def run_rspec
|
2012-11-21 16:28:08 -05:00
|
|
|
p :prefork
|
2012-08-28 13:43:53 -04:00
|
|
|
fork do
|
2012-08-28 13:14:10 -04:00
|
|
|
exit run_rspec
|
|
|
|
end
|
|
|
|
pid, status = Process.wait2
|
|
|
|
status.exitstatus
|
|
|
|
end
|
|
|
|
end
|
2012-08-14 06:27:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|