Introduce Mutant::Config objects

This will ease deve
This commit is contained in:
Markus Schirp 2013-02-24 20:40:23 +01:00
parent 1114a156e5
commit c7fae6dd07
8 changed files with 45 additions and 11 deletions

View file

@ -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 file

@ -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 file

@ -14,6 +14,7 @@ require 'composition'
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 @@ require 'mutant/mutator/node/return'
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 file

@ -14,7 +14,7 @@ module Mutant
# @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 @@ module Mutant
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 @@ module Mutant
end
memoize :reporter
private
# Return matcher
#
# @return [Mutant::Matcher]

8
lib/mutant/config.rb Normal file
View file

@ -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

View file

@ -1,5 +1,6 @@
module Mutant
class Runner
# Runner for config
class Config < self
# Return subject runners

View file

@ -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

View file

@ -3,11 +3,12 @@ require 'spec_helper'
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 @@ describe Mutant::CLI, '.run' do
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 @@ describe Mutant::CLI, '.run' do
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