summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-04 06:49:04 (GMT)
committerkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-04 06:49:04 (GMT)
commit2cc0461bfa6352b485a25cfbfad65ce538dd9609 (patch)
tree67f98f72a94d87396d09076078c4c9cd66accc25 /sample
parent411083a9a6fa2767657b5e69c776c5abc521e5cd (diff)
sample/pty/expect_sample.rb: Update sample
* Fix regexp capture scope bug. * Specify frozen_string_literal: true. * Use passive mode. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rw-r--r--sample/pty/expect_sample.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/sample/pty/expect_sample.rb b/sample/pty/expect_sample.rb
index 2f87f21..199d98b 100644
--- a/sample/pty/expect_sample.rb
+++ b/sample/pty/expect_sample.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
#
# sample program of expect.rb
#
@@ -23,8 +24,17 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
username = 'guest'
end
- r_f.expect(/^(Name).*: |(word):|> /) do
- w_f.puts($1 ? "ftp" : $2 ? "#{username}@" : "cd pub/ruby")
+ r_f.expect(/^Name.*: /) do
+ w_f.puts("ftp")
+ end
+ r_f.expect(/word:/) do
+ w_f.puts("#{username}@")
+ end
+ r_f.expect(/> /) do
+ w_f.puts("cd pub/ruby")
+ end
+ r_f.expect("> ") do
+ w_f.print "pass\n"
end
r_f.expect("> ") do
w_f.print "dir\n"