aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorStephen Blackstone <sblackstone@gmail.com>2016-01-05 22:53:38 -0500
committerStephen Blackstone <sblackstone@gmail.com>2016-01-05 23:13:13 -0500
commit02d2d3cf699f2c8a1e078d5e5e72f76ec6706da6 (patch)
treedfaa2381c1c3bc15a3761c940775ebfc3ad03bbf /railties
parent53954aa4762f5c4d1b28af3d382a40fd3ec04229 (diff)
downloadrails-02d2d3cf699f2c8a1e078d5e5e72f76ec6706da6.tar.gz
rails-02d2d3cf699f2c8a1e078d5e5e72f76ec6706da6.tar.bz2
rails-02d2d3cf699f2c8a1e078d5e5e72f76ec6706da6.zip
Provide a better error message if a user mistypes the name of script with runner
Add tests for detecting bad options for runner
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/commands/runner.rb8
-rw-r--r--railties/test/application/runner_test.rb10
2 files changed, 17 insertions, 1 deletions
diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb
index 86bce9b2fe..babb197ba1 100644
--- a/railties/lib/rails/commands/runner.rb
+++ b/railties/lib/rails/commands/runner.rb
@@ -58,5 +58,11 @@ elsif File.exist?(code_or_file)
$0 = code_or_file
Kernel.load code_or_file
else
- eval(code_or_file, binding, __FILE__, __LINE__)
+ begin
+ eval(code_or_file, binding, __FILE__, __LINE__)
+ rescue SyntaxError,NameError => err
+ $stderr.puts "Please specify a valid ruby command or the path of a script to run."
+ $stderr.puts "Run '#{$0} -h' for help."
+ exit 1
+ end
end
diff --git a/railties/test/application/runner_test.rb b/railties/test/application/runner_test.rb
index 0c180339b4..9f15ce5e85 100644
--- a/railties/test/application/runner_test.rb
+++ b/railties/test/application/runner_test.rb
@@ -74,6 +74,16 @@ module ApplicationTests
assert_match "development", Dir.chdir(app_path) { `bin/rails runner "puts Rails.env"` }
end
+ def test_runner_detects_syntax_errors
+ Dir.chdir(app_path) { `bin/rails runner "puts 'hello world" 2>&1` }
+ refute $?.success?
+ end
+
+ def test_runner_detects_bad_script_name
+ Dir.chdir(app_path) { `bin/rails runner "iuiqwiourowe" 2>&1` }
+ refute $?.success?
+ end
+
def test_environment_with_rails_env
with_rails_env "production" do
assert_match "production", Dir.chdir(app_path) { `bin/rails runner "puts Rails.env"` }