Skip to content

Commit

Permalink
Fix rake test loader swallowing useful error information
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Nov 11, 2020
1 parent a7ecd32 commit eef4f7e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
31 changes: 15 additions & 16 deletions lib/rake/rake_test_loader.rb
Expand Up @@ -3,24 +3,23 @@

# Load the test files from the command line.
argv = ARGV.select do |argument|
begin
case argument
when /^-/ then
argument
when /\*/ then
FileList[argument].to_a.each do |file|
require File.expand_path file
end
case argument
when /^-/ then
argument
when /\*/ then
FileList[argument].to_a.each do |file|
require File.expand_path file
end

false
else
require File.expand_path argument
false
else
path = File.expand_path argument

false
end
rescue LoadError => e
raise unless e.path
abort "\nFile does not exist: #{e.path}\n\n"
abort "\nFile does not exist: #{path}\n\n" unless File.exist?(path)

require path

false
end
end

Expand Down
16 changes: 15 additions & 1 deletion test/test_rake_rake_test_loader.rb
Expand Up @@ -24,7 +24,7 @@ def test_pattern
$:.replace orig_loaded_features
end

def test_load_error_from_require
def test_load_error_from_missing_test_file
out, err = capture_io do
ARGV.replace %w[no_such_test_file.rb]

Expand All @@ -45,6 +45,20 @@ def test_load_error_from_require
assert_match expected, err
end

def test_load_error_raised_implicitly
File.write("error_test.rb", "require 'superkalifragilisticoespialidoso'")
out, err = capture_io do
ARGV.replace %w[error_test.rb]

exc = assert_raises(LoadError) do
load @loader
end
assert_equal "cannot load such file -- superkalifragilisticoespialidoso", exc.message
end
assert_empty out
assert_empty err
end

def test_load_error_raised_explicitly
File.write("error_test.rb", "raise LoadError, 'explicitly raised'")
out, err = capture_io do
Expand Down

0 comments on commit eef4f7e

Please sign in to comment.