Add specs for all CLI flags
This commit is contained in:
parent
89ea14b5a1
commit
eb5c203d74
2 changed files with 84 additions and 7 deletions
|
@ -66,7 +66,7 @@ module Mutant
|
||||||
#
|
#
|
||||||
def parse(arguments)
|
def parse(arguments)
|
||||||
opts = OptionParser.new do |builder|
|
opts = OptionParser.new do |builder|
|
||||||
builder.banner = 'usage: mutant STRATEGY [options] PATTERN ...'
|
builder.banner = 'usage: mutant [options] MATCH_EXPRESSION ...'
|
||||||
%w[add_environment_options add_mutation_options add_filter_options add_debug_options].each do |name|
|
%w[add_environment_options add_mutation_options add_filter_options add_debug_options].each do |name|
|
||||||
send(name, builder)
|
send(name, builder)
|
||||||
end
|
end
|
||||||
|
@ -125,9 +125,6 @@ module Mutant
|
||||||
def setup_integration(name)
|
def setup_integration(name)
|
||||||
require "mutant/integration/#{name}"
|
require "mutant/integration/#{name}"
|
||||||
update(integration: Integration.lookup(name).new)
|
update(integration: Integration.lookup(name).new)
|
||||||
rescue LoadError
|
|
||||||
$stderr.puts("Cannot load plugin: #{name.inspect}")
|
|
||||||
raise
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add options
|
# Add options
|
||||||
|
@ -177,12 +174,12 @@ module Mutant
|
||||||
update(fail_fast: true)
|
update(fail_fast: true)
|
||||||
end.on('--version', 'Print mutants version') do
|
end.on('--version', 'Print mutants version') do
|
||||||
puts("mutant-#{Mutant::VERSION}")
|
puts("mutant-#{Mutant::VERSION}")
|
||||||
Kernel.exit(0)
|
Kernel.exit(EXIT_SUCCESS)
|
||||||
end.on('-d', '--debug', 'Enable debugging output') do
|
end.on('-d', '--debug', 'Enable debugging output') do
|
||||||
update(debug: true)
|
update(debug: true)
|
||||||
end.on_tail('-h', '--help', 'Show this message') do
|
end.on_tail('-h', '--help', 'Show this message') do
|
||||||
puts(opts)
|
puts(opts.to_s)
|
||||||
exit
|
Kernel.exit(EXIT_SUCCESS)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,37 @@ describe Mutant::CLI do
|
||||||
it_should_behave_like 'an invalid cli run'
|
it_should_behave_like 'an invalid cli run'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
context 'with include flag' do
|
context 'with include flag' do
|
||||||
let(:flags) { %w[--include foo] }
|
let(:flags) { %w[--include foo] }
|
||||||
|
|
||||||
|
@ -79,6 +110,35 @@ describe Mutant::CLI do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with use flag' do
|
||||||
|
let(:flags) { %w[--use rspec] }
|
||||||
|
|
||||||
|
it_should_behave_like 'a cli parser'
|
||||||
|
|
||||||
|
let(:expected_integration) { Mutant::Integration::Rspec2.new }
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
context 'with require flag' do
|
context 'with require flag' do
|
||||||
let(:flags) { %w[--require foo] }
|
let(:flags) { %w[--require foo] }
|
||||||
|
|
||||||
|
@ -89,6 +149,26 @@ describe Mutant::CLI do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
context 'with debug flag' do
|
context 'with debug flag' do
|
||||||
let(:flags) { %w[--debug] }
|
let(:flags) { %w[--debug] }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue