Prepare to split mutant-rspec from gem.

* Moves all rspec integration into Mutant::Rspec namespace.
* Removes the unused --rspec-level option
* Mutant::Rspec::Strategy is smelly, has no state. Will make sense with
  future commits.
This commit is contained in:
Markus Schirp 2014-01-17 22:59:22 +01:00
parent 874ae91709
commit 3ebf5b7992
12 changed files with 116 additions and 115 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 790
total_score: 783

View file

@ -31,7 +31,7 @@ FeatureEnvy:
- Mutant::Mutation::Evil#success?
- Mutant::Mutation::Neutral#success?
- Mutant::Reporter::CLI#subject_results
- Mutant::Strategy::Rspec#options
- Mutant::Rspec::Strategy#options
IrresponsibleModule:
enabled: true
exclude: []
@ -83,7 +83,7 @@ TooManyStatements:
- Mutant::CLI#parse
- Mutant::CLI#add_options
- Mutant::CLI#add_strategies
- Mutant::Killer::Rspec#run
- Mutant::Rspec::Killer#run
- Mutant::Reporter::CLI#colorized_diff
- Mutant::Reporter::CLI::Printer::Config::Runner#run
- Mutant::Runner#dispatch
@ -132,8 +132,8 @@ UtilityFunction:
- Mutant::Mutation::Evil#success?
- Mutant::Mutation::Neutral#success?
- Mutant::NodeHelpers#s
- Mutant::Strategy::Rspec#configuration
- Mutant::Strategy::Rspec#options
- Mutant::Strategy::Rspec#world
- Mutant::Rspec::Strategy#configuration
- Mutant::Rspec::Strategy#options
- Mutant::Rspec::Strategy#world
max_helper_calls: 0

View file

@ -17,10 +17,8 @@ require 'unparser'
require 'ice_nine'
require 'diff/lcs'
require 'diff/lcs/hunk'
require 'rspec'
require 'anima'
require 'concord'
require 'rspec'
# Library namespace
module Mutant
@ -113,11 +111,9 @@ require 'mutant/matcher/scope'
require 'mutant/matcher/filter'
require 'mutant/killer'
require 'mutant/killer/static'
require 'mutant/killer/rspec'
require 'mutant/killer/forking'
require 'mutant/killer/forked'
require 'mutant/strategy'
require 'mutant/strategy/rspec'
require 'mutant/runner'
require 'mutant/runner/config'
require 'mutant/runner/subject'
@ -138,3 +134,4 @@ require 'mutant/reporter/cli/printer/subject'
require 'mutant/reporter/cli/printer/killer'
require 'mutant/reporter/cli/printer/mutation'
require 'mutant/zombifier'
require 'mutant/rspec'

View file

@ -168,10 +168,7 @@ module Mutant
parser.separator(EMPTY_STRING)
parser.separator('Strategies:')
{
Builder::Rspec => :@strategy,
Builder::Predicate::Subject => :@subject_predicate,
}.each do |builder, instance_variable_name|
Builder::REGISTRY.each do |builder, instance_variable_name|
builder = builder.new(@cache, parser)
instance_variable_set(instance_variable_name, builder)
end

View file

@ -6,6 +6,18 @@ module Mutant
class Builder
include AbstractType
REGISTRY = {}
# Register builder
#
# @return [undefined]
#
# @api private
#
def self.register(instance_variable_name)
REGISTRY[self] = instance_variable_name
end
# Return cache
#
# @return [Cache]
@ -53,63 +65,14 @@ module Mutant
#
abstract_method :output
# Rspec strategy builder
class Rspec < self
# Initialize object
#
# @return [undefined]
#
# @api private
#
def initialize(*)
@level = 0
@rspec = false
super
end
# Return strategy
#
# @return [Strategy::Rspec]
#
# @api private
#
def output
unless @rspec
raise Error, 'No strategy given'
end
Strategy::Rspec.new(@level)
end
private
# Add cli options
#
# @param [OptionParser] parser
#
# @return [undefined]
#
# @api private
#
def add_options
parser.on('--rspec', 'kills mutations with rspec') do
@rspec = true
end
parser.on('--rspec-level LEVEL', 'set rspec expansion level') do |level|
@level = level.to_i
end
end
end # Rspec
# Abstract predicate builder
class Predicate < self
# Bubject predicate builder
class Subject < self
register :@subject_predicate
# Initialize object
#
# @api private
@ -158,7 +121,7 @@ module Mutant
@predicates << Mutant::Predicate::Matcher.new(matcher)
end
end
end # Subject
end # Predicate

