Skip to content

Commit

Permalink
Merge pull request #155 from Ptico/master
Browse files Browse the repository at this point in the history
Add support for rspec-3 beta.
  • Loading branch information
mbj committed Mar 5, 2014
2 parents 4c90f5d + b453777 commit 58fd5fb
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ measurements
## BUNDLER
.bundle
Gemfile.lock
Gemfile.*.lock

## PROJECT::SPECIFIC
/vendor
2 changes: 1 addition & 1 deletion config/flay.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
threshold: 18
total_score: 811
total_score: 808
1 change: 1 addition & 0 deletions config/reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 17 additions & 2 deletions lib/mutant/rspec/killer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def run
return false
end

reporter = RSpec::Core::Reporter.new

example_groups.each do |group|
return true unless group.run(reporter)
end
Expand Down Expand Up @@ -90,6 +88,23 @@ def all_example_groups
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
16 changes: 15 additions & 1 deletion lib/mutant/rspec/strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ def example_groups
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
Expand All @@ -67,7 +81,7 @@ def world
#
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
Expand Down
2 changes: 1 addition & 1 deletion mutant-rspec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
62 changes: 40 additions & 22 deletions spec/integration/mutant/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,53 @@

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
end

let(:base_cmd) { 'bundle exec mutant -I lib --require test_app --use rspec' }
specify 'it allows to kill mutations' do
expect(Kernel.system("#{base_cmd} ::TestApp::Literal#string")).to be(true)
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 '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)
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

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)
context 'RSpec 2' do
let(:gemfile) { 'Gemfile.rspec2' }

it_behaves_like 'rspec integration'
end

specify 'fails when some mutations are not covered' do
cli = "#{base_cmd} ::TestApp::Literal"
expect(Kernel.system(cli)).to be(false)
context 'Rspec 3' do
let(:gemfile) { 'Gemfile.rspec3' }

it_behaves_like 'rspec integration'
end
end
6 changes: 3 additions & 3 deletions spec/unit/mutant/cli_new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
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
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/mutant/rspec/killer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
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

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
Expand Down
4 changes: 4 additions & 0 deletions test_app/Gemfile.rspec2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'rspec', '~> 2.14.1'
gem 'mutant', path: '../'
3 changes: 3 additions & 0 deletions test_app/Gemfile.rspec3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'
gem 'rspec', '~> 3.0.0.beta2'
gem 'mutant', path: '../'

0 comments on commit 58fd5fb

Please sign in to comment.