2012-12-07 16:55:53 +01:00
|
|
|
module Mutant
|
2014-06-28 23:04:18 +00:00
|
|
|
class Integration
|
2014-06-28 23:54:04 +00:00
|
|
|
# Shared parts of rspec2/3 integration
|
2014-06-28 23:04:18 +00:00
|
|
|
class Rspec < self
|
2014-06-28 23:54:04 +00:00
|
|
|
include AbstractType
|
2014-05-23 02:33:15 +00:00
|
|
|
|
2014-06-28 23:04:18 +00:00
|
|
|
# Setup rspec integration
|
2013-01-18 21:38:46 +01:00
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2013-07-17 19:59:44 +02:00
|
|
|
def setup
|
2013-08-04 18:49:42 +02:00
|
|
|
options.configure(configuration)
|
|
|
|
configuration.load_spec_files
|
2013-01-18 21:38:46 +01:00
|
|
|
self
|
|
|
|
end
|
2013-08-04 18:49:42 +02:00
|
|
|
memoize :setup
|
|
|
|
|
2014-05-23 02:33:15 +00:00
|
|
|
# Return report for test
|
|
|
|
#
|
|
|
|
# @param [Rspec::Test] test
|
2014-04-28 19:17:25 +00:00
|
|
|
#
|
2014-06-28 20:52:47 +00:00
|
|
|
# @return [Test::Report]
|
|
|
|
#
|
2014-04-28 19:17:25 +00:00
|
|
|
# @api private
|
|
|
|
#
|
2014-05-23 02:33:15 +00:00
|
|
|
def run(test)
|
|
|
|
output = StringIO.new
|
|
|
|
success = false
|
|
|
|
reporter = new_reporter(output)
|
|
|
|
reporter.report(1) do
|
2014-06-28 22:48:56 +00:00
|
|
|
success = example_group_index.fetch(test.expression.syntax).run(reporter)
|
2014-04-28 19:17:25 +00:00
|
|
|
end
|
2014-05-23 02:33:15 +00:00
|
|
|
output.rewind
|
|
|
|
Test::Report.new(
|
2014-05-23 02:53:24 +00:00
|
|
|
test: self,
|
|
|
|
output: output.read,
|
2014-05-23 02:33:15 +00:00
|
|
|
success: success
|
|
|
|
)
|
2014-04-28 19:17:25 +00:00
|
|
|
end
|
|
|
|
|
2014-05-23 02:33:15 +00:00
|
|
|
# Return all available tests
|
2014-04-28 19:17:25 +00:00
|
|
|
#
|
2014-05-23 02:33:15 +00:00
|
|
|
# @return [Enumerable<Test>]
|
2014-04-28 19:17:25 +00:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-05-23 02:33:15 +00:00
|
|
|
def all_tests
|
2014-06-28 22:48:56 +00:00
|
|
|
example_group_index.keys.each_with_object([]) do |full_description, aggregate|
|
|
|
|
expression = Expression.parse(full_description) or next
|
2014-06-28 20:47:46 +00:00
|
|
|
|
2014-06-28 22:48:56 +00:00
|
|
|
aggregate << Test.new(self, expression)
|
2014-06-28 20:47:46 +00:00
|
|
|
end
|
2014-04-28 19:17:25 +00:00
|
|
|
end
|
2014-05-23 02:33:15 +00:00
|
|
|
memoize :all_tests
|
2014-04-28 19:17:25 +00:00
|
|
|
|
2014-05-23 02:33:15 +00:00
|
|
|
private
|
|
|
|
|
2014-06-28 20:47:46 +00:00
|
|
|
# Return all example groups
|
|
|
|
#
|
2014-06-28 22:48:56 +00:00
|
|
|
# @return [Hash<String, RSpec::Core::ExampleGroup]
|
2014-06-28 20:47:46 +00:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-06-28 22:48:56 +00:00
|
|
|
def example_group_index
|
|
|
|
Hash[RSpec.world.example_groups.flat_map(&:descendants).map do |example_group|
|
|
|
|
[full_description(example_group), example_group]
|
|
|
|
end]
|
2014-06-28 20:47:46 +00:00
|
|
|
end
|
2014-06-28 22:48:56 +00:00
|
|
|
memoize :example_group_index
|
2014-06-28 20:47:46 +00:00
|
|
|
|
2014-05-23 02:33:15 +00:00
|
|
|
# Return configuration
|
2014-04-28 19:17:25 +00:00
|
|
|
#
|
2014-05-23 02:33:15 +00:00
|
|
|
# @return [RSpec::Core::Configuration]
|
2014-04-28 19:17:25 +00:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-05-23 02:33:15 +00:00
|
|
|
def configuration
|
|
|
|
RSpec::Core::Configuration.new
|
2014-04-28 19:17:25 +00:00
|
|
|
end
|
2014-05-23 02:33:15 +00:00
|
|
|
memoize :configuration, freezer: :noop
|
2014-04-28 19:17:25 +00:00
|
|
|
|
2013-08-04 18:49:42 +02:00
|
|
|
# Return options
|
|
|
|
#
|
|
|
|
# @return [RSpec::Core::ConfigurationOptions]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def options
|
2014-06-28 23:54:04 +00:00
|
|
|
RSpec::Core::ConfigurationOptions.new(%w[--fail-fast spec])
|
2013-08-04 18:49:42 +02:00
|
|
|
end
|
2013-09-07 20:27:06 +02:00
|
|
|
memoize :options, freezer: :noop
|
2013-01-18 21:38:46 +01:00
|
|
|
|
2014-06-28 23:04:18 +00:00
|
|
|
end # Rspec
|
|
|
|
end # Integration
|
2013-06-14 20:54:02 +02:00
|
|
|
end # Mutant
|