Add abstract (test) runner
This commit is contained in:
parent
87161f382d
commit
b6de7fad91
6 changed files with 179 additions and 0 deletions
|
@ -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
80
lib/mutant/runner.rb
Normal 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
|
26
spec/unit/mutant/runner/class_methods/run_spec.rb
Normal file
26
spec/unit/mutant/runner/class_methods/run_spec.rb
Normal 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
|
34
spec/unit/mutant/runner/killed_ques_spec.rb
Normal file
34
spec/unit/mutant/runner/killed_ques_spec.rb
Normal 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
|
19
spec/unit/mutant/runner/mutant_spec.rb
Normal file
19
spec/unit/mutant/runner/mutant_spec.rb
Normal 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
|
19
spec/unit/mutant/runner/subject_spec.rb
Normal file
19
spec/unit/mutant/runner/subject_spec.rb
Normal 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
|
Loading…
Reference in a new issue