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

Provide a better error message if a user mistypes the name of script with runner

Add tests for detecting bad options for runner
This commit is contained in:
Stephen Blackstone 2016-01-05 22:53:38 -05:00
parent 53954aa476
commit 02d2d3cf69
2 changed files with 17 additions and 1 deletions

View file

@ -58,5 +58,11 @@ elsif File.exist?(code_or_file)
$0 = code_or_file $0 = code_or_file
Kernel.load code_or_file Kernel.load code_or_file
else 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 end

View file

@ -74,6 +74,16 @@ module ApplicationTests
assert_match "development", Dir.chdir(app_path) { `bin/rails runner "puts Rails.env"` } assert_match "development", Dir.chdir(app_path) { `bin/rails runner "puts Rails.env"` }
end 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 def test_environment_with_rails_env
with_rails_env "production" do with_rails_env "production" do
assert_match "production", Dir.chdir(app_path) { `bin/rails runner "puts Rails.env"` } assert_match "production", Dir.chdir(app_path) { `bin/rails runner "puts Rails.env"` }