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-07-23 16:42:05 -07:00
|
|
|
|
2013-08-04 18:49:42 +02:00
|
|
|
groups = example_groups
|
2013-07-28 19:28:08 +02:00
|
|
|
|
2013-08-04 18:49:42 +02:00
|
|
|
unless groups
|
|
|
|
$stderr.puts "No rspec example groups found for: #{match_prefixes.join(', ')}"
|
|
|
|
return false
|
|
|
|
end
|
2013-07-23 16:42:05 -07:00
|
|
|
|
2013-08-04 18:49:42 +02:00
|
|
|
strategy.configuration.reporter.report(groups.length, nil) do |reporter|
|
|
|
|
example_groups.each do |group|
|
|
|
|
return true unless group.run(reporter)
|
|
|
|
end.all?
|
2013-07-23 16:42:05 -07:00
|
|
|
|
2013-08-04 18:49:42 +02:00
|
|
|
return false
|
2013-07-23 16:42:05 -07:00
|
|
|
end
|
2013-08-04 18:49:42 +02:00
|
|
|
end
|
2013-07-23 16:42:05 -07:00
|
|
|
|
2013-08-04 18:49:42 +02:00
|
|
|
# Return match prefixes
|
|
|
|
#
|
|
|
|
# @return [Enumerble<String>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def match_prefixes
|
|
|
|
subject.match_prefixes
|
2012-08-28 19:14:10 +02:00
|
|
|
end
|
|
|
|
|
2013-08-04 18:49:42 +02:00
|
|
|
# Return example groups
|
|
|
|
#
|
|
|
|
# @return [Array<RSpec::Example>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def example_groups
|
|
|
|
match_prefixes.each do |match_expression|
|
|
|
|
example_groups = find_with(match_expression)
|
|
|
|
return example_groups unless example_groups.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return example groups that match expression
|
|
|
|
#
|
|
|
|
# @param [String] match_expression
|
|
|
|
#
|
|
|
|
# @return [Enumerable<String>]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def find_with(match_expression)
|
|
|
|
all_example_groups.select do |example_group|
|
|
|
|
example_group.description.start_with?(match_expression)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
DELIMITERS = /::|#/.freeze
|
|
|
|
|
|
|
|
# Return all example groups
|
2012-08-14 12:27:56 +02:00
|
|
|
#
|
2013-08-04 18:49:42 +02:00
|
|
|
# @return [Enumerable<RSpec::Example>]
|
2012-08-14 12:27:56 +02:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-08-04 18:49:42 +02:00
|
|
|
def all_example_groups
|
|
|
|
strategy.example_groups
|
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
|