How to get ARGV options on Rails 6.1

Viewed 40

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?

by TheR

1 Answers

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://stackoverflow.com/a/67287175/1852005

Related