Add abstract (test) runner

This commit is contained in:
Markus Schirp 2012-08-01 19:05:34 +02:00
parent 87161f382d
commit b6de7fad91
6 changed files with 179 additions and 0 deletions

View file

@ -37,6 +37,7 @@ end
require 'mutant/support/abstract'
require 'mutant/random'
require 'mutant/runner'
require 'mutant/mutator'
require 'mutant/mutator/registry'
require 'mutant/mutator/literal'

80
lib/mutant/runner.rb Normal file
View file

@ -0,0 +1,80 @@
module Mutant
# Abstract runner for tests
class Runner
include Veritas::Immutable
extend Abstract
# Run runner
#
# @api private
#
# @return [Runner]
#
def self.run(*args)
new(*args)
end
# Return subject of test
#
# @api private
#
# @return [Subject]
#
attr_reader :subject
# Return mutant tested
#
# @api private
#
# @return [Rubnius::AST::Node]
#
attr_reader :mutant
# Check if mutant was killed
#
# @return [true]
# returns true when mutant was killed
#
# @return [false]
# returns false otherwise
#
# @api private
#
def killed?
@killed
end
private
private_class_method :new
# Initialize runner and run the test
#
# @param [Subject] subject
# @param [Rubinius::AST::Node] mutant
#
# @return [undefined]
#
# @api private
#
def initialize(subject,mutant)
@subject,@mutant = subject,mutant
subject.insert(@mutant)
@killed = run
subject.reset
end
# Run test
#
# @return [true]
# returns true when mutant was killed
#
# @return [false]
# returns false otherwise
#
# @api private
#
abstract :run
end
end

View file

@ -0,0 +1,26 @@
require 'spec_helper'
describe Mutant::Runner,'.run' do
subject { class_under_test.run(mutation_subject,mutant) }
let(:mutation_subject) { mock('Subject', :insert => nil, :reset => nil) }
let(:mutant) { mock('Mutant') }
let(:class_under_test) do
Class.new(described_class) do
define_method(:run) {}
end
end
it { should be_kind_of(class_under_test) }
it 'should insert mutation' do
mutation_subject.should_receive(:insert).with(mutant).and_return(mutation_subject)
subject
end
it 'should reset mutation' do
mutation_subject.should_receive(:reset).and_return(mutation_subject)
subject
end
end

View file

@ -0,0 +1,34 @@
require 'spec_helper'
describe Mutant::Runner,'#killed?' do
subject { object.killed? }
let(:object) { class_under_test.run(mutation_subject,mutant) }
let(:mutation_subject) { mock('Subject', :insert => nil, :reset => nil) }
let(:mutant) { mock('Mutant') }
let(:class_under_test) do
kill_state = self.kill_state
Class.new(described_class) do
define_method :run do
kill_state
end
end
end
context 'when mutant was killed' do
let(:kill_state) { true }
it_should_behave_like 'an idempotent method'
it { should be(true) }
end
context 'when mutant was NOT killed' do
let(:kill_state) { false }
it_should_behave_like 'an idempotent method'
it { should be(false) }
end
end

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe Mutant::Runner,'#mutant' do
subject { object.mutant }
let(:object) { class_under_test.run(mutation_subject, mutant) }
let(:mutation_subject) { mock('Subject', :insert => nil, :reset => nil) }
let(:mutant) { mock('Mutant') }
let(:class_under_test) do
Class.new(described_class) do
define_method(:run) {}
end
end
it_should_behave_like 'an idempotent method'
it { should be(mutant) }
end

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe Mutant::Runner,'#subject' do
subject { object.subject }
let(:object) { class_under_test.run(mutation_subject, mutant) }
let(:mutation_subject) { mock('Subject', :insert => nil, :reset => nil) }
let(:mutant) { mock('Mutant') }
let(:class_under_test) do
Class.new(described_class) do
define_method(:run) {}
end
end
it_should_behave_like 'an idempotent method'
it { should be(subject) }
end