free_mutant/lib/mutant/integration/rspec.rb

98 lines
2.2 KiB
Ruby
Raw Normal View History

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