Skip to content

Commit

Permalink
(PDK-1442) Add basic interactive pdk bundle test
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Dec 9, 2019
1 parent 19f5eea commit 07e7835
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/acceptance/bundle_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
require 'spec_helper_acceptance'
require 'open3'

class IO
def expects(expected)
combined_output = ''

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

next unless (r = rs[0])

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

if expected.match?(combined_output) && !r.ready?
yield combined_output
break
end
end
rescue EOFError
nil
end
end

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

context 'when running an interactive command' do
it 'works interactively' do
command = 'pdk bundle exec irb -f --echo --prompt simple'
prompt = %r{>> \Z}m
exit_command = "exit\n"

Open3.popen2e(command) do |stdin, stdouterr, _|
stdouterr.expects(prompt) { |_| stdin.syswrite "require 'date'\n" }
stdouterr.expects(prompt) { |_| stdin.syswrite "Date.today.year\n" }
stdouterr.expects(prompt) do |output|
expect(output).to match(%r{=> #{Date.today.year}}m)
stdin.syswrite exit_command
end
end
end
end

context 'when running in a subdirectory of the module root' do
before(:all) do
Dir.chdir('manifests')
Expand Down

0 comments on commit 07e7835

Please sign in to comment.