Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PDK-1442) Add basic interactive pdk bundle test #736

Merged
merged 1 commit into from
Dec 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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