10
lib/mutant/rspec.rb Normal file
View file

@ -0,0 +1,10 @@
require 'rspec'
require 'mutant/rspec/killer'
require 'mutant/rspec/strategy'
require 'mutant/rspec/builder'
module Mutant
module Rspec
end # Rspec
end # Mutant

View file

@ -0,0 +1,51 @@
module Mutant
module Rspec
# Rspec strategy builder
class Builder < CLI::Builder
register :@strategy
# Initialize object
#
# @return [undefined]
#
# @api private
#
def initialize(*)
@rspec = false
super
end
# Return strategy
#
# @return [Strategy::Rspec]
#
# @api private
#
def output
unless @rspec
raise Error, 'No strategy given'
end
Strategy.new
end
private
# Add cli options
#
# @param [OptionParser] parser
#
# @return [undefined]
#
# @api private
#
def add_options
parser.on('--rspec', 'kills mutations with rspec') do
@rspec = true
end
end
end # Builder
end # Rspec
end # Mutant

View file

@ -1,9 +1,9 @@
# encoding: utf-8
module Mutant
class Killer
module Rspec
# Runner for rspec tests
class Rspec < self
class Killer < Mutant::Killer
private
@ -90,6 +90,6 @@ module Mutant
strategy.example_groups
end
end # Rspec
end # Killer
end # Killer
end # Rspec
end # Mutant

View file

@ -1,12 +1,12 @@
# encoding: utf-8
module Mutant
class Strategy
module Rspec
# Rspec killer strategy
class Rspec < self
include Concord.new(:level)
class Strategy < Mutant::Strategy
include Equalizer.new
KILLER = Killer::Forking.new(Killer::Rspec)
KILLER = Killer::Forking.new(Rspec::Killer)
# Setup rspec strategy
#
@ -71,6 +71,6 @@ module Mutant
end
memoize :options, freezer: :noop
end # Rspec
end # Strategy
end # Strategy
end # Rspec
end # Mutant

View file

@ -1,38 +0,0 @@
# encoding: utf-8
require 'spec_helper'
describe Mutant::CLI::Builder::Rspec do
let(:option_parser) { OptionParser.new }
let(:cache) { Mutant::Cache.new }
let(:object) { described_class.new(cache, option_parser) }
let(:level) { double('Level') }
let(:default_strategy) do
Mutant::Strategy::Rspec.new(0)
end
let(:altered_strategy) do
Mutant::Strategy::Rspec.new(1)
end
describe 'default' do
specify do
object
option_parser.parse!(%w[--rspec])
expect(object.output).to eql(default_strategy)
end
end
describe 'parsing a level' do
specify do
object
option_parser.parse!(%w[--rspec --rspec-level 1])
expect(object.output).to eql(altered_strategy)
end
end
end

View file

@ -28,7 +28,7 @@ describe Mutant::CLI, '.new' do
# Defaults
let(:expected_filter) { Mutant::Predicate::TAUTOLOGY }
let(:expected_strategy) { Mutant::Strategy::Rspec.new(0) }
let(:expected_strategy) { Mutant::Rspec::Strategy.new }
let(:expected_reporter) { Mutant::Reporter::CLI.new($stdout) }
let(:ns) { Mutant::Matcher }

View file

@ -0,0 +1,21 @@
# encoding: utf-8
require 'spec_helper'
describe Mutant::Rspec::Builder do
let(:option_parser) { OptionParser.new }
let(:cache) { Mutant::Cache.new }
let(:object) { described_class.new(cache, option_parser) }
let(:default_strategy) do
Mutant::Rspec::Strategy.new
end
specify do
object
option_parser.parse!(%w[--rspec])
expect(object.output).to eql(default_strategy)
end
end