1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

show error message when error raised in rails runner

This commit is contained in:
yuuji.yaginuma 2016-03-21 10:08:38 +09:00
parent d46d61e46e
commit bf71b6a579
2 changed files with 9 additions and 5 deletions

View file

@ -61,9 +61,11 @@ elsif File.exist?(code_or_file)
else
begin
eval(code_or_file, binding, __FILE__, __LINE__)
rescue SyntaxError, NameError
rescue SyntaxError, NameError => e
$stderr.puts "Please specify a valid ruby command or the path of a script to run."
$stderr.puts "Run '#{command} -h' for help."
$stderr.puts
$stderr.puts e
exit 1
end
end

View file

@ -74,13 +74,15 @@ module ApplicationTests
end
def test_runner_detects_syntax_errors
Dir.chdir(app_path) { `bin/rails runner "puts 'hello world" 2>&1` }
refute $?.success?
output = Dir.chdir(app_path) { `bin/rails runner "puts 'hello world" 2>&1` }
assert_not $?.success?
assert_match 'unterminated string meets end of file', output
end
def test_runner_detects_bad_script_name
Dir.chdir(app_path) { `bin/rails runner "iuiqwiourowe" 2>&1` }
refute $?.success?
output = Dir.chdir(app_path) { `bin/rails runner "iuiqwiourowe" 2>&1` }
assert_not $?.success?
assert_match "undefined local variable or method `iuiqwiourowe' for main:Object", output
end
def test_environment_with_rails_env