Merge pull request #45875 from tekin/rails-runner-spots-missing-files

Better rails runner output for missing files
This commit is contained in:
Eileen M. Uchitelle 2022-08-24 09:38:43 -04:00 committed by GitHub
commit 61733bde03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 4 deletions

@ -1,3 +1,7 @@
* Improve `rails runner` output when given a file path that doesn't exist.
*Tekin Suleyman*
* `config.allow_concurrency = false` now use a `Monitor` instead of a `Mutex`
This allows to enable `config.active_support.executor_around_test_case` even

@ -51,14 +51,24 @@ def perform(code_or_file = nil, *command_argv)
eval(code_or_file, TOPLEVEL_BINDING, __FILE__, __LINE__)
end
rescue SyntaxError, NameError => e
error "Please specify a valid ruby command or the path of a script to run."
error "Run '#{executable} -h' for help."
error ""
error e
if looks_like_a_file_path?(code_or_file)
error "The file #{code_or_file} could not be found, please check and try again."
error "Run '#{self.class.executable} -h' for help."
else
error "Please specify a valid ruby command or the path of a script to run."
error "Run '#{self.class.executable} -h' for help."
error ""
error e
end
exit 1
end
end
end
def looks_like_a_file_path?(code_or_file)
code_or_file.ends_with?(".rb")
end
end
end
end

@ -32,6 +32,13 @@ def test_rails_runner_with_file
OUTPUT
end
def test_rails_runner_with_file_path_that_does_not_exist
command_output = run_runner_command("no-file-here.rb", allow_failure: true)
assert_match(/The file no-file-here.rb could not be found/, command_output)
assert_equal 1, $?.exitstatus
end
def test_rails_runner_with_ruby_code
assert_equal <<~OUTPUT, run_runner_command('puts "Hello world"')
Hello world