Simplify rspec integration differencies between rspec2 and rspec3
This commit is contained in:
parent
3efbfd2dad
commit
609fb3cccb
9 changed files with 109 additions and 106 deletions
|
@ -124,7 +124,7 @@ module Mutant
|
|||
#
|
||||
def setup_integration(name)
|
||||
require "mutant/integration/#{name}"
|
||||
update(integration: Integration.lookup(name).new)
|
||||
update(integration: Integration.lookup(name))
|
||||
end
|
||||
|
||||
# Add options
|
||||
|
|
|
@ -16,7 +16,7 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def self.lookup(name)
|
||||
REGISTRY.fetch(name)
|
||||
REGISTRY.fetch(name).build
|
||||
end
|
||||
|
||||
# Register integration
|
||||
|
|
|
@ -8,6 +8,24 @@ module Mutant
|
|||
class Rspec < self
|
||||
include AbstractType
|
||||
|
||||
register 'rspec'
|
||||
|
||||
RSPEC_2_VERSION_PREFIX = '2.'.freeze
|
||||
|
||||
# Return integration compatible to currently loaded rspec
|
||||
#
|
||||
# @return [Integration]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def self.build
|
||||
if RSpec::Core::Version::STRING.start_with?(RSPEC_2_VERSION_PREFIX)
|
||||
Rspec2.new
|
||||
else
|
||||
Rspec3.new
|
||||
end
|
||||
end
|
||||
|
||||
# Setup rspec integration
|
||||
#
|
||||
# @return [self]
|
||||
|
@ -110,14 +128,86 @@ module Mutant
|
|||
end
|
||||
memoize :options, freezer: :noop
|
||||
|
||||
# Rspec2 integration
|
||||
class Rspec2 < self
|
||||
|
||||
register 'rspec'
|
||||
|
||||
private
|
||||
|
||||
# Return options
|
||||
#
|
||||
# @return [RSpec::Core::ConfigurationOptions]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def options
|
||||
super.tap(&:parse_options)
|
||||
end
|
||||
|
||||
# Return full description of example group
|
||||
#
|
||||
# @param [RSpec::Core::ExampleGroup] example_group
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def full_description(example_group)
|
||||
example_group.metadata.fetch(:example_group).fetch(:full_description)
|
||||
end
|
||||
|
||||
# Return new reporter
|
||||
#
|
||||
# @param [StringIO] output
|
||||
#
|
||||
# @return [RSpec::Core::Reporter]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def new_reporter(output)
|
||||
formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
|
||||
|
||||
RSpec::Core::Reporter.new(formatter)
|
||||
end
|
||||
|
||||
end # Rspec2
|
||||
|
||||
# Rspec 3 integration
|
||||
class Rspec3 < self
|
||||
|
||||
private
|
||||
|
||||
# Return full description for example group
|
||||
#
|
||||
# @param [RSpec::Core::ExampleGroup] example_group
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def full_description(example_group)
|
||||
example_group.metadata.fetch(:full_description)
|
||||
end
|
||||
|
||||
# Return new reporter
|
||||
#
|
||||
# @param [StringIO] output
|
||||
#
|
||||
# @return [RSpec::Core::Reporter]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def new_reporter(output)
|
||||
formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
|
||||
notifications = RSpec::Core::Formatters::Loader.allocate.send(:notifications_for, formatter.class)
|
||||
|
||||
RSpec::Core::Reporter.new(configuration).tap do |reporter|
|
||||
reporter.register_listener(formatter, *notifications)
|
||||
end
|
||||
end
|
||||
|
||||
end # Rspec3
|
||||
end # Rspec
|
||||
end # Integration
|
||||
end # Mutant
|
||||
|
||||
RSPEC_2_VERSION_PREFIX = '2.'.freeze
|
||||
|
||||
if RSpec::Core::Version::STRING.start_with?(RSPEC_2_VERSION_PREFIX)
|
||||
require 'mutant/integration/rspec2'
|
||||
else
|
||||
require 'mutant/integration/rspec3'
|
||||
end
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
module Mutant
|
||||
class Integration
|
||||
# Rspec2 integration
|
||||
class Rspec2 < Rspec
|
||||
|
||||
register 'rspec'
|
||||
|
||||
private
|
||||
|
||||
# Return options
|
||||
#
|
||||
# @return [RSpec::Core::ConfigurationOptions]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def options
|
||||
super.tap(&:parse_options)
|
||||
end
|
||||
|
||||
# Return full description of example group
|
||||
#
|
||||
# @param [RSpec::Core::ExampleGroup] example_group
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def full_description(example_group)
|
||||
example_group.metadata.fetch(:example_group).fetch(:full_description)
|
||||
end
|
||||
|
||||
# Return new reporter
|
||||
#
|
||||
# @param [StringIO] output
|
||||
#
|
||||
# @return [RSpec::Core::Reporter]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def new_reporter(output)
|
||||
formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
|
||||
|
||||
RSpec::Core::Reporter.new(formatter)
|
||||
end
|
||||
|
||||
end # Rspec2
|
||||
end # Integration
|
||||
end # Mutant
|
|
@ -1,41 +0,0 @@
|
|||
module Mutant
|
||||
class Integration
|
||||
# Rspec3 integration
|
||||
class Rspec3 < Rspec
|
||||
|
||||
register 'rspec'
|
||||
|
||||
private
|
||||
|
||||
# Return full description for example group
|
||||
#
|
||||
# @param [RSpec::Core::ExampleGroup] example_group
|
||||
#
|
||||
# @return [String]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def full_description(example_group)
|
||||
example_group.metadata.fetch(:full_description)
|
||||
end
|
||||
|
||||
# Return new reporter
|
||||
#
|
||||
# @param [StringIO] output
|
||||
#
|
||||
# @return [RSpec::Core::Reporter]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def new_reporter(output)
|
||||
formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
|
||||
notifications = RSpec::Core::Formatters::Loader.allocate.send(:notifications_for, formatter.class)
|
||||
|
||||
RSpec::Core::Reporter.new(configuration).tap do |reporter|
|
||||
reporter.register_listener(formatter, *notifications)
|
||||
end
|
||||
end
|
||||
|
||||
end # Rspec3
|
||||
end # Integration
|
||||
end # Mutant
|
|
@ -13,8 +13,8 @@ Gem::Specification.new do |gem|
|
|||
gem.license = 'MIT'
|
||||
|
||||
gem.require_paths = %w[lib]
|
||||
gem.files = `git ls-files -- lib/mutant/integration/rspec{,2,3}.rb`.split("\n")
|
||||
gem.test_files = `git ls-files -- spec/{unit/mutant/rspec,integration/rspec}`.split("\n")
|
||||
gem.files = `git ls-files -- lib/mutant/integration/rspec.rb`.split("\n")
|
||||
gem.test_files = `git ls-files -- spec/{unit,integration}/mutant/rspec/**/*.rb}`.split("\n")
|
||||
gem.extra_rdoc_files = %w[TODO LICENSE]
|
||||
|
||||
gem.add_runtime_dependency('mutant', "~> #{gem.version}")
|
||||
|
|
|
@ -5,10 +5,6 @@ require 'spec_helper'
|
|||
|
||||
describe 'Mutant on ruby corpus' do
|
||||
|
||||
ROOT = Pathname.new(__FILE__).parent.parent.parent.parent
|
||||
|
||||
TMP = ROOT.join('tmp').freeze
|
||||
|
||||
before do
|
||||
skip 'Corpus test is deactivated on 1.9.3' if RUBY_VERSION.eql?('1.9.3')
|
||||
skip 'Corpus test is deactivated on RBX' if RUBY_ENGINE.eql?('rbx')
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
require 'morpher'
|
||||
require 'anima'
|
||||
|
||||
# Namespace module for corpus testing
|
||||
module Corpus
|
||||
# Project under corpus test
|
||||
# rubocop:disable ClassLength
|
||||
ROOT = Pathname.new(__FILE__).parent.parent.parent
|
||||
TMP = ROOT.join('tmp').freeze
|
||||
|
||||
class Project
|
||||
MUTEX = Mutex.new
|
||||
include Adamantium, Anima.new(
|
||||
|
|
|
@ -161,7 +161,7 @@ Options:
|
|||
|
||||
it_should_behave_like 'a cli parser'
|
||||
|
||||
let(:expected_integration) { Mutant::Integration::Rspec2.new }
|
||||
let(:expected_integration) { Mutant::Integration::Rspec::Rspec2.new }
|
||||
end
|
||||
|
||||
context 'with version flag' do
|
||||
|
|
Loading…
Add table
Reference in a new issue