1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/test/command/base_test.rb
Jonathan Hefner ddcfde2226 Populate ARGV with Rails::Command.invoke args
Follow-up to #38495.

Similar to #40994, but for all Rails commands.  Programmatic and CLI
invocations of Rails commands will still behave identically, and `ARGV`
will still be isolated between invocations.

Reverts #40994.
2021-04-03 10:12:52 -05:00

41 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require "abstract_unit"
require "rails/command"
require "rails/commands/generate/generate_command"
require "rails/commands/secrets/secrets_command"
require "rails/commands/db/system/change/change_command"
class Rails::Command::BaseTest < ActiveSupport::TestCase
test "printing commands" do
assert_equal %w(generate), Rails::Command::GenerateCommand.printing_commands
assert_equal %w(secrets:setup secrets:edit secrets:show), Rails::Command::SecretsCommand.printing_commands
assert_equal %w(db:system:change), Rails::Command::Db::System::ChangeCommand.printing_commands
end
test "ARGV is populated" do
class Rails::Command::ArgvCommand < Rails::Command::Base
def check_populated(*args)
raise "not populated" if ARGV.empty? || ARGV != args
end
end
assert_nothing_raised { Rails::Command.invoke("argv:check_populated", %w[foo bar]) }
end
test "ARGV is isolated" do
class Rails::Command::ArgvCommand < Rails::Command::Base
def check_isolated
ARGV << "isolate this"
end
end
original_argv = ARGV.dup
ARGV.clear
Rails::Command.invoke("argv:check_isolated")
assert_empty ARGV
ensure
ARGV.replace(original_argv)
end
end