Add initial rspec2 runner

* Needs integration spec!
This commit is contained in:
Markus Schirp 2012-08-09 19:46:15 +02:00
parent 5e7600e573
commit fda5d716a4
5 changed files with 138 additions and 1 deletions

View file

@ -36,7 +36,7 @@ end
require 'mutant/random'
require 'mutant/runner'
#require 'mutant/runner/rspec'
require 'mutant/runner/rspec'
require 'mutant/mutator'
require 'mutant/mutator/registry'
require 'mutant/mutator/literal'

View file

@ -0,0 +1,69 @@
module Mutant
class Runner
# Simple runner for rspec tests
class Rspec < Runner
# Return error stream
#
# @return [StringIO]
#
# @api private
#
def error_stream
StringIO.new
end
# Return output stream
#
# @return [StringIO]
#
# @api private
#
def output_stream
StringIO.new
end
private
# Run rspec test
#
# @return [true]
# returns true when test is NOT successful and the mutant was killed
#
# @return [false]
# returns false otherwise
#
# @api private
#
def run
!RSpec::Core::Runner.run(command_line,error_stream,output_stream).zero?
end
# Return command line
#
# @return [Array]
#
# @api private
#
def command_line
%W(
--fail-fast
) + Dir[filename_pattern]
end
# Return rspec filename pattern
#
# @return [String]
#
# @api private
#
# TODO: Add an option or be clever and only run affected specs.
#
def filename_pattern
'spec/unit/**/*_spec.rb'
end
memoize :output_stream, :error_stream
end
end
end

View file

@ -0,0 +1,30 @@
require 'spec_helper'
describe Mutant::Runner::Rspec, '.run' do
subject { object.run(context, mutant) }
let(:context) { mock('Context') }
let(:mutant) { mock('Mutant') }
let(:object) { described_class }
before do
context.stub(:insert => context)
context.stub(:reset => context)
RSpec::Core::Runner.stub(:run => exit_status)
end
context 'when run exits zero' do
let(:exit_status) { 0 }
its(:killed?) { should be(false) }
it { should be_a(described_class) }
end
context 'when run exits nonzero' do
let(:exit_status) { 1 }
its(:killed?) { should be(true) }
it { should be_a(described_class) }
end
end

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe Mutant::Runner::Rspec,'#error_stream' do
subject { object.error_stream }
let(:object) { described_class.run(mutation_subject,mutant) }
let(:mutation_subject) { mock('Subject', :insert => nil,:reset => nil) }
let(:mutant) { mock('Mutant') }
before do
RSpec::Core::Runner.stub(:run => 1)
end
it_should_behave_like 'an idempotent method'
it { should be_kind_of(StringIO) }
its(:read) { should eql('') }
end

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe Mutant::Runner::Rspec,'#output_stream' do
subject { object.output_stream }
let(:object) { described_class.run(mutation_subject,mutant) }
let(:mutation_subject) { mock('Subject', :insert => nil,:reset => nil) }
let(:mutant) { mock('Mutant') }
before do
RSpec::Core::Runner.stub(:run => 1)
end
it_should_behave_like 'an idempotent method'
it { should be_kind_of(StringIO) }
its(:read) { should eql('') }
end