Separate rspec2 and rspec3 integrations
This commit is contained in:
parent
f2e908dd35
commit
55b93b5d76
6 changed files with 111 additions and 66 deletions
|
@ -1,3 +1,3 @@
|
||||||
---
|
---
|
||||||
threshold: 18
|
threshold: 18
|
||||||
total_score: 950
|
total_score: 960
|
||||||
|
|
|
@ -25,7 +25,8 @@ DuplicateMethodCall:
|
||||||
FeatureEnvy:
|
FeatureEnvy:
|
||||||
enabled: true
|
enabled: true
|
||||||
exclude:
|
exclude:
|
||||||
- Mutant::Integration::Rspec#full_description
|
- Mutant::Integration::Rspec2#full_description
|
||||||
|
- Mutant::Integration::Rspec3#full_description
|
||||||
- Mutant::Matcher::Method::Instance#match?
|
- Mutant::Matcher::Method::Instance#match?
|
||||||
- Mutant::Matcher::Method::Singleton#receiver?
|
- Mutant::Matcher::Method::Singleton#receiver?
|
||||||
- Mutant::Mutation::Evil#success?
|
- Mutant::Mutation::Evil#success?
|
||||||
|
@ -71,7 +72,6 @@ RepeatedConditional:
|
||||||
enabled: true
|
enabled: true
|
||||||
exclude:
|
exclude:
|
||||||
- Mutant::Mutator
|
- Mutant::Mutator
|
||||||
- Mutant::Integration::Rspec
|
|
||||||
- Mutant::Reporter::CLI
|
- Mutant::Reporter::CLI
|
||||||
- Mutant::Meta::Example::DSL
|
- Mutant::Meta::Example::DSL
|
||||||
max_ifs: 1
|
max_ifs: 1
|
||||||
|
@ -95,7 +95,6 @@ TooManyStatements:
|
||||||
enabled: true
|
enabled: true
|
||||||
exclude:
|
exclude:
|
||||||
- Mutant#self.singleton_subclass_instance
|
- Mutant#self.singleton_subclass_instance
|
||||||
- Mutant::Integration::Rspec#new_reporter
|
|
||||||
- Mutant::Reporter::CLI::Report::Config#run
|
- Mutant::Reporter::CLI::Report::Config#run
|
||||||
- Mutant::Reporter::CLI::Registry#included
|
- Mutant::Reporter::CLI::Registry#included
|
||||||
- Mutant::Reporter::CLI#colorized_diff
|
- Mutant::Reporter::CLI#colorized_diff
|
||||||
|
@ -122,7 +121,9 @@ UncommunicativeMethodName:
|
||||||
accept: []
|
accept: []
|
||||||
UncommunicativeModuleName:
|
UncommunicativeModuleName:
|
||||||
enabled: true
|
enabled: true
|
||||||
exclude: []
|
exclude:
|
||||||
|
- Rspec2
|
||||||
|
- Rspec3
|
||||||
reject:
|
reject:
|
||||||
- !ruby/regexp /^.$/
|
- !ruby/regexp /^.$/
|
||||||
- !ruby/regexp /[0-9]$/
|
- !ruby/regexp /[0-9]$/
|
||||||
|
@ -151,7 +152,10 @@ UtilityFunction:
|
||||||
exclude:
|
exclude:
|
||||||
- Mutant::CLI#reporter
|
- Mutant::CLI#reporter
|
||||||
- Mutant::Integration::Rspec#configuration
|
- Mutant::Integration::Rspec#configuration
|
||||||
- Mutant::Integration::Rspec#rspec2?
|
- Mutant::Integration::Rspec#options
|
||||||
|
- Mutant::Integration::Rspec2#full_description
|
||||||
|
- Mutant::Integration::Rspec2#new_reporter
|
||||||
|
- Mutant::Integration::Rspec3#full_description
|
||||||
- Mutant::Meta::Example::Verification#format_mutation
|
- Mutant::Meta::Example::Verification#format_mutation
|
||||||
- Mutant::Mutation::Evil#success?
|
- Mutant::Mutation::Evil#success?
|
||||||
- Mutant::Mutation::Neutral#success?
|
- Mutant::Mutation::Neutral#success?
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
module Mutant
|
module Mutant
|
||||||
class Integration
|
class Integration
|
||||||
# Rspec integration
|
# Shared parts of rspec2/3 integration
|
||||||
class Rspec < self
|
class Rspec < self
|
||||||
|
include AbstractType
|
||||||
register 'rspec'
|
|
||||||
|
|
||||||
RSPEC_2_VERSION_PREFIX = '2.'.freeze
|
|
||||||
|
|
||||||
# Setup rspec integration
|
# Setup rspec integration
|
||||||
#
|
#
|
||||||
|
@ -73,58 +70,6 @@ module Mutant
|
||||||
end
|
end
|
||||||
memoize :example_group_index
|
memoize :example_group_index
|
||||||
|
|
||||||
# Return new reporter
|
|
||||||
#
|
|
||||||
# @param [StringIO] output
|
|
||||||
#
|
|
||||||
# @return [RSpec::Core::Reporter]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def new_reporter(output)
|
|
||||||
reporter_class = RSpec::Core::Reporter
|
|
||||||
|
|
||||||
# rspec3 does require that one via a very indirect autoload setup
|
|
||||||
require 'rspec/core/formatters/base_text_formatter'
|
|
||||||
formatter = RSpec::Core::Formatters::BaseTextFormatter.new(output)
|
|
||||||
|
|
||||||
if rspec2?
|
|
||||||
reporter_class.new(formatter)
|
|
||||||
else
|
|
||||||
notifications = RSpec::Core::Formatters::Loader.allocate.send(:notifications_for, formatter.class)
|
|
||||||
reporter = reporter_class.new(configuration)
|
|
||||||
reporter.register_listener(formatter, *notifications)
|
|
||||||
reporter
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Test for rspec2
|
|
||||||
#
|
|
||||||
# @return [Boolean]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def rspec2?
|
|
||||||
RSpec::Core::Version::STRING.start_with?(RSPEC_2_VERSION_PREFIX)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return full description for example group
|
|
||||||
#
|
|
||||||
# @param [RSpec::Core::ExampleGroup] example_group
|
|
||||||
#
|
|
||||||
# @return [String]
|
|
||||||
#
|
|
||||||
# @api private
|
|
||||||
#
|
|
||||||
def full_description(example_group)
|
|
||||||
metadata = example_group.metadata
|
|
||||||
if rspec2?
|
|
||||||
metadata.fetch(:example_group).fetch(:full_description)
|
|
||||||
else
|
|
||||||
metadata.fetch(:full_description)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return configuration
|
# Return configuration
|
||||||
#
|
#
|
||||||
# @return [RSpec::Core::Configuration]
|
# @return [RSpec::Core::Configuration]
|
||||||
|
@ -143,9 +88,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def options
|
def options
|
||||||
options = RSpec::Core::ConfigurationOptions.new(%w[--fail-fast spec])
|
RSpec::Core::ConfigurationOptions.new(%w[--fail-fast spec])
|
||||||
options.parse_options if rspec2?
|
|
||||||
options
|
|
||||||
end
|
end
|
||||||
memoize :options, freezer: :noop
|
memoize :options, freezer: :noop
|
||||||
|
|
||||||
|
|
48
lib/mutant/integration/rspec2.rb
Normal file
48
lib/mutant/integration/rspec2.rb
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
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
|
41
lib/mutant/integration/rspec3.rb
Normal file
41
lib/mutant/integration/rspec3.rb
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
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
|
|
@ -2,4 +2,13 @@
|
||||||
require 'rspec/core'
|
require 'rspec/core'
|
||||||
require 'rspec/version'
|
require 'rspec/version'
|
||||||
|
|
||||||
|
require 'rspec/core/formatters/base_text_formatter'
|
||||||
|
|
||||||
|
RSPEC_2_VERSION_PREFIX = '2.'.freeze
|
||||||
|
|
||||||
require 'mutant/integration/rspec'
|
require 'mutant/integration/rspec'
|
||||||
|
if RSpec::Core::Version::STRING.start_with?(RSPEC_2_VERSION_PREFIX)
|
||||||
|
require 'mutant/integration/rspec2'
|
||||||
|
else
|
||||||
|
require 'mutant/integration/rspec3'
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue