Permalink
Browse files

Introduce Mutant::Config objects

This will ease deve
  • Loading branch information...
1 parent 1114a15 commit c7fae6dd0764378aef219ab8104f3c3be5bfa912 Markus Schirp committed Feb 24, 2013
Showing with 45 additions and 11 deletions.
  1. +4 −0 Changelog.md
  2. +1 −1 Gemfile
  3. +2 −0 lib/mutant.rb
  4. +20 −3 lib/mutant/cli.rb
  5. +8 −0 lib/mutant/config.rb
  6. +1 −0 lib/mutant/runner/config.rb
  7. +1 −0 mutant.gemspec
  8. +8 −7 spec/unit/mutant/cli/class_methods/run_spec.rb
View
@@ -1,5 +1,9 @@
# v0.2.17 2013-01-20
+* [change][dm2] Kill mutations in #initialize from class methods.
+
+# v0.2.17 2013-01-20
+
* [change] Update dependencies
# v0.2.16 2013-01-20
View
@@ -4,5 +4,5 @@ gemspec
gem 'composition', :git => 'https://github.com/mbj/composition.git'
-gem 'devtools', :git => 'https://github.com/datamapper/devtools.git'
+gem 'devtools', :path => '../devtools' #:git => 'https://github.com/datamapper/devtools.git'
eval(File.read(File.join(File.dirname(__FILE__),'Gemfile.devtools')))
View
@@ -14,6 +14,7 @@
require 'diff/lcs'
require 'diff/lcs/hunk'
require 'rspec'
+require 'anima'
# Patch ice none to freeze nodes correctly
class IceNine::Freezer
@@ -83,6 +84,7 @@ module Mutant
require 'mutant/mutator/node/iter_19'
require 'mutant/mutator/node/if'
require 'mutant/mutator/node/receiver_case'
+require 'mutant/config'
require 'mutant/loader'
require 'mutant/context'
require 'mutant/context/scope'
View
@@ -14,7 +14,7 @@ class CLI < CLIParser
# @api private
#
def self.run(*arguments)
- config = new(*arguments)
+ config = new(*arguments).config
runner = Runner::Config.run(config)
runner.success? ? EXIT_SUCCESS : EXIT_FAILURE
rescue Error => exception
@@ -46,6 +46,25 @@ def initialize(arguments)
matcher
end
+ # Return config
+ #
+ # @return [Config]
+ #
+ # @api private
+ #
+ def config
+ Config.new(
+ :debug => debug?,
+ :matcher => matcher,
+ :filter => filter,
+ :strategy => strategy,
+ :reporter => reporter
+ )
+ end
+ memoize :config
+
+ private
+
# Test for running in debug mode
#
# @return [true]
@@ -98,8 +117,6 @@ def reporter
end
memoize :reporter
- private
-
# Return matcher
#
# @return [Mutant::Matcher]
View
@@ -0,0 +1,8 @@
+module Mutant
+ # The configuration of a mutator run
+ class Config
+ include Adamantium::Flat, Anima.new(
+ :debug, :strategy, :matcher, :filter, :reporter
+ )
+ end
+end
@@ -1,5 +1,6 @@
module Mutant
class Runner
+ # Runner for config
class Config < self
# Return subject runners
View
@@ -25,4 +25,5 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency('abstract_type', '~> 0.0.4')
gem.add_runtime_dependency('rspec-core', '~> 2.13.0')
gem.add_runtime_dependency('diff-lcs', '~> 1.2.1')
+ gem.add_runtime_dependency('anima', '~> 0.0.5')
end
@@ -3,11 +3,12 @@
describe Mutant::CLI, '.run' do
subject { object.run(argv) }
- let(:object) { described_class }
- let(:argv) { mock('ARGV') }
- let(:attributes) { mock('Options') }
- let(:runner) { mock('Runner', :success? => success) }
- let(:instance) { mock(described_class.name, :attributes => attributes) }
+ let(:object) { described_class }
+ let(:argv) { mock('ARGV') }
+ let(:attributes) { mock('Options') }
+ let(:runner) { mock('Runner', :success? => success) }
+ let(:config) { mock('Config') }
+ let(:instance) { mock(described_class.name, :config => config) }
before do
described_class.stub(:new => instance)
@@ -20,7 +21,7 @@
it { should be(0) }
it 'should run with attributes' do
- Mutant::Runner::Config.should_receive(:run).with(instance).and_return(runner)
+ Mutant::Runner::Config.should_receive(:run).with(config).and_return(runner)
should be(0)
end
end
@@ -31,7 +32,7 @@
it { should be(1) }
it 'should run with attributes' do
- Mutant::Runner::Config.should_receive(:run).with(instance).and_return(runner)
+ Mutant::Runner::Config.should_receive(:run).with(config).and_return(runner)
should be(1)
end
end

4 comments on commit c7fae6d

Contributor

nevir replied Mar 2, 2013

Awesome! Way better than my quick hacks :P

Contributor

nevir replied Mar 2, 2013

Oh, almost - still not completely consumable externally because the strategy depends on the Mutant::CLI object which behaves like a config

Owner

mbj replied Mar 2, 2013

@nevir This will also be addressed. The Runner refactoring is still going on. I do not have much time for mutant.

Contributor

nevir replied Mar 2, 2013

Yeah, no rush

Please sign in to comment.