free_mutant/lib/mutant/rspec/strategy.rb
Markus Schirp a618d82fb1 Push down test selection and add framework for output capture
This clearly is a WIP. We know have the reporter granularity to capture
per mutation test outputs + per mutation test selections.

This adds all infrastructure to address:

* #185 we know which tests are run in reporter
* #180 fine grained information available for the reporter
* #178 minitest project integration only needs to return an enumerable
  with metadata
* #174 We can now "see" all test, allowing to generate a default
  matcher.
* #158 Ability to steer test selection centralized for all integrations
* #125 We have the required objects in graph
* #96 We have finer granularity in reporter graph

Because we know signal more complex state from killforks to parent I
need to bring back killfork partent signalling, but this time with
sending complex data around (Test::Report). Should be easy with
Marshal.{dump,load} but my OSS time budget is exhausted for now.
2014-04-28 19:17:29 +00:00

148 lines
2.8 KiB
Ruby

# encoding: utf-8
module Mutant
module Rspec
# Rspec test abstraction
class Test < Mutant::Test
include Concord.new(:strategy, :example_group)
# Return subject identification
#
# @return [String]
#
# @api private
#
def subject_identification
example_group.description
end
memoize :subject_identification
# Run test, return report
#
# @return [String]
#
# @api private
#
def run
flag = example_group.run(strategy.reporter)
Report.new(
test: self,
output: '',
success: flag
)
end
end # Test
# Rspec killer strategy
class Strategy < Mutant::Strategy
register 'rspec'
# Setup rspec strategy
#
# @return [self]
#
# @api private
#
def setup
output = StringIO.new
configuration.error_stream = output
configuration.output_stream = output
options.configure(configuration)
configuration.load_spec_files
self
end
memoize :setup
# Return new reporter
#
# @api private
#
def reporter
reporter_class = RSpec::Core::Reporter
if rspec2?
reporter_class.new
else
reporter_class.new(configuration)
end
end
# Detect RSpec 2
#
# @return [true]
# when RSpec 2
#
# @return [false]
# otherwise
#
# @api private
#
def rspec2?
RSpec::Core::Version::STRING.start_with?('2.')
end
# Return configuration
#
# @return [RSpec::Core::Configuration]
#
# @api private
#
def configuration
RSpec::Core::Configuration.new
end
memoize :configuration, freezer: :noop
# Return example groups
#
# @return [Enumerable<RSpec::Core::ExampleGroup>]
#
# @api private
#
def example_groups
world.example_groups
end
private
# Return world
#
# @return [RSpec::Core::World]
#
# @api private
#
def world
RSpec.world
end
memoize :world, freezer: :noop
# Return all available tests
#
# @return [Enumerable<Test>]
#
# @api private
#
def all_tests
example_groups.map do |example_group|
Test.new(self, example_group)
end
end
# Return options
#
# @return [RSpec::Core::ConfigurationOptions]
#
# @api private
#
def options
options = RSpec::Core::ConfigurationOptions.new(%w(--fail-fast spec))
options.parse_options if rspec2?
options
end
memoize :options, freezer: :noop
end # Strategy
end # Rspec
end # Mutant