Skip to content

Commit

Permalink
Added scenario for missing file error
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed Jun 26, 2009
1 parent 715bbbc commit 93ee686
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
4 changes: 3 additions & 1 deletion bin/reek
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions features/masking_smells.feature
Expand Up @@ -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
Expand Down
File renamed without changes.
21 changes: 5 additions & 16 deletions lib/reek/options.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
5 changes: 0 additions & 5 deletions spec/slow/script_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 93ee686

Please sign in to comment.