2014-08-10 17:04:05 -04:00
|
|
|
RSpec.shared_examples_for 'an invalid cli run' do
|
2014-07-03 17:16:12 -04:00
|
|
|
it 'raises error' do
|
|
|
|
expect do
|
|
|
|
subject
|
|
|
|
end.to raise_error(Mutant::CLI::Error, expected_message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-10 17:04:05 -04:00
|
|
|
RSpec.shared_examples_for 'a cli parser' do
|
2014-07-03 17:16:12 -04:00
|
|
|
it { expect(subject.config.integration).to eql(expected_integration) }
|
|
|
|
it { expect(subject.config.reporter).to eql(expected_reporter) }
|
|
|
|
it { expect(subject.config.matcher_config).to eql(expected_matcher_config) }
|
|
|
|
end
|
|
|
|
|
2014-08-10 17:04:05 -04:00
|
|
|
RSpec.describe Mutant::CLI do
|
2014-07-06 18:30:39 -04:00
|
|
|
let(:object) { described_class }
|
|
|
|
|
|
|
|
describe '.run' do
|
|
|
|
subject { object.run(arguments) }
|
|
|
|
|
|
|
|
let(:arguments) { double('arguments') }
|
|
|
|
|
|
|
|
let(:report) { double('Report', success?: report_success) }
|
|
|
|
let(:config) { double('Config') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
expect(Mutant::CLI).to receive(:call).with(arguments).and_return(config)
|
|
|
|
expect(Mutant::Env).to receive(:call).with(config).and_return(report)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when report signalls success' do
|
|
|
|
let(:report_success) { true }
|
|
|
|
|
|
|
|
it 'exits failure' do
|
|
|
|
expect(subject).to be(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-07 12:00:31 -04:00
|
|
|
context 'when report signals error' do
|
2014-07-06 18:30:39 -04:00
|
|
|
let(:report_success) { false }
|
|
|
|
|
|
|
|
it 'exits failure' do
|
|
|
|
expect(subject).to be(1)
|
|
|
|
end
|
2014-07-06 18:33:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when execution raises an Mutant::CLI::Error' do
|
|
|
|
let(:exception) { Mutant::CLI::Error.new('test-error') }
|
|
|
|
let(:report_success) { nil }
|
|
|
|
|
|
|
|
before do
|
|
|
|
expect(report).to receive(:success?).and_raise(exception)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exits failure' do
|
|
|
|
expect($stderr).to receive(:puts).with('test-error')
|
|
|
|
expect(subject).to be(1)
|
|
|
|
end
|
2014-07-06 18:30:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
describe '.new' do
|
|
|
|
let(:object) { described_class }
|
|
|
|
|
|
|
|
subject { object.new(arguments) }
|
|
|
|
|
|
|
|
# Defaults
|
2014-08-10 18:09:29 -04:00
|
|
|
let(:expected_filter) { Morpher.evaluator(s(:true)) }
|
|
|
|
let(:expected_integration) { Mutant::Integration::Null.new }
|
|
|
|
let(:expected_reporter) { Mutant::Config::DEFAULT.reporter }
|
|
|
|
let(:expected_matcher_config) { default_matcher_config }
|
2014-07-03 17:16:12 -04:00
|
|
|
|
|
|
|
let(:default_matcher_config) do
|
|
|
|
Mutant::Matcher::Config::DEFAULT
|
|
|
|
.update(match_expressions: expressions.map(&Mutant::Expression.method(:parse)))
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:flags) { [] }
|
|
|
|
let(:expressions) { %w[TestApp*] }
|
|
|
|
|
|
|
|
let(:arguments) { flags + expressions }
|
|
|
|
|
|
|
|
context 'with unknown flag' do
|
|
|
|
let(:flags) { %w[--invalid] }
|
|
|
|
|
|
|
|
let(:expected_message) { 'invalid option: --invalid' }
|
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unknown option' do
|
|
|
|
let(:flags) { %w[--invalid Foo] }
|
|
|
|
|
|
|
|
let(:expected_message) { 'invalid option: --invalid' }
|
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without expressions' do
|
|
|
|
let(:expressions) { [] }
|
|
|
|
|
|
|
|
let(:expected_message) { 'No expressions given' }
|
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with code filter and missing argument' do
|
|
|
|
let(:arguments) { %w[--code] }
|
|
|
|
let(:expected_message) { 'missing argument: --code' }
|
|
|
|
|
|
|
|
it_should_behave_like 'an invalid cli run'
|
|
|
|
end
|
|
|
|
|
2014-07-06 11:00:37 -04:00
|
|
|
context 'with include help flag' do
|
|
|
|
let(:flags) { %w[--help] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
expect($stdout).to receive(:puts).with(expected_message)
|
|
|
|
expect(Kernel).to receive(:exit).with(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
let(:expected_message) do
|
|
|
|
strip_indent(<<-MESSAGE)
|
|
|
|
usage: mutant [options] MATCH_EXPRESSION ...
|
|
|
|
Environment:
|
|
|
|
--zombie Run mutant zombified
|
|
|
|
-I, --include DIRECTORY Add DIRECTORY to $LOAD_PATH
|
|
|
|
-r, --require NAME Require file with NAME
|
2014-09-24 15:16:39 -04:00
|
|
|
-j, --jobs NUMBER Number of kill jobs. Defaults to number of processors.
|
2014-07-06 11:00:37 -04:00
|
|
|
|
|
|
|
Options:
|
|
|
|
--score COVERAGE Fail unless COVERAGE is not reached exactly
|
|
|
|
--use STRATEGY Use STRATEGY for killing mutations
|
|
|
|
--ignore-subject PATTERN Ignore subjects that match PATTERN
|
|
|
|
--code CODE Scope execution to subjects with CODE
|
|
|
|
--fail-fast Fail fast
|
|
|
|
--version Print mutants version
|
|
|
|
-d, --debug Enable debugging output
|
|
|
|
-h, --help Show this message
|
|
|
|
MESSAGE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
context 'with include flag' do
|
|
|
|
let(:flags) { %w[--include foo] }
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'configures includes' do
|
|
|
|
expect(subject.config.includes).to eql(%w[foo])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-06 11:00:37 -04:00
|
|
|
context 'with use flag' do
|
|
|
|
let(:flags) { %w[--use rspec] }
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
2014-08-06 11:30:06 -04:00
|
|
|
let(:expected_integration) { Mutant::Integration::Rspec.build }
|
2014-07-06 11:00:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with version flag' do
|
|
|
|
let(:flags) { %w[--version] }
|
|
|
|
|
|
|
|
before do
|
|
|
|
expect(Kernel).to receive(:exit).with(0)
|
|
|
|
expect($stdout).to receive(:puts).with("mutant-#{Mutant::VERSION}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
end
|
|
|
|
|
2014-07-17 09:59:25 -04:00
|
|
|
context 'with jobs flag' do
|
|
|
|
let(:flags) { %w[--jobs 0] }
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'configures expected coverage' do
|
2014-09-24 15:16:39 -04:00
|
|
|
expect(subject.config.jobs).to eql(0)
|
2014-07-17 09:59:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-06 11:00:37 -04:00
|
|
|
context 'with score flag' do
|
|
|
|
let(:flags) { %w[--score 99.5] }
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'configures expected coverage' do
|
|
|
|
expect(subject.config.expected_coverage).to eql(99.5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
context 'with require flag' do
|
|
|
|
let(:flags) { %w[--require foo] }
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'configures requires' do
|
|
|
|
expect(subject.config.requires).to eql(%w[foo])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-06 11:00:37 -04:00
|
|
|
context 'with subject-ignore flag' do
|
|
|
|
let(:flags) { %w[--ignore-subject Foo::Bar] }
|
|
|
|
|
|
|
|
let(:expected_matcher_config) do
|
|
|
|
default_matcher_config.update(subject_ignores: [Mutant::Expression.parse('Foo::Bar')])
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with fail-fast flag' do
|
|
|
|
let(:flags) { %w[--fail-fast] }
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'sets the fail fast option' do
|
|
|
|
expect(subject.config.fail_fast).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-03 17:16:12 -04:00
|
|
|
context 'with debug flag' do
|
|
|
|
let(:flags) { %w[--debug] }
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'sets the debug option' do
|
|
|
|
expect(subject.config.debug).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with zombie flag' do
|
|
|
|
let(:flags) { %w[--zombie] }
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
|
|
|
|
it 'sets the zombie option' do
|
|
|
|
expect(subject.config.zombie).to be(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with subject code filter' do
|
|
|
|
let(:flags) { %w[--code faa --code bbb] }
|
|
|
|
|
|
|
|
let(:expected_matcher_config) do
|
|
|
|
default_matcher_config.update(subject_selects: [[:code, 'faa'], [:code, 'bbb']])
|
|
|
|
end
|
|
|
|
|
|
|
|
it_should_behave_like 'a cli parser'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|