free_mutant/spec/integration/mutant/rspec_spec.rb
Markus Schirp 6df5811a87 Use RSpec as receiver for rspec DSL methods
* I dislike the global infection RSpec does. This commit is a first step
  to get a rid of it.
* Also remove the need for `require 'spec_helper` in each spec file with
  adjusting `.rspec`.
2014-08-10 21:04:07 +00:00

52 lines
1.4 KiB
Ruby

RSpec.describe 'rspec integration' do
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}") || fail('Bundle install failed!')
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
context 'RSpec 2' do
let(:gemfile) { 'Gemfile.rspec2' }
it_behaves_like 'rspec integration'
end
context 'RSpec 3' do
let(:gemfile) { 'Gemfile.rspec3' }
it_behaves_like 'rspec integration'
end
end