2013-07-28 16:03:06 -07:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2012-08-14 12:27:56 +02:00
|
|
|
module Mutant
|
|
|
|
class Killer
|
2012-08-28 19:14:10 +02:00
|
|
|
# Runner for rspec tests
|
2012-08-14 12:27:56 +02:00
|
|
|
class Rspec < self
|
2013-01-15 23:46:05 +01:00
|
|
|
|
2012-08-14 12:27:56 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
# Run rspec test
|
|
|
|
#
|
|
|
|
# @return [true]
|
2013-04-17 20:31:21 -07:00
|
|
|
# when test is NOT successful
|
2012-08-14 12:27:56 +02:00
|
|
|
#
|
|
|
|
# @return [false]
|
2013-01-21 23:54:25 +01:00
|
|
|
# otherwise
|
2012-08-14 12:27:56 +02:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def run
|
2012-12-07 18:53:03 +01:00
|
|
|
mutation.insert
|
2013-04-17 19:04:49 -07:00
|
|
|
# TODO: replace with real streams from configuration
|
2013-04-17 20:24:14 -07:00
|
|
|
require 'stringio'
|
2013-07-28 19:28:08 +02:00
|
|
|
# Note: We assume interesting output from a failed rspec run is stderr.
|
2013-07-23 16:42:05 -07:00
|
|
|
rspec_err = StringIO.new
|
|
|
|
|
2013-07-28 19:28:08 +02:00
|
|
|
exit_code = ::RSpec::Core::Runner.run(cli_arguments, nil, rspec_err)
|
|
|
|
|
|
|
|
killed = !exit_code.zero?
|
2013-07-23 16:42:05 -07:00
|
|
|
|
|
|
|
if killed and mutation.should_survive?
|
|
|
|
rspec_err.rewind
|
|
|
|
|
|
|
|
puts "#{mutation.class} test failed."
|
|
|
|
puts 'RSpec stderr:'
|
|
|
|
puts rspec_err.read
|
|
|
|
end
|
|
|
|
|
|
|
|
killed
|
2012-08-28 19:14:10 +02:00
|
|
|
end
|
|
|
|
|
2012-08-14 12:27:56 +02:00
|
|
|
# Return command line arguments
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-07-28 19:28:08 +02:00
|
|
|
def cli_arguments
|
2012-08-14 12:27:56 +02:00
|
|
|
%W(
|
|
|
|
--fail-fast
|
2013-01-13 23:47:00 +01:00
|
|
|
) + strategy.spec_files(mutation.subject)
|
2012-11-21 22:28:08 +01:00
|
|
|
end
|
2013-02-01 23:39:00 +01:00
|
|
|
|
2013-06-14 20:54:02 +02:00
|
|
|
end # Rspec
|
|
|
|
end # Killer
|
|
|
|
end # Mutant
|