expectr 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile DELETED
@@ -1,18 +0,0 @@
1
- require 'rake/testtask'
2
- require 'rdoc/task'
3
-
4
- task default: :test
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs.unshift File.expand_path('../test', __FILE__)
8
- t.test_files = Dir.glob('test/**/test_*.rb')
9
- t.ruby_opts = ['-rubygems'] if defined? Gem
10
- t.ruby_opts << '-I./lib'
11
- end
12
-
13
- RDoc::Task.new(:doc) do |rdoc|
14
- rdoc.rdoc_dir = 'doc'
15
- rdoc.main = 'README.rdoc'
16
- rdoc.rdoc_files.include('README.rdoc', 'lib/*.rb')
17
- rdoc.options = %w[--inline-source --line-numbers --title Expectr --encoding=UTF-8 --main README.rdoc]
18
- end
data/expectr.gemspec DELETED
@@ -1,18 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
- require 'expectr/version'
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "expectr"
6
- s.version = Expectr::VERSION
7
-
8
- s.description = "Expectr is an interface to the functionality of Expect in Ruby"
9
- s.summary = "Expect for Ruby"
10
- s.authors = ["Chris Wuest"]
11
- s.email = "chris@chriswuest.com"
12
- s.homepage = "http://github.com/cwuest/expectr"
13
-
14
- s.files = `git ls-files`.split("\n")
15
- s.test_files = s.files.select { |f| f =~ /^test\/test_/ }
16
-
17
- s.license = 'MIT'
18
- end
data/test/helper.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'test/unit'
2
- require 'expectr'
3
-
4
- $LOAD_PATH.unshift File.dirname(__FILE__)
data/test/test_core.rb DELETED
@@ -1,50 +0,0 @@
1
- require 'helper'
2
-
3
- class CoreTests < Test::Unit::TestCase
4
- # For the purpose of testing, we will assume we are working within a POSIX
5
- # environment.
6
- def setup
7
- @exp = Expectr.new("ls /dev && sleep 5", flush_buffer: false, timeout: 1,
8
- buffer_size: 4096)
9
- end
10
-
11
- def test_object_consistency
12
- assert_equal(false, @exp.flush_buffer)
13
- assert_equal(1, @exp.timeout)
14
- assert_equal(4096, @exp.buffer_size)
15
- assert_equal(false, @exp.force_match)
16
- end
17
-
18
- # POSIX specifies /dev/console, /dev/null and /dev/tty must exist.
19
- def test_match_sets_discard
20
- assert_not_equal(nil, @exp.expect(/null/))
21
- assert_not_equal('', @exp.discard)
22
- end
23
-
24
- def test_match_failure
25
- @exp.force_match = true
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/) }
32
- end
33
-
34
- def test_clear_buffer
35
- sleep 1
36
- assert_not_equal('', @exp.buffer)
37
- @exp.clear_buffer!
38
- assert_equal('', @exp.buffer)
39
- end
40
-
41
- def test_garbage_output
42
- @exp = Expectr.new("dd if=/dev/urandom bs=1024 count=1",
43
- flush_buffer:false, timeout: 1, buffer_size: 1024)
44
- assert_nothing_raised { @exp.expect(/probablyNotThere/, true) }
45
- end
46
-
47
- def test_pid_set
48
- assert_not_equal(0, @exp.pid)
49
- end
50
- end
@@ -1,17 +0,0 @@
1
- require 'helper'
2
-
3
- class InitializationTests < Test::Unit::TestCase
4
- def test_spawn_with_file
5
- assert_nothing_raised { exp = Expectr.new(File.new("/bin/ls"), flush_buffer: false) }
6
- end
7
-
8
- def test_spawn_with_string
9
- assert_nothing_raised { exp = Expectr.new(File.new("/bin/ls"), flush_buffer: false) }
10
- end
11
-
12
- # lib/expectr.rb's permissions should be set to 0644
13
- def test_spawn_failures
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
- end
17
- end
@@ -1,112 +0,0 @@
1
- require 'helper'
2
-
3
- class InteractionTest < Test::Unit::TestCase
4
- # Assume that bc(1) exists on the system for these tests
5
- def setup
6
- @exp = Expectr.new("bc", flush_buffer: false, timeout: 1)
7
- end
8
-
9
- def test_send_and_expect
10
- assert_nothing_raised do
11
- @exp.send("300+21\n")
12
- @exp.expect("321")
13
- @exp.puts("quit")
14
- end
15
- end
16
-
17
- def test_expect_with_block
18
- assert_nothing_raised do
19
- @exp.send("300+21\n")
20
- @exp.expect("321") { |m| m.nil? ? raise(ArgumentError) : true }
21
- end
22
-
23
- assert_raises(TimeoutError) do
24
- @exp.send("300+21\n")
25
- @exp.expect("xxx") { |m| m.nil? ? raise(ArgumentError) : true }
26
- end
27
-
28
- assert_raises(ArgumentError) do
29
- @exp.send("300+21\n")
30
- @exp.expect("xxx", true) { |m| m.nil? ? raise(ArgumentError) : true }
31
- end
32
- end
33
-
34
- def test_send_to_terminated_fails
35
- @exp.send("quit\n")
36
- sleep 2
37
- assert_raises(Expectr::ProcessError) { @exp.send("test\n") }
38
- end
39
-
40
- def test_winsize_set
41
- assert_not_equal([0, 0], @exp.winsize)
42
- end
43
-
44
- def test_interact_sets_appropriate_flags
45
- [
46
- Thread.new {
47
- assert_equal(false, @exp.interact?)
48
-
49
- sleep 0.5
50
- @exp.interact!.join
51
- },
52
- Thread.new {
53
- sleep 1
54
- assert_equal(true, @exp.flush_buffer)
55
- assert_equal(true, @exp.interact?)
56
-
57
- @exp.flush_buffer = false
58
- @exp.send("quit\n")
59
- }
60
- ].each { |x| x.join }
61
- end
62
-
63
- def test_interact_mode
64
- [
65
- Thread.new {
66
- sleep 0.5
67
- @exp.interact!.join
68
- },
69
- Thread.new {
70
- sleep 1
71
- @exp.flush_buffer = false
72
- @exp.send("300+21\n")
73
- @exp.send("quit\n")
74
- }
75
- ].each { |x| x.join }
76
-
77
- assert_not_nil(@exp.expect(/321/))
78
- end
79
-
80
- def test_leaving_interact_mode
81
- [
82
- Thread.new {
83
- sleep 0.5
84
- @exp.interact!.join
85
- },
86
- Thread.new {
87
- sleep 1
88
- @exp.flush_buffer = false
89
- assert_nothing_raised { @exp.leave! }
90
- assert_equal(false, @exp.interact?)
91
- @exp.send("quit\n")
92
- }
93
- ].each { |x| x.join }
94
- end
95
-
96
- def test_blocking_interact_mode
97
- [
98
- Thread.new {
99
- sleep 0.5
100
- @exp.interact!(blocking: true)
101
- },
102
- Thread.new {
103
- sleep 1
104
- @exp.flush_buffer = false
105
- @exp.send("300+21\n")
106
- @exp.send("quit\n")
107
- }
108
- ].each { |x| x.join }
109
-
110
- assert_not_nil(@exp.expect(/321/))
111
- end
112
- end
data/test/test_signals.rb DELETED
@@ -1,36 +0,0 @@
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
- sleep 0.5
33
- assert_equal(0, @exp.pid)
34
- assert_raises(Expectr::ProcessError) { @exp.send("test\n") }
35
- end
36
- end