Some of my Rails tests require parameters from command line. After Rails 6.1. ARGV has been (for whatever reason) cleared and not available in application.
Is there an alternative way to get parameters send to rails command?
Some of my Rails tests require parameters from command line. After Rails 6.1. ARGV has been (for whatever reason) cleared and not available in application.
Is there an alternative way to get parameters send to rails command?
Depending on what you're doing, you might be able to use Rake.application.top_level_tasks
. For rake
tasks, this is set by rake itself. But it may also be set for your use-case too.
For my use-case, I was able to see if migrations were running, by doing:
if File.basename($0) == "rake" && Rake.application.top_level_tasks == ["db:migrate"]
# DB Migration is runnning...
end
See: https://mcmap.net/q/176617/-how-do-i-detect-in-rails-if-i-am-running-a-rake-command
© 2022 - 2024 — McMap. All rights reserved.
ps -o "pid,command" | grep #{Process.pid}
. I.e. find the current process and look through the string output (includes the grep command too). – Skilken