expectr 1.0.0 → 1.0.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.
- data/lib/expectr/version.rb +1 -1
- data/lib/expectr.rb +12 -1
- data/test/test_core.rb +15 -9
- data/test/test_initialization.rb +4 -4
- data/test/test_interaction.rb +1 -1
- metadata +2 -2
data/lib/expectr/version.rb
CHANGED
data/lib/expectr.rb
CHANGED
@@ -60,7 +60,7 @@ class Expectr
|
|
60
60
|
# sub-process to :buffer_size (default: false)
|
61
61
|
def initialize(cmd, args={})
|
62
62
|
unless cmd.kind_of? String or cmd.kind_of? File
|
63
|
-
|
63
|
+
raise ArgumentError, "String or File expected"
|
64
64
|
end
|
65
65
|
|
66
66
|
cmd = cmd.path if cmd.kind_of? File
|
@@ -91,6 +91,7 @@ class Expectr
|
|
91
91
|
break
|
92
92
|
end
|
93
93
|
|
94
|
+
force_utf8(buf) unless buf.valid_encoding?
|
94
95
|
print_buffer(buf)
|
95
96
|
|
96
97
|
@out_mutex.synchronize do
|
@@ -284,4 +285,14 @@ class Expectr
|
|
284
285
|
print buf if @flush_buffer
|
285
286
|
STDOUT.flush unless STDOUT.sync
|
286
287
|
end
|
288
|
+
|
289
|
+
# Internal: Encode a String twice to force UTF-8 encoding, dropping
|
290
|
+
# problematic characters in the process.
|
291
|
+
#
|
292
|
+
# buf - String to be encoded.
|
293
|
+
#
|
294
|
+
# Returns the encoded String.
|
295
|
+
def force_utf8(buf)
|
296
|
+
buf.force_encoding('ISO-8859-1').encode('UTF-8', 'UTF-8', replace: nil)
|
297
|
+
end
|
287
298
|
end
|
data/test/test_core.rb
CHANGED
@@ -4,20 +4,20 @@ class CoreTests < Test::Unit::TestCase
|
|
4
4
|
# For the purpose of testing, we will assume we are working within a POSIX
|
5
5
|
# environment.
|
6
6
|
def setup
|
7
|
-
@exp = Expectr.new("ls /dev", :
|
8
|
-
:
|
7
|
+
@exp = Expectr.new("ls /dev", flush_buffer: false, timeout: 1,
|
8
|
+
buffer_size: 4096)
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_object_consistency
|
12
|
-
assert_equal
|
13
|
-
assert_equal
|
14
|
-
assert_equal
|
12
|
+
assert_equal(false, @exp.flush_buffer)
|
13
|
+
assert_equal(1, @exp.timeout)
|
14
|
+
assert_equal(4096, @exp.buffer_size)
|
15
15
|
end
|
16
16
|
|
17
17
|
# POSIX specifies /dev/console, /dev/null and /dev/tty must exist.
|
18
18
|
def test_match_sets_discard
|
19
|
-
assert_not_equal
|
20
|
-
assert_not_equal
|
19
|
+
assert_not_equal(nil, @exp.expect(/null/))
|
20
|
+
assert_not_equal('', @exp.discard)
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_match_failure
|
@@ -27,9 +27,15 @@ class CoreTests < Test::Unit::TestCase
|
|
27
27
|
|
28
28
|
def test_clear_buffer
|
29
29
|
sleep 1
|
30
|
-
assert_not_equal
|
30
|
+
assert_not_equal(@exp.buffer, '')
|
31
31
|
@exp.clear_buffer!
|
32
|
-
assert_equal
|
32
|
+
assert_equal('', @exp.buffer)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_garbage_output
|
36
|
+
@exp = Expectr.new("dd if=/dev/urandom bs=1024 count=1",
|
37
|
+
flush_buffer:false, timeout: 1, buffer_size: 1024)
|
38
|
+
assert_nothing_raised { @exp.expect(/probablyNotThere/, true) }
|
33
39
|
end
|
34
40
|
|
35
41
|
def test_pid_set
|
data/test/test_initialization.rb
CHANGED
@@ -2,16 +2,16 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class InitializationTests < Test::Unit::TestCase
|
4
4
|
def test_spawn_with_file
|
5
|
-
assert_nothing_raised { exp = Expectr.new(File.new("/bin/ls"), :
|
5
|
+
assert_nothing_raised { exp = Expectr.new(File.new("/bin/ls"), flush_buffer: false) }
|
6
6
|
end
|
7
7
|
|
8
8
|
def test_spawn_with_string
|
9
|
-
assert_nothing_raised { exp = Expectr.new(File.new("/bin/ls"), :
|
9
|
+
assert_nothing_raised { exp = Expectr.new(File.new("/bin/ls"), flush_buffer: false) }
|
10
10
|
end
|
11
11
|
|
12
12
|
# lib/expectr.rb's permissions should hopefully be set to 0644
|
13
13
|
def test_spawn_failures
|
14
|
-
assert_raises(Errno::ENOENT) { exp = Expectr.new("lib/ThisFileShouldNotExist", :
|
15
|
-
assert_raises(Errno::EACCES) { exp = Expectr.new("lib/expectr.rb", :
|
14
|
+
assert_raises(Errno::ENOENT) { exp = Expectr.new("lib/ThisFileShouldNotExist", flush_buffer: false) }
|
15
|
+
assert_raises(Errno::EACCES) { exp = Expectr.new("lib/expectr.rb", flush_buffer: false) }
|
16
16
|
end
|
17
17
|
end
|
data/test/test_interaction.rb
CHANGED
@@ -3,7 +3,7 @@ require 'helper'
|
|
3
3
|
class InteractionTest < Test::Unit::TestCase
|
4
4
|
# Assume that bc(1) exists on the system for these tests
|
5
5
|
def setup
|
6
|
-
@exp = Expectr.new("bc", :
|
6
|
+
@exp = Expectr.new("bc", flush_buffer: false, timeout: 1)
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_send_and_expect
|
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.1
|
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
|
+
date: 2012-11-14 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
|