Skip to content

Commit

Permalink
graphql-cli: update test to drop expect dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
cho-m committed Dec 21, 2024
1 parent fda1e3c commit 56c899f
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions Formula/g/graphql-cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 56c899f

Please sign in to comment.