From 97530771bfcf8d923b8adaa9ca887c3d432cd9c5 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Sun, 30 Nov 2014 23:22:21 +0000 Subject: [PATCH] Handle integration load errors with better message [fixes #269] --- lib/mutant/cli.rb | 2 ++ spec/unit/mutant/cli_spec.rb | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/mutant/cli.rb b/lib/mutant/cli.rb index 4b3eafb9..61be1b20 100644 --- a/lib/mutant/cli.rb +++ b/lib/mutant/cli.rb @@ -128,6 +128,8 @@ module Mutant def setup_integration(name) require "mutant/integration/#{name}" update(integration: Integration.lookup(name)) + rescue LoadError + fail Error, "Could not load integration #{name.inspect} (you may want to try installing the gem mutant-#{name})" end # Add options diff --git a/spec/unit/mutant/cli_spec.rb b/spec/unit/mutant/cli_spec.rb index 7dd2d09c..eb62e07d 100644 --- a/spec/unit/mutant/cli_spec.rb +++ b/spec/unit/mutant/cli_spec.rb @@ -155,11 +155,24 @@ Options: end context 'with use flag' do - let(:flags) { %w[--use rspec] } + context 'when integration exists' do + let(:flags) { %w[--use rspec] } - it_should_behave_like 'a cli parser' + it_should_behave_like 'a cli parser' - let(:expected_integration) { Mutant::Integration::Rspec.build } + let(:expected_integration) { Mutant::Integration::Rspec.build } + end + + context 'when integration does NOT exist' do + let(:flags) { %w[--use other] } + + it 'raises error' do + expect { subject }.to raise_error( + Mutant::CLI::Error, + 'Could not load integration "other" (you may want to try installing the gem mutant-other)' + ) + end + end end context 'with version flag' do