From 93ee686b79789736dbd26c7c32ef86e543eb07a2 Mon Sep 17 00:00:00 2001 From: Kevin Rutherford Date: Fri, 26 Jun 2009 21:32:07 +0100 Subject: [PATCH] Added scenario for missing file error --- bin/reek | 4 +++- features/masking_smells.feature | 9 ++++++++ ...correct_smells.feature => samples.feature} | 0 lib/reek/options.rb | 21 +++++-------------- spec/slow/script_spec.rb | 5 ----- 5 files changed, 17 insertions(+), 22 deletions(-) rename features/{correct_smells.feature => samples.feature} (100%) diff --git a/bin/reek b/bin/reek index f069f6ebd..83f9d360f 100755 --- a/bin/reek +++ b/bin/reek @@ -18,7 +18,9 @@ def reek(args) return 2 end return 0 - rescue RuntimeError => error + rescue SystemExit => ex + return ex.status + rescue Exception => error $stderr.puts "Error: #{error}" return 1 end diff --git a/features/masking_smells.feature b/features/masking_smells.feature index 5724a2316..dae42a015 100644 --- a/features/masking_smells.feature +++ b/features/masking_smells.feature @@ -28,6 +28,15 @@ Feature: Masking smells using config files """ + Scenario: missing source file is an error + When I run reek no_such_file.rb + Then it fails with exit status 1 + And it displays the error message: + """ + Error: No such file or directory - no_such_file.rb + + """ + Scenario: switch off one smell When I run reek spec/samples/masked/dirty.rb Then it fails with exit status 2 diff --git a/features/correct_smells.feature b/features/samples.feature similarity index 100% rename from features/correct_smells.feature rename to features/samples.feature diff --git a/lib/reek/options.rb b/lib/reek/options.rb index 079c391b6..e446e4937 100644 --- a/lib/reek/options.rb +++ b/lib/reek/options.rb @@ -42,15 +42,11 @@ def self.set_options(opts, config) end def self.parse(args) - begin - @@opts = parse_args(args) - if args.length > 0 - return Source.from_pathlist(args) - else - return Source.from_io($stdin, 'stdin') - end - rescue OptionParser::ParseError, SystemCallError => err - fatal_error(err) + @@opts = parse_args(args) + if args.length > 0 + return Source.from_pathlist(args) + else + return Source.from_io($stdin, 'stdin') end end @@ -81,12 +77,5 @@ def self.set_sort_option(config, opts) config[:format] = SMELL_SORT end end - - def self.fatal_error(err) # :nodoc: - puts "Error: #{err}" - puts "Use '-h' for help." - exit(1) - end - end end diff --git a/spec/slow/script_spec.rb b/spec/slow/script_spec.rb index 4d815277a..c8b608ab2 100644 --- a/spec/slow/script_spec.rb +++ b/spec/slow/script_spec.rb @@ -15,11 +15,6 @@ $?.exitstatus.should == 1 end - it 'should complain about missing file' do - `ruby -Ilib bin/reek nosuchfile.rb` - $?.exitstatus.should == 1 - end - it 'should return non-zero status on missing argument' do `ruby -Ilib bin/reek -f 2>/dev/null` $?.exitstatus.should == 1