ruby_expect 1.6.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +202 -0
- data/NOTICE +13 -0
- data/README.md +152 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/ruby_expect.rb +2 -0
- data/lib/ruby_expect/errors.rb +7 -0
- data/lib/ruby_expect/expect.rb +39 -10
- data/lib/ruby_expect/version.rb +3 -0
- data/ruby_expect.gemspec +40 -0
- metadata +68 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d69e96f0db84d1a8c74e6bd146bb659b5f45d786
|
|
4
|
+
data.tar.gz: 1a3d0154c09b4948886628bfc832c145d8b05b3f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b0216cdaa2821ee2bc1e59893fb94b1b176562b1c28b9e2655aae502e400e37bd72a86211ef276cacd22578da4b4aa2f6bb6715c349491aaa43f26694b1c843b
|
|
7
|
+
data.tar.gz: 6e0176f523f14ee9ca115a16f9f6434789b96659925982ea7ccf7a4de89ac3d16db1ac3e1debd928320021f7817ee344a56d12bf785fd03ac6a5c3990cd2339f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2012 Andrew Bates
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/NOTICE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2012 Andrew Bates
|
|
2
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
you may not use this file except in compliance with the License.
|
|
4
|
+
You may obtain a copy of the License at
|
|
5
|
+
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
|
|
8
|
+
Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
See the License for the specific language governing permissions and
|
|
12
|
+
limitations under the License.
|
|
13
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
RubyExpect
|
|
2
|
+
==========
|
|
3
|
+
|
|
4
|
+
Introduction
|
|
5
|
+
------------
|
|
6
|
+
|
|
7
|
+
This is a simple expect API written in pure ruby. Part of this library includes a simple procedure DSL
|
|
8
|
+
for creating sequences of expect/send behavior. For more information on the motivation and design of
|
|
9
|
+
this gem, please see: http://www.andrewbates.co/ruby-expect/
|
|
10
|
+
|
|
11
|
+
Examples
|
|
12
|
+
--------
|
|
13
|
+
|
|
14
|
+
### SSH to a host and run a command
|
|
15
|
+
This example will use the system ssh binary and connect to a host. Upon connecting it will
|
|
16
|
+
execute a command and wait for the response then exit. The response from the command will be
|
|
17
|
+
parsed and printed to the screen.
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
#!/usr/bin/ruby
|
|
21
|
+
|
|
22
|
+
require 'ruby_expect'
|
|
23
|
+
|
|
24
|
+
username = 'username'
|
|
25
|
+
password = 'password'
|
|
26
|
+
hostname = 'hostname'
|
|
27
|
+
|
|
28
|
+
exp = RubyExpect::Expect.spawn("/usr/bin/ssh #{username}@#{hostname}")
|
|
29
|
+
|
|
30
|
+
exp.procedure do
|
|
31
|
+
retval = 0
|
|
32
|
+
while (retval != 2)
|
|
33
|
+
retval = any do
|
|
34
|
+
expect /Are you sure you want to continue connecting \(yes\/no\)\?/ do
|
|
35
|
+
send 'yes'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
expect /password:\s*$/ do
|
|
39
|
+
send password
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
expect /\$\s*$/ do
|
|
43
|
+
send 'uptime'
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Expect each of the following
|
|
49
|
+
each do
|
|
50
|
+
expect /load\s+average:\s+\d+\.\d+,\s+\d+\.\d+,\s+\d+\.\d+/ do # expect the output of uptime
|
|
51
|
+
puts last_match.to_s
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
expect /\$\s+$/ do # shell prompt
|
|
55
|
+
send 'exit'
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Interact with a local script
|
|
62
|
+
This example runs a script and interacts with it
|
|
63
|
+
```ruby
|
|
64
|
+
#!/usr/bin/ruby
|
|
65
|
+
|
|
66
|
+
require 'ruby_expect'
|
|
67
|
+
|
|
68
|
+
root_password = 'root_password'
|
|
69
|
+
new_root_password = 'new_password'
|
|
70
|
+
|
|
71
|
+
exp = RubyExpect::Expect.spawn('mysql_secure_installation', :debug => true)
|
|
72
|
+
|
|
73
|
+
exp.procedure do
|
|
74
|
+
each do
|
|
75
|
+
expect "Enter current password for root (enter for none):" do
|
|
76
|
+
send root_password
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
expect "Change the root password? [Y/n]" do
|
|
80
|
+
send "y"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
expect "New password:" do
|
|
84
|
+
send new_root_password
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
expect "Re-enter new password:" do
|
|
88
|
+
send new_root_password
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
expect "Remove anonymous users?" do
|
|
92
|
+
send "y"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
expect "Disallow root login remotely?" do
|
|
96
|
+
send "y"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
expect "Remove test database and access to it?" do
|
|
100
|
+
send "y"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
expect "Reload privilege tables now?" do
|
|
104
|
+
send "y"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
puts "Ended expect script."
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
### SSH to a host and interact
|
|
114
|
+
This example will spawn ssh and login to the host. Once logged in, the interact
|
|
115
|
+
method is called which returns control to the user and allows them to interact
|
|
116
|
+
directly with the remote system
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
#!/usr/bin/ruby
|
|
120
|
+
|
|
121
|
+
require 'ruby_expect'
|
|
122
|
+
|
|
123
|
+
username = 'username'
|
|
124
|
+
password = 'password'
|
|
125
|
+
hostname = 'hostname'
|
|
126
|
+
|
|
127
|
+
exp = RubyExpect::Expect.spawn("/usr/bin/ssh #{username}@#{hostname}")
|
|
128
|
+
exp.procedure do
|
|
129
|
+
retval = 0
|
|
130
|
+
while (retval != 2)
|
|
131
|
+
retval = any do
|
|
132
|
+
# Accept the key if it isn't already known
|
|
133
|
+
expect /Are you sure you want to continue connecting \(yes\/no\)\?/ do
|
|
134
|
+
send 'yes'
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Send the password at the prompt
|
|
138
|
+
expect /password:\s*$/ do
|
|
139
|
+
send password
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Expect the shell prompt
|
|
143
|
+
expect /\$\s*$/ do
|
|
144
|
+
send ""
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Pass control back to the user
|
|
151
|
+
exp.interact
|
|
152
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "ruby_expect"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/ruby_expect.rb
CHANGED
data/lib/ruby_expect/expect.rb
CHANGED
|
@@ -18,6 +18,7 @@ require 'thread'
|
|
|
18
18
|
require 'ruby_expect/procedure'
|
|
19
19
|
require 'pty'
|
|
20
20
|
require 'io/console'
|
|
21
|
+
require 'logger'
|
|
21
22
|
|
|
22
23
|
#####
|
|
23
24
|
#
|
|
@@ -42,8 +43,9 @@ module RubyExpect
|
|
|
42
43
|
# know what you are doing!
|
|
43
44
|
attr_reader :buffer
|
|
44
45
|
|
|
45
|
-
#
|
|
46
|
-
|
|
46
|
+
# Any supplied logger will be used both for errors and warnings as well
|
|
47
|
+
# as debug information (I/O when sending and expecting)
|
|
48
|
+
attr_accessor :logger
|
|
47
49
|
|
|
48
50
|
#####
|
|
49
51
|
# Create a new Expect object for the given IO object
|
|
@@ -96,6 +98,12 @@ module RubyExpect
|
|
|
96
98
|
|
|
97
99
|
@child_pid = options[:child_pid]
|
|
98
100
|
@debug = options[:debug] || false
|
|
101
|
+
@logger = options[:logger]
|
|
102
|
+
if @logger.nil?
|
|
103
|
+
@logger = Logger.new(STDERR)
|
|
104
|
+
@logger.level = Logger::FATAL
|
|
105
|
+
end
|
|
106
|
+
|
|
99
107
|
@buffer = ''
|
|
100
108
|
@before = ''
|
|
101
109
|
@match = ''
|
|
@@ -142,6 +150,27 @@ module RubyExpect
|
|
|
142
150
|
return RubyExpect::Expect.new(client, options, &block)
|
|
143
151
|
end
|
|
144
152
|
|
|
153
|
+
#####
|
|
154
|
+
# Set debug in order to see the output being read from the spawned process
|
|
155
|
+
def debug= debug
|
|
156
|
+
warn "`debug` is deprecated. Use a logger instead"
|
|
157
|
+
if debug
|
|
158
|
+
@logger.level = Logger::DEBUG
|
|
159
|
+
else
|
|
160
|
+
@logger.level = -1
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def debug
|
|
165
|
+
warn "`debug` is deprecated. Use a logger instead"
|
|
166
|
+
@logger.debug?
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def debug?
|
|
170
|
+
warn "`debug` is deprecated. Use a logger instead"
|
|
171
|
+
@logger.debug?
|
|
172
|
+
end
|
|
173
|
+
|
|
145
174
|
#####
|
|
146
175
|
# Perform a series of 'expects' using the DSL defined in Procedure
|
|
147
176
|
#
|
|
@@ -228,6 +257,7 @@ module RubyExpect
|
|
|
228
257
|
# end
|
|
229
258
|
#
|
|
230
259
|
def expect *patterns, &block
|
|
260
|
+
@logger.debug("Expecting #{patterns.inspect}") if @logger.debug?
|
|
231
261
|
patterns = pattern_escape(*patterns)
|
|
232
262
|
@end_time = 0
|
|
233
263
|
if (@timeout != 0)
|
|
@@ -237,11 +267,12 @@ module RubyExpect
|
|
|
237
267
|
@before = ''
|
|
238
268
|
matched_index = nil
|
|
239
269
|
while (@end_time == 0 || Time.now < @end_time)
|
|
240
|
-
|
|
270
|
+
raise ClosedError.new("Read filehandle is closed") if (@read_fh.closed?)
|
|
241
271
|
break unless (read_proc)
|
|
242
272
|
@last_match = nil
|
|
243
273
|
patterns.each_index do |i|
|
|
244
274
|
if (match = patterns[i].match(@buffer))
|
|
275
|
+
@logger.debug("Matched #{match}") if @logger.debug?
|
|
245
276
|
@last_match = match
|
|
246
277
|
@before = @buffer.slice!(0...match.begin(0))
|
|
247
278
|
@match = @buffer.slice!(0...match.to_s.length)
|
|
@@ -256,6 +287,7 @@ module RubyExpect
|
|
|
256
287
|
return matched_index
|
|
257
288
|
end
|
|
258
289
|
end
|
|
290
|
+
@logger.debug("Timeout")
|
|
259
291
|
return nil
|
|
260
292
|
end
|
|
261
293
|
|
|
@@ -327,10 +359,7 @@ module RubyExpect
|
|
|
327
359
|
else
|
|
328
360
|
input = @read_fh.readpartial(4096)
|
|
329
361
|
@buffer << input
|
|
330
|
-
if (@
|
|
331
|
-
STDERR.print input
|
|
332
|
-
STDERR.flush
|
|
333
|
-
end
|
|
362
|
+
@logger.info(input) if (@logger.info?)
|
|
334
363
|
end
|
|
335
364
|
end
|
|
336
365
|
rescue EOFError => e
|
|
@@ -339,9 +368,9 @@ module RubyExpect
|
|
|
339
368
|
return false
|
|
340
369
|
rescue Exception => e
|
|
341
370
|
unless (e.to_s == 'stream closed')
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
371
|
+
@logger.error("Exception in read_loop:")
|
|
372
|
+
@logger.error("#{e}")
|
|
373
|
+
@logger.error("\t#{e.backtrace.join("\n\t")}")
|
|
345
374
|
end
|
|
346
375
|
@read_fh.close
|
|
347
376
|
return false
|
data/ruby_expect.gemspec
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
# stub: ruby_expect 1.7.1 ruby lib
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
s.name = "ruby_expect"
|
|
6
|
+
s.version = "1.7.1"
|
|
7
|
+
|
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
9
|
+
s.require_paths = ["lib"]
|
|
10
|
+
s.authors = ["Andrew Bates"]
|
|
11
|
+
s.bindir = "exe"
|
|
12
|
+
s.date = "2016-01-06"
|
|
13
|
+
s.description = "Ruby implementation for send/expect interaction"
|
|
14
|
+
s.email = ["abates@omeganetserv.com"]
|
|
15
|
+
s.files = [".gitignore", ".rspec", ".travis.yml", "Gemfile", "LICENSE", "NOTICE", "README.md", "Rakefile", "bin/console", "bin/setup", "lib/ruby_expect.rb", "lib/ruby_expect/errors.rb", "lib/ruby_expect/expect.rb", "lib/ruby_expect/procedure.rb", "lib/ruby_expect/version.rb", "ruby_expect.gemspec"]
|
|
16
|
+
s.homepage = "https://github.com/abates/ruby_expect"
|
|
17
|
+
s.rubygems_version = "2.4.8"
|
|
18
|
+
s.summary = "This is a simple expect implementation that provides interactive access to IO objects"
|
|
19
|
+
|
|
20
|
+
if s.respond_to? :specification_version then
|
|
21
|
+
s.specification_version = 4
|
|
22
|
+
|
|
23
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
24
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.10"])
|
|
25
|
+
s.add_development_dependency(%q<rake>, ["~> 10.0"])
|
|
26
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
|
27
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
|
28
|
+
else
|
|
29
|
+
s.add_dependency(%q<bundler>, ["~> 1.10"])
|
|
30
|
+
s.add_dependency(%q<rake>, ["~> 10.0"])
|
|
31
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
|
32
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
33
|
+
end
|
|
34
|
+
else
|
|
35
|
+
s.add_dependency(%q<bundler>, ["~> 1.10"])
|
|
36
|
+
s.add_dependency(%q<rake>, ["~> 10.0"])
|
|
37
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
|
38
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
|
39
|
+
end
|
|
40
|
+
end
|
metadata
CHANGED
|
@@ -1,38 +1,94 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby_expect
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Bates
|
|
8
8
|
autorequire:
|
|
9
|
-
bindir:
|
|
9
|
+
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-01-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: bundler
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - ~>
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '1.10'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - ~>
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '1.10'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: simplecov
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
27
69
|
description: Ruby implementation for send/expect interaction
|
|
28
|
-
email:
|
|
70
|
+
email:
|
|
71
|
+
- abates@omeganetserv.com
|
|
29
72
|
executables: []
|
|
30
73
|
extensions: []
|
|
31
74
|
extra_rdoc_files: []
|
|
32
75
|
files:
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".travis.yml"
|
|
79
|
+
- Gemfile
|
|
80
|
+
- LICENSE
|
|
81
|
+
- NOTICE
|
|
82
|
+
- README.md
|
|
83
|
+
- Rakefile
|
|
84
|
+
- bin/console
|
|
85
|
+
- bin/setup
|
|
33
86
|
- lib/ruby_expect.rb
|
|
87
|
+
- lib/ruby_expect/errors.rb
|
|
34
88
|
- lib/ruby_expect/expect.rb
|
|
35
89
|
- lib/ruby_expect/procedure.rb
|
|
90
|
+
- lib/ruby_expect/version.rb
|
|
91
|
+
- ruby_expect.gemspec
|
|
36
92
|
homepage: https://github.com/abates/ruby_expect
|
|
37
93
|
licenses: []
|
|
38
94
|
metadata: {}
|
|
@@ -42,17 +98,17 @@ require_paths:
|
|
|
42
98
|
- lib
|
|
43
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
100
|
requirements:
|
|
45
|
-
- -
|
|
101
|
+
- - ">="
|
|
46
102
|
- !ruby/object:Gem::Version
|
|
47
103
|
version: '0'
|
|
48
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
105
|
requirements:
|
|
50
|
-
- -
|
|
106
|
+
- - ">="
|
|
51
107
|
- !ruby/object:Gem::Version
|
|
52
108
|
version: '0'
|
|
53
109
|
requirements: []
|
|
54
110
|
rubyforge_project:
|
|
55
|
-
rubygems_version: 2.
|
|
111
|
+
rubygems_version: 2.4.8
|
|
56
112
|
signing_key:
|
|
57
113
|
specification_version: 4
|
|
58
114
|
summary: This is a simple expect implementation that provides interactive access to
|