expectr 1.0.3 → 1.1.0

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.
@@ -1,3 +1,3 @@
1
1
  class Expectr
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/expectr.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'pty'
2
2
  require 'timeout'
3
3
  require 'thread'
4
+ require 'io/console'
4
5
 
5
6
  require 'expectr/error'
6
7
  require 'expectr/version'
@@ -88,6 +89,7 @@ class Expectr
88
89
  @interact = false
89
90
 
90
91
  @stdout,@stdin,@pid = PTY.spawn(cmd)
92
+ @stdout.winsize = STDOUT.winsize
91
93
 
92
94
  Thread.new do
93
95
  while @pid > 0
@@ -152,6 +154,11 @@ class Expectr
152
154
  old_tstp_trap = trap 'TSTP' do
153
155
  send "\C-z"
154
156
  end
157
+
158
+ # SIGWINCH should trigger an update to the child process
159
+ old_winch_trap = trap 'WINCH' do
160
+ @stdout.winsize = STDOUT.winsize
161
+ end
155
162
 
156
163
  interact = Thread.new do
157
164
  input = ''.encode("UTF-8")
@@ -164,6 +171,7 @@ class Expectr
164
171
 
165
172
  trap 'INT', old_int_trap
166
173
  trap 'TSTP', old_tstp_trap
174
+ trap 'WINCH', old_winch_trap
167
175
  `stty #{old_tty}`
168
176
  @interact = false
169
177
  end
@@ -293,6 +301,13 @@ class Expectr
293
301
  end
294
302
  end
295
303
 
304
+ # Public: Return the child's window size.
305
+ #
306
+ # Returns a two-element array (same as IO#winsize).
307
+ def winsize
308
+ @stdout.winsize
309
+ end
310
+
296
311
  # Internal: Print buffer to STDOUT if @flush_buffer is true
297
312
  #
298
313
  # buf - String to be printed to STDOUT
@@ -9,7 +9,7 @@ class InitializationTests < Test::Unit::TestCase
9
9
  assert_nothing_raised { exp = Expectr.new(File.new("/bin/ls"), flush_buffer: false) }
10
10
  end
11
11
 
12
- # lib/expectr.rb's permissions should hopefully be set to 0644
12
+ # lib/expectr.rb's permissions should be set to 0644
13
13
  def test_spawn_failures
14
14
  assert_raises(Errno::ENOENT) { exp = Expectr.new("lib/ThisFileShouldNotExist", flush_buffer: false) }
15
15
  assert_raises(Errno::EACCES) { exp = Expectr.new("lib/expectr.rb", flush_buffer: false) }
@@ -37,6 +37,10 @@ class InteractionTest < Test::Unit::TestCase
37
37
  assert_raises(Expectr::ProcessError) { @exp.send("test\n") }
38
38
  end
39
39
 
40
+ def test_winsize_set
41
+ assert_not_equal [0, 0], @exp.winsize
42
+ end
43
+
40
44
  def test_interact_sets_appropriate_flags
41
45
  [
42
46
  Thread.new {
@@ -105,10 +109,4 @@ class InteractionTest < Test::Unit::TestCase
105
109
 
106
110
  assert_not_nil @exp.expect(/321/)
107
111
  end
108
-
109
- def test_kill_process
110
- assert_equal true, @exp.kill!
111
- assert_equal 0, @exp.pid
112
- assert_raises(Expectr::ProcessError) { @exp.send("test\n") }
113
- end
114
112
  end
@@ -0,0 +1,35 @@
1
+ require 'helper'
2
+
3
+ class SignalHandlerTest < Test::Unit::TestCase
4
+ def setup
5
+ @exp = Expectr.new("bc", flush_buffer: false, timeout: 1)
6
+ end
7
+
8
+ def test_winsz_change
9
+ winsize = $stdout.winsize
10
+ [
11
+ Thread.new {
12
+ sleep 0.5
13
+ @exp.interact!.join
14
+ },
15
+ Thread.new {
16
+ sleep 1
17
+ @exp.flush_buffer=false
18
+ assert_nothing_raised do
19
+ $stdout.winsize = [10,10]
20
+ end
21
+ sleep 0.1
22
+ assert_equal [10,10], @exp.winsize
23
+ @exp.puts("quit")
24
+ }
25
+ ].each {|x| x.join}
26
+
27
+ $stdout.winsize = winsize
28
+ end
29
+
30
+ def test_kill_process
31
+ assert_equal true, @exp.kill!
32
+ assert_equal 0, @exp.pid
33
+ assert_raises(Expectr::ProcessError) { @exp.send("test\n") }
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expectr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-05 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Expectr is an interface to the functionality of Expect in Ruby
15
15
  email: chris@chriswuest.com
@@ -29,6 +29,7 @@ files:
29
29
  - test/test_core.rb
30
30
  - test/test_initialization.rb
31
31
  - test/test_interaction.rb
32
+ - test/test_signals.rb
32
33
  homepage: http://github.com/cwuest/expectr
33
34
  licenses:
34
35
  - MIT
@@ -50,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
51
  version: '0'
51
52
  requirements: []
52
53
  rubyforge_project:
53
- rubygems_version: 1.8.24
54
+ rubygems_version: 1.8.25
54
55
  signing_key:
55
56
  specification_version: 3
56
57
  summary: Expect for Ruby
@@ -58,3 +59,4 @@ test_files:
58
59
  - test/test_core.rb
59
60
  - test/test_initialization.rb
60
61
  - test/test_interaction.rb
62
+ - test/test_signals.rb