From eb5c203d743597713ac72502a5832c5c2803f3f9 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 6 Jul 2014 15:00:37 +0000 Subject: [PATCH] Add specs for all CLI flags --- lib/mutant/cli.rb | 11 ++--- spec/unit/mutant/cli_spec.rb | 80 ++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 7 deletions(-) diff --git a/lib/mutant/cli.rb b/lib/mutant/cli.rb index f53508c8..fa8d34b0 100644 --- a/lib/mutant/cli.rb +++ b/lib/mutant/cli.rb @@ -66,7 +66,7 @@ module Mutant # def parse(arguments) 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| send(name, builder) end @@ -125,9 +125,6 @@ module Mutant def setup_integration(name) require "mutant/integration/#{name}" update(integration: Integration.lookup(name).new) - rescue LoadError - $stderr.puts("Cannot load plugin: #{name.inspect}") - raise end # Add options @@ -177,12 +174,12 @@ module Mutant update(fail_fast: true) end.on('--version', 'Print mutants version') do puts("mutant-#{Mutant::VERSION}") - Kernel.exit(0) + Kernel.exit(EXIT_SUCCESS) end.on('-d', '--debug', 'Enable debugging output') do update(debug: true) end.on_tail('-h', '--help', 'Show this message') do - puts(opts) - exit + puts(opts.to_s) + Kernel.exit(EXIT_SUCCESS) end end diff --git a/spec/unit/mutant/cli_spec.rb b/spec/unit/mutant/cli_spec.rb index b2eec244..e5932887 100644 --- a/spec/unit/mutant/cli_spec.rb +++ b/spec/unit/mutant/cli_spec.rb @@ -69,6 +69,37 @@ describe Mutant::CLI do it_should_behave_like 'an invalid cli run' 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 let(:flags) { %w[--include foo] } @@ -79,6 +110,35 @@ describe Mutant::CLI do 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 let(:flags) { %w[--require foo] } @@ -89,6 +149,26 @@ describe Mutant::CLI do 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 let(:flags) { %w[--debug] }