2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-14 00:54:59 -05:00
|
|
|
require "abstract_unit"
|
2017-07-25 02:01:33 -04:00
|
|
|
require "console_helpers"
|
2016-12-14 00:54:59 -05:00
|
|
|
|
|
|
|
class Rails::Engine::CommandsTest < ActiveSupport::TestCase
|
2017-07-25 02:01:33 -04:00
|
|
|
include ConsoleHelpers
|
|
|
|
|
2016-12-14 00:54:59 -05:00
|
|
|
def setup
|
|
|
|
@destination_root = Dir.mktmpdir("bukkits")
|
|
|
|
Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --mountable` }
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
FileUtils.rm_rf(@destination_root)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_help_command_work_inside_engine
|
|
|
|
output = capture(:stderr) do
|
|
|
|
Dir.chdir(plugin_path) { `bin/rails --help` }
|
|
|
|
end
|
|
|
|
assert_no_match "NameError", output
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_runner_command_work_inside_engine
|
|
|
|
output = capture(:stdout) do
|
|
|
|
Dir.chdir(plugin_path) { system("bin/rails runner 'puts Rails.env'") }
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "test", output.strip
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_console_command_work_inside_engine
|
|
|
|
skip "PTY unavailable" unless available_pty?
|
|
|
|
|
2018-09-10 16:29:43 -04:00
|
|
|
primary, replica = PTY.open
|
|
|
|
spawn_command("console", replica)
|
|
|
|
assert_output(">", primary)
|
2016-12-14 00:54:59 -05:00
|
|
|
ensure
|
|
|
|
master.puts "quit"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_dbconsole_command_work_inside_engine
|
|
|
|
skip "PTY unavailable" unless available_pty?
|
|
|
|
|
2018-09-10 16:29:43 -04:00
|
|
|
primary, replica = PTY.open
|
|
|
|
spawn_command("dbconsole", replica)
|
|
|
|
assert_output("sqlite>", primary)
|
2016-12-14 00:54:59 -05:00
|
|
|
ensure
|
|
|
|
master.puts ".exit"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_server_command_work_inside_engine
|
|
|
|
skip "PTY unavailable" unless available_pty?
|
|
|
|
|
2018-09-10 16:29:43 -04:00
|
|
|
primary, replica = PTY.open
|
|
|
|
pid = spawn_command("server", replica)
|
|
|
|
assert_output("Listening on", primary)
|
2016-12-14 00:54:59 -05:00
|
|
|
ensure
|
|
|
|
kill(pid)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def plugin_path
|
|
|
|
"#{@destination_root}/bukkits"
|
|
|
|
end
|
|
|
|
|
|
|
|
def spawn_command(command, fd)
|
|
|
|
Process.spawn(
|
|
|
|
"#{plugin_path}/bin/rails #{command}",
|
|
|
|
in: fd, out: fd, err: fd
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def kill(pid)
|
|
|
|
Process.kill("TERM", pid)
|
|
|
|
Process.wait(pid)
|
|
|
|
rescue Errno::ESRCH
|
|
|
|
end
|
|
|
|
end
|