From 56c899f3542710a3876de19a5d8a6dc2c4545845 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Sat, 21 Dec 2024 18:48:28 -0500 Subject: [PATCH] graphql-cli: update test to drop `expect` dependency --- Formula/g/graphql-cli.rb | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/Formula/g/graphql-cli.rb b/Formula/g/graphql-cli.rb index e8e0a953d3440..7723661e0542e 100644 --- a/Formula/g/graphql-cli.rb +++ b/Formula/g/graphql-cli.rb @@ -27,35 +27,26 @@ class GraphqlCli < Formula depends_on "node" - uses_from_macos "expect" => :test - def install system "npm", "install", *std_npm_args bin.install_symlink Dir["#{libexec}/bin/*"] end test do - (testpath/"test.exp").write <<~EOS - #!/usr/bin/env expect -f - set timeout -1 - spawn #{bin}/graphql init - - expect -exact "Select the best option for you" - send -- "1\r" - - expect -exact "? What is the name of the project?" - send -- "brew\r" - - expect -exact "? Choose a template to bootstrap" - send -- "1\r" - - expect eof - EOS - - system "expect", "-f", "test.exp" - - assert_predicate testpath/"brew", :exist? - assert_match "Graphback runtime template with Apollo Server and PostgreSQL", - File.read(testpath/"brew/package.json") + require "expect" + require "open3" + + Open3.popen2(bin/"graphql", "init") do |stdin, stdout, wait_thread| + stdout.expect "Select the best option for you" + stdin.write "1\n" + stdout.expect "? What is the name of the project?" + stdin.write "brew\n" + stdout.expect "? Choose a template to bootstrap" + stdin.write "1\n" + wait_thread.join + end + + assert_path_exists testpath/"brew" + assert_match "Graphback runtime template with Apollo Server and PostgreSQL", (testpath/"brew/package.json").read end end