From b6de7fad916e1477ca2c6adaf362ccd60575383f Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Wed, 1 Aug 2012 19:05:34 +0200 Subject: [PATCH] Add abstract (test) runner --- lib/mutant.rb | 1 + lib/mutant/runner.rb | 80 +++++++++++++++++++ .../mutant/runner/class_methods/run_spec.rb | 26 ++++++ spec/unit/mutant/runner/killed_ques_spec.rb | 34 ++++++++ spec/unit/mutant/runner/mutant_spec.rb | 19 +++++ spec/unit/mutant/runner/subject_spec.rb | 19 +++++ 6 files changed, 179 insertions(+) create mode 100644 lib/mutant/runner.rb create mode 100644 spec/unit/mutant/runner/class_methods/run_spec.rb create mode 100644 spec/unit/mutant/runner/killed_ques_spec.rb create mode 100644 spec/unit/mutant/runner/mutant_spec.rb create mode 100644 spec/unit/mutant/runner/subject_spec.rb diff --git a/lib/mutant.rb b/lib/mutant.rb index 44ec6481..291bcbc4 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -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' diff --git a/lib/mutant/runner.rb b/lib/mutant/runner.rb new file mode 100644 index 00000000..161a917e --- /dev/null +++ b/lib/mutant/runner.rb @@ -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 diff --git a/spec/unit/mutant/runner/class_methods/run_spec.rb b/spec/unit/mutant/runner/class_methods/run_spec.rb new file mode 100644 index 00000000..4948fb42 --- /dev/null +++ b/spec/unit/mutant/runner/class_methods/run_spec.rb @@ -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 diff --git a/spec/unit/mutant/runner/killed_ques_spec.rb b/spec/unit/mutant/runner/killed_ques_spec.rb new file mode 100644 index 00000000..dcf381c5 --- /dev/null +++ b/spec/unit/mutant/runner/killed_ques_spec.rb @@ -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 diff --git a/spec/unit/mutant/runner/mutant_spec.rb b/spec/unit/mutant/runner/mutant_spec.rb new file mode 100644 index 00000000..a85788a7 --- /dev/null +++ b/spec/unit/mutant/runner/mutant_spec.rb @@ -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 diff --git a/spec/unit/mutant/runner/subject_spec.rb b/spec/unit/mutant/runner/subject_spec.rb new file mode 100644 index 00000000..0b847db7 --- /dev/null +++ b/spec/unit/mutant/runner/subject_spec.rb @@ -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