diff --git a/config/flay.yml b/config/flay.yml index 3050cb1d..4e120a35 100644 --- a/config/flay.yml +++ b/config/flay.yml @@ -1,3 +1,3 @@ --- threshold: 18 -total_score: 790 +total_score: 783 diff --git a/config/reek.yml b/config/reek.yml index be8e92c2..5e113839 100644 --- a/config/reek.yml +++ b/config/reek.yml @@ -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 diff --git a/lib/mutant.rb b/lib/mutant.rb index a80c89b9..25621519 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -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' diff --git a/lib/mutant/cli.rb b/lib/mutant/cli.rb index 92720b85..26bce678 100644 --- a/lib/mutant/cli.rb +++ b/lib/mutant/cli.rb @@ -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 diff --git a/lib/mutant/cli/builder.rb b/lib/mutant/cli/builder.rb index cfb3e1ae..b49a13b4 100644 --- a/lib/mutant/cli/builder.rb +++ b/lib/mutant/cli/builder.rb @@ -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 diff --git a/lib/mutant/rspec.rb b/lib/mutant/rspec.rb new file mode 100644 index 00000000..5e85fdeb --- /dev/null +++ b/lib/mutant/rspec.rb @@ -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 diff --git a/lib/mutant/rspec/builder.rb b/lib/mutant/rspec/builder.rb new file mode 100644 index 00000000..657d08a4 --- /dev/null +++ b/lib/mutant/rspec/builder.rb @@ -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 diff --git a/lib/mutant/killer/rspec.rb b/lib/mutant/rspec/killer.rb similarity index 95% rename from lib/mutant/killer/rspec.rb rename to lib/mutant/rspec/killer.rb index ff5828ff..27ac01e4 100644 --- a/lib/mutant/killer/rspec.rb +++ b/lib/mutant/rspec/killer.rb @@ -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 diff --git a/lib/mutant/strategy/rspec.rb b/lib/mutant/rspec/strategy.rb similarity index 89% rename from lib/mutant/strategy/rspec.rb rename to lib/mutant/rspec/strategy.rb index 08d9cf09..4ad063fc 100644 --- a/lib/mutant/strategy/rspec.rb +++ b/lib/mutant/rspec/strategy.rb @@ -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 diff --git a/spec/unit/mutant/cli/builder/rspec_spec.rb b/spec/unit/mutant/cli/builder/rspec_spec.rb deleted file mode 100644 index 9de0e459..00000000 --- a/spec/unit/mutant/cli/builder/rspec_spec.rb +++ /dev/null @@ -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 diff --git a/spec/unit/mutant/cli_new_spec.rb b/spec/unit/mutant/cli_new_spec.rb index 567f02f9..51cbe39e 100644 --- a/spec/unit/mutant/cli_new_spec.rb +++ b/spec/unit/mutant/cli_new_spec.rb @@ -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 } diff --git a/spec/unit/mutant/rspec/builder_spec.rb b/spec/unit/mutant/rspec/builder_spec.rb new file mode 100644 index 00000000..047bc0cd --- /dev/null +++ b/spec/unit/mutant/rspec/builder_spec.rb @@ -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