free_mutant/lib/mutant/killer/rspec.rb
Dan Kubb 7293386c26 Add magic encoding header to all ruby files
* rubocop still warns about this on ruby 1.9.3, so it was fixed so
  it produces less output on travis.
2013-07-28 16:03:06 -07:00

56 lines
1.1 KiB
Ruby

# encoding: utf-8
module Mutant
class Killer
# Runner for rspec tests
class Rspec < self
private
# Run rspec test
#
# @return [true]
# when test is NOT successful
#
# @return [false]
# otherwise
#
# @api private
#
def run
mutation.insert
# TODO: replace with real streams from configuration
require 'stringio'
# Note: We assume interesting output from a failed rspec run is stderr.
rspec_err = StringIO.new
exit_code = ::RSpec::Core::Runner.run(cli_arguments, nil, rspec_err)
killed = !exit_code.zero?
if killed and mutation.should_survive?
rspec_err.rewind
puts "#{mutation.class} test failed."
puts 'RSpec stderr:'
puts rspec_err.read
end
killed
end
# Return command line arguments
#
# @return [Array]
#
# @api private
#
def cli_arguments
%W(
--fail-fast
) + strategy.spec_files(mutation.subject)
end
end # Rspec
end # Killer
end # Mutant