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

Merge pull request #24260 from y-yagi/show_error_message_when_error_raised_in_rails_runner

show error message when error raised in rails runner
This commit is contained in:
Kasper Timm Hansen 2016-08-07 17:19:33 +02:00 committed by GitHub
commit 33ec865e7b
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