From bf71b6a57959f00e2b445037996c32ba45802351 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Mon, 21 Mar 2016 10:08:38 +0900 Subject: show error message when error raised in rails runner --- railties/lib/rails/commands/runner.rb | 4 +++- railties/test/application/runner_test.rb | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index f9c183ac86..1ec10a8a37 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -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 diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb index 84d90cc6d7..7e68a545e9 100644 --- a/railties/test/application/runner_test.rb +++ b/railties/test/application/runner_test.rb @@ -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 -- cgit v1.2.3