Merge pull request #155 from Ptico/master

Add support for rspec-3 beta.
This commit is contained in:
Markus Schirp 2014-03-05 19:17:32 +00:00
commit 58fd5fb3ee
11 changed files with 89 additions and 33 deletions

1
.gitignore vendored
View file

@ -33,6 +33,7 @@ measurements
## BUNDLER
.bundle
Gemfile.lock
Gemfile.*.lock
## PROJECT::SPECIFIC
/vendor

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 811
total_score: 808

View file

@ -136,4 +136,5 @@ UtilityFunction:
- Mutant::Rspec::Strategy#configuration
- Mutant::Rspec::Strategy#options
- Mutant::Rspec::Strategy#world
- Mutant::Rspec::Strategy#rspec2
max_helper_calls: 0

View file

@ -32,8 +32,6 @@ module Mutant
return false
end
reporter = RSpec::Core::Reporter.new
example_groups.each do |group|
return true unless group.run(reporter)
end
@ -90,6 +88,23 @@ module Mutant
strategy.example_groups
end
# Choose and memoize RSpec reporter
#
# @return [RSpec::Core::Reporter]
#
# @api private
#
def reporter
reporter_class = RSpec::Core::Reporter
if strategy.rspec2?
reporter_class.new
else
reporter_class.new(strategy.configuration)
end
end
memoize :reporter, freezer: :noop
end # Killer
end # Rspec
end # Mutant

View file

@ -46,6 +46,20 @@ module Mutant
world.example_groups
end
# Detect RSpec 2
#
# @return [true]
# when RSpec 2
#
# @return [false]
# otherwise
#
# @api private
#
def rspec2?
RSpec::Core::Version::STRING.start_with?('2.')
end
private
# Return world
@ -67,7 +81,7 @@ module Mutant
#
def options
options = RSpec::Core::ConfigurationOptions.new(%w(--fail-fast spec))
options.parse_options
options.parse_options if rspec2?
options
end
memoize :options, freezer: :noop

View file

@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
gem.extra_rdoc_files = %w[TODO LICENSE]
gem.add_runtime_dependency('mutant', "~> #{gem.version}")
gem.add_runtime_dependency('rspec-core', '~> 2.14.1')
gem.add_runtime_dependency('rspec-core', '>= 2.14.1', '<= 3.0.0.beta2')
gem.add_development_dependency('bundler', '~> 1.3', '>= 1.3.5')
end

View file

@ -4,35 +4,53 @@ require 'spec_helper'
describe Mutant, 'rspec integration' do
around do |example|
Dir.chdir(TestApp.root) do
example.run
let(:base_cmd) { "bundle exec mutant -I lib --require test_app --use rspec" }
shared_examples_for 'rspec integration' do
around do |example|
Bundler.with_clean_env do
Dir.chdir(TestApp.root) do
Kernel.system("bundle install --gemfile=#{gemfile}")
ENV['BUNDLE_GEMFILE'] = gemfile
example.run
end
end
end
specify 'it allows to kill mutations' do
expect(Kernel.system("#{base_cmd} ::TestApp::Literal#string")).to be(true)
end
specify 'it allows to exclude mutations' do
cli = <<-CMD.split("\n").join(' ')
#{base_cmd}
::TestApp::Literal#string
::TestApp::Literal#uncovered_string
--ignore-subject ::TestApp::Literal#uncovered_string
CMD
expect(Kernel.system(cli)).to be(true)
end
specify 'fails to kill mutations when they are not covered' do
cli = "#{base_cmd} ::TestApp::Literal#uncovered_string"
expect(Kernel.system(cli)).to be(false)
end
specify 'fails when some mutations are not covered' do
cli = "#{base_cmd} ::TestApp::Literal"
expect(Kernel.system(cli)).to be(false)
end
end
let(:base_cmd) { 'bundle exec mutant -I lib --require test_app --use rspec' }
context 'RSpec 2' do
let(:gemfile) { 'Gemfile.rspec2' }
specify 'it allows to kill mutations' do
expect(Kernel.system("#{base_cmd} ::TestApp::Literal#string")).to be(true)
it_behaves_like 'rspec integration'
end
specify 'it allows to exclude mutations' do
cli = <<-CMD.split("\n").join(' ')
#{base_cmd}
::TestApp::Literal#string
::TestApp::Literal#uncovered_string
--ignore-subject ::TestApp::Literal#uncovered_string
CMD
expect(Kernel.system(cli)).to be(true)
end
context 'Rspec 3' do
let(:gemfile) { 'Gemfile.rspec3' }
specify 'fails to kill mutations when they are not covered' do
cli = "#{base_cmd} ::TestApp::Literal#uncovered_string"
expect(Kernel.system(cli)).to be(false)
end
specify 'fails when some mutations are not covered' do
cli = "#{base_cmd} ::TestApp::Literal"
expect(Kernel.system(cli)).to be(false)
it_behaves_like 'rspec integration'
end
end

View file

@ -13,9 +13,9 @@ end
shared_examples_for 'a cli parser' do
subject { cli.config }
its(:strategy) { should eql(expected_strategy) }
its(:reporter) { should eql(expected_reporter) }
its(:matcher) { should eql(expected_matcher) }
it { expect(subject.strategy).to eql(expected_strategy) }
it { expect(subject.reporter).to eql(expected_reporter) }
it { expect(subject.matcher).to eql(expected_matcher) }
end
describe Mutant::CLI, '.new' do

View file

@ -42,7 +42,7 @@ describe Mutant::Rspec::Killer, '.new' do
context 'when run exits zero' do
let(:exit_status) { 0 }
its(:killed?) { should be(false) }
it { expect(subject.killed?).to be(false) }
it { should be_a(described_class) }
end
@ -50,7 +50,7 @@ describe Mutant::Rspec::Killer, '.new' do
context 'when run exits nonzero' do
let(:exit_status) { 1 }
its(:killed?) { should be(true) }
it { expect(subject.killed?).to be(true) }
it { should be_a(described_class) }
end

4
test_app/Gemfile.rspec2 Normal file
View file

@ -0,0 +1,4 @@
source 'https://rubygems.org'
gem 'rspec', '~> 2.14.1'
gem 'mutant', path: '../'

3
test_app/Gemfile.rspec3 Normal file
View file

@ -0,0 +1,3 @@
source 'https://rubygems.org'
gem 'rspec', '~> 3.0.0.beta2'
gem 'mutant', path: '../'