Skip to content

Commit

Permalink
(fixup) try out my own cross-platform expect
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Nov 29, 2019
1 parent e6c7f06 commit 16e710d
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions spec/acceptance/bundle_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
require 'spec_helper_acceptance'
require 'pty'
require 'expect'
require 'open3'

class IO
def expect(expected)
combined_output = ''

loop do
rs, = IO.select([self], [], [], 10)

next unless (r = rs[0])

data = r.read_nonblock(1024)
combined_output << data

if expected.match?(combined_output)
yield combined_output
break
end
end
rescue EOFError
nil
end
end

describe 'pdk bundle' do
context 'in a new module' do
Expand All @@ -17,16 +38,16 @@
its(:stdout) { is_expected.to match(%r{## Environment}) }
end

context 'when running an interactive command', unless: Gem.win_platform? do
context 'when running an interactive command' do
it 'works interactively' do
command = 'pdk bundle exec pry --no-color --simple-prompt'
prompt = %r{>> }
prompt = %r{>> \Z}m
exit_command = '!!!'

PTY.spawn(command) do |stdout, stdin, _|
stdout.expect(prompt) { |_| stdin.puts "require 'date'" }
stdout.expect(prompt) { |_| stdin.puts 'Date.today.year' }
stdout.expect(prompt) do |output|
Open3.popen2e(command) do |stdin, stdouterr, _|
stdouterr.expect(prompt) { |_| stdin.puts "require 'date'" }
stdouterr.expect(prompt) { |_| stdin.puts 'Date.today.year' }
stdouterr.expect(prompt) do |output|
expect(output[0]).to match(%r{=> #{Date.today.year}}m)
stdin.puts exit_command
end
Expand Down

0 comments on commit 16e710d

Please sign in to comment.