expectr 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/expectr/version.rb +1 -1
- data/lib/expectr.rb +12 -2
- data/test/test_core.rb +7 -1
- metadata +2 -2
data/lib/expectr/version.rb
CHANGED
data/lib/expectr.rb
CHANGED
@@ -30,12 +30,14 @@ require 'expectr/error'
|
|
30
30
|
class Expectr
|
31
31
|
# Public: Gets/sets the number of seconds a call to Expectr#expect may last
|
32
32
|
attr_accessor :timeout
|
33
|
+
# Public: Gets/sets whether to flush program output to STDOUT
|
34
|
+
attr_accessor :flush_buffer
|
33
35
|
# Public: Gets/sets the number of bytes to use for the internal buffer
|
34
36
|
attr_accessor :buffer_size
|
35
37
|
# Public: Gets/sets whether to constrain the buffer to the buffer size
|
36
38
|
attr_accessor :constrain
|
37
|
-
# Public:
|
38
|
-
attr_accessor :
|
39
|
+
# Public: Whether to always attempt to match once on calls to Expectr#expect.
|
40
|
+
attr_accessor :force_match
|
39
41
|
# Public: Returns the PID of the running process
|
40
42
|
attr_reader :pid
|
41
43
|
# Public: Returns the active buffer to match against
|
@@ -58,6 +60,12 @@ class Expectr
|
|
58
60
|
# (default: 8192)
|
59
61
|
# :constrain - Whether to constrain the internal buffer from the
|
60
62
|
# sub-process to :buffer_size (default: false)
|
63
|
+
# :force_match - Whether to always attempt to match against the
|
64
|
+
# internal buffer on a call to Expectr#expect. This
|
65
|
+
# is relevant following a failed call to
|
66
|
+
# Expectr#expect, which will leave the update status
|
67
|
+
# set to false, preventing further matches until more
|
68
|
+
# output is generated otherwise. (default: false)
|
61
69
|
def initialize(cmd, args={})
|
62
70
|
unless cmd.kind_of? String or cmd.kind_of? File
|
63
71
|
raise ArgumentError, "String or File expected"
|
@@ -72,6 +80,7 @@ class Expectr
|
|
72
80
|
@flush_buffer = args[:flush_buffer].nil? ? true : args[:flush_buffer]
|
73
81
|
@buffer_size = args[:buffer_size] || 8192
|
74
82
|
@constrain = args[:constrain] || false
|
83
|
+
@force_match = args[:force_match] || false
|
75
84
|
|
76
85
|
@out_mutex = Mutex.new
|
77
86
|
@out_update = false
|
@@ -232,6 +241,7 @@ class Expectr
|
|
232
241
|
# Raises Timeout::Error if a match isn't found in time, unless recoverable
|
233
242
|
def expect(pattern, recoverable = false)
|
234
243
|
match = nil
|
244
|
+
@out_update = true if @force_match
|
235
245
|
|
236
246
|
case pattern
|
237
247
|
when String
|
data/test/test_core.rb
CHANGED
@@ -12,6 +12,7 @@ class CoreTests < Test::Unit::TestCase
|
|
12
12
|
assert_equal(false, @exp.flush_buffer)
|
13
13
|
assert_equal(1, @exp.timeout)
|
14
14
|
assert_equal(4096, @exp.buffer_size)
|
15
|
+
assert_equal(false, @exp.force_match)
|
15
16
|
end
|
16
17
|
|
17
18
|
# POSIX specifies /dev/console, /dev/null and /dev/tty must exist.
|
@@ -21,8 +22,13 @@ class CoreTests < Test::Unit::TestCase
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def test_match_failure
|
24
|
-
|
25
|
+
@exp.force_match = true
|
25
26
|
assert_nothing_raised { @exp.expect(/ThisFileShouldNotExist/, true) }
|
27
|
+
assert_nothing_raised { @exp.expect(/null/) }
|
28
|
+
|
29
|
+
@exp.force_match = false
|
30
|
+
assert_raises(Timeout::Error) { @exp.expect(/ThisFileShouldNotExist/) }
|
31
|
+
assert_raises(Timeout::Error) { @exp.expect(/tty/) }
|
26
32
|
end
|
27
33
|
|
28
34
|
def test_clear_buffer
|
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.
|
4
|
+
version: 1.0.2
|
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-11-
|
12
|
+
date: 2012-11-27 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
|