Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make LoadError from running tests more obvious #195

Merged
merged 4 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions lib/rake/rake_test_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

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

false
false
end
rescue LoadError => e
abort "\nFile does not exist: #{e.path}\n\n"
end
end

Expand Down
28 changes: 27 additions & 1 deletion test/test_rake_rake_test_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

class TestRakeRakeTestLoader < Rake::TestCase

def setup
super

@loader = File.join @rake_lib, 'rake/rake_test_loader.rb'
end

def test_pattern
orig_loaded_features = $:.dup
FileUtils.touch "foo.rb"
Expand All @@ -10,11 +16,31 @@ def test_pattern

ARGV.replace %w[foo.rb test_*.rb -v]

load File.join(@rake_lib, "rake/rake_test_loader.rb")
load @loader

assert_equal %w[-v], ARGV
ensure
$:.replace orig_loaded_features
end

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

assert_raises SystemExit do
load @loader
end
end

assert_empty out

no_such_path = File.join @tempdir, 'no_such_test_file'

expected =
/\A\n
File\ does\ not\ exist:\ #{no_such_path}(\.rb)? # JRuby is different
\n\n\Z/x

assert_match expected, err
end
end