te3270 0.7.1 → 0.8.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.
- checksums.yaml +4 -4
- data/ChangeLog +4 -0
- data/Gemfile +1 -2
- data/README.md +2 -2
- data/lib/te3270.rb +5 -3
- data/lib/te3270/emulator_factory.rb +3 -1
- data/lib/te3270/emulators/virtel.rb +210 -0
- data/lib/te3270/version.rb +1 -1
- data/spec/lib/te3270/accessors_spec.rb +8 -8
- data/spec/lib/te3270/emulators/extra_spec.rb +143 -133
- data/spec/lib/te3270/emulators/quick3270_spec.rb +125 -118
- data/spec/lib/te3270/emulators/x3270_spec.rb +47 -49
- data/spec/lib/te3270/screen_factory_spec.rb +3 -3
- data/spec/lib/te3270/screen_populator_spec.rb +4 -4
- data/spec/lib/te3270_spec.rb +19 -19
- data/spec/spec_helper.rb +16 -20
- data/te3270.gemspec +5 -2
- metadata +35 -2
@@ -1,170 +1,177 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe TE3270::Emulators::Quick3270 do
|
4
4
|
|
5
|
-
|
5
|
+
unless Gem.win_platform?
|
6
|
+
class WIN32OLE
|
7
|
+
end
|
8
|
+
end
|
6
9
|
|
7
|
-
|
10
|
+
let(:quick) { TE3270::Emulators::Quick3270.new }
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
allow(WIN32OLE).to receive(:new).and_return quick_system
|
14
|
+
quick.instance_variable_set(:@session_file, 'the_host')
|
15
|
+
end
|
8
16
|
|
9
|
-
|
10
|
-
|
11
|
-
|
17
|
+
describe "global behaviors" do
|
18
|
+
it 'should start new terminal' do
|
19
|
+
expect(WIN32OLE).to receive(:new).and_return(quick_system)
|
20
|
+
quick.connect
|
12
21
|
end
|
13
22
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
23
|
+
it 'should establish a session' do
|
24
|
+
allow(quick_system).to receive(:ActiveSession).and_return(quick_session)
|
25
|
+
quick.connect
|
26
|
+
end
|
19
27
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
it 'should get the screen from the active session' do
|
29
|
+
expect(quick_session).to receive(:Screen).and_return(quick_screen)
|
30
|
+
quick.connect
|
31
|
+
end
|
24
32
|
|
25
|
-
|
26
|
-
|
27
|
-
|
33
|
+
it 'should take the Visible value from a block' do
|
34
|
+
expect(quick_system).to receive(:Visible=).with(false)
|
35
|
+
quick.connect do |platform|
|
36
|
+
platform.visible = false
|
28
37
|
end
|
38
|
+
end
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
40
|
+
it 'should take the session file from a block' do
|
41
|
+
expect(quick).to receive(:session_file=).with('blah.txt')
|
42
|
+
quick.connect do |platform|
|
43
|
+
platform.session_file = 'blah.txt'
|
35
44
|
end
|
45
|
+
end
|
36
46
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
47
|
+
it 'should display an error when the session file is not set' do
|
48
|
+
quick.instance_variable_set(:@session_file, nil)
|
49
|
+
expect { quick.connect }.to raise_error('The session file must be set in a block when calling connect with the Quick3270 emulator.')
|
50
|
+
end
|
43
51
|
|
44
|
-
|
45
|
-
|
46
|
-
|
52
|
+
it 'should open the connection using the sesion file' do
|
53
|
+
expect(quick_session).to receive(:Open).with('blah.txt')
|
54
|
+
quick.connect do |platform|
|
55
|
+
platform.session_file = 'blah.txt'
|
47
56
|
end
|
57
|
+
end
|
48
58
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
59
|
+
it 'should default to Visible being true when not provided' do
|
60
|
+
expect(quick_system).to receive(:Visible=).with(true)
|
61
|
+
quick.connect
|
62
|
+
end
|
55
63
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
64
|
+
it 'should make the connection via the session' do
|
65
|
+
expect(quick_session).to receive(:Connect)
|
66
|
+
quick.connect
|
67
|
+
end
|
60
68
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
69
|
+
it 'should check to make sure the connection is successful before continuing' do
|
70
|
+
expect(quick_session).to receive(:Connected).once.and_return(false)
|
71
|
+
expect(quick_screen).to receive(:WaitHostQuiet).once.with(1000)
|
72
|
+
expect(quick_session).to receive(:Connected).once.and_return(true)
|
73
|
+
quick.connect
|
74
|
+
end
|
65
75
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
76
|
+
it 'should disconnect from a session' do
|
77
|
+
application = double('application')
|
78
|
+
expect(quick_session).to receive(:Disconnect)
|
79
|
+
expect(quick_system).to receive(:Application).and_return(application)
|
80
|
+
expect(application).to receive(:Quit)
|
81
|
+
quick.connect
|
82
|
+
quick.disconnect
|
83
|
+
end
|
84
|
+
end
|
72
85
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
quick.connect
|
79
|
-
quick.disconnect
|
80
|
-
end
|
86
|
+
describe "interacting with text fields" do
|
87
|
+
it 'should get the value from the screen' do
|
88
|
+
expect(quick_screen).to receive(:GetString).with(1, 2, 7).and_return('blah')
|
89
|
+
quick.connect
|
90
|
+
expect(quick.get_string(1, 2, 7)).to eql 'blah'
|
81
91
|
end
|
82
92
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
93
|
+
it 'should put a value on the screen' do
|
94
|
+
expect(quick_screen).to receive(:MoveTo).with(15, 56)
|
95
|
+
expect(quick_screen).to receive(:PutString).with('blah')
|
96
|
+
expect(quick_screen).to receive(:WaitHostQuiet).with(3000)
|
97
|
+
quick.connect
|
98
|
+
quick.put_string('blah', 15, 56)
|
99
|
+
end
|
100
|
+
end
|
89
101
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
102
|
+
describe "interacting with the screen" do
|
103
|
+
it 'should know how to send function keys' do
|
104
|
+
expect(quick_screen).to receive(:SendKeys).with('<Home>')
|
105
|
+
expect(quick_screen).to receive(:WaitHostQuiet).with(3000)
|
106
|
+
quick.connect
|
107
|
+
quick.send_keys(TE3270.Home)
|
97
108
|
end
|
98
109
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
quick.send_keys(TE3270.Home)
|
105
|
-
end
|
110
|
+
it 'should wait for a string to appear' do
|
111
|
+
expect(quick_screen).to receive(:WaitForString).with('string', 3, 10)
|
112
|
+
quick.connect
|
113
|
+
quick.wait_for_string('string', 3, 10)
|
114
|
+
end
|
106
115
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
116
|
+
it 'should wait for the host to be quiet' do
|
117
|
+
expect(quick_screen).to receive(:WaitHostQuiet).with(6000)
|
118
|
+
quick.connect
|
119
|
+
quick.wait_for_host(6)
|
120
|
+
end
|
112
121
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
122
|
+
it 'should wait until the cursor is at a position' do
|
123
|
+
expect(quick_screen).to receive(:WaitForCursor).with(5, 8)
|
124
|
+
quick.connect
|
125
|
+
quick.wait_until_cursor_at(5, 8)
|
126
|
+
end
|
118
127
|
|
119
|
-
|
120
|
-
quick_screen.should_receive(:WaitForCursor).with(5, 8)
|
121
|
-
quick.connect
|
122
|
-
quick.wait_until_cursor_at(5,8)
|
123
|
-
end
|
128
|
+
if Gem.win_platform?
|
124
129
|
|
125
130
|
it 'should take screenshots' do
|
126
131
|
take = double('Take')
|
127
|
-
quick_system.
|
128
|
-
Win32::Screenshot::Take.
|
129
|
-
take.
|
132
|
+
expect(quick_system).to receive(:WindowTitle).and_return('The Title')
|
133
|
+
expect(Win32::Screenshot::Take).to receive(:of).with(:window, title: 'The Title').and_return(take)
|
134
|
+
expect(take).to receive(:write).with('image.png')
|
130
135
|
quick.connect
|
131
136
|
quick.screenshot('image.png')
|
132
137
|
end
|
133
138
|
|
134
139
|
it 'should delete the file for the screenshot if it already exists' do
|
135
|
-
File.
|
136
|
-
File.
|
140
|
+
expect(File).to receive(:exists?).and_return(true)
|
141
|
+
expect(File).to receive(:delete)
|
137
142
|
take = double('Take')
|
138
|
-
quick_system.
|
139
|
-
Win32::Screenshot::Take.
|
140
|
-
take.
|
143
|
+
expect(quick_system).to receive(:WindowTitle).and_return('The Title')
|
144
|
+
expect(Win32::Screenshot::Take).to receive(:of).with(:window, title: 'The Title').and_return(take)
|
145
|
+
expect(take).to receive(:write).with('image.png')
|
141
146
|
quick.connect
|
142
147
|
quick.screenshot('image.png')
|
143
148
|
end
|
144
149
|
|
145
150
|
it 'should make the window visible before taking a screenshot' do
|
146
151
|
take = double('Take')
|
147
|
-
quick_system.
|
148
|
-
Win32::Screenshot::Take.
|
149
|
-
take.
|
150
|
-
quick_system.
|
151
|
-
quick_system.
|
152
|
+
expect(quick_system).to receive(:WindowTitle).and_return('The Title')
|
153
|
+
expect(Win32::Screenshot::Take).to receive(:of).with(:window, title: 'The Title').and_return(take)
|
154
|
+
expect(take).to receive(:write).with('image.png')
|
155
|
+
expect(quick_system).to receive(:Visible=).once.with(true)
|
156
|
+
expect(quick_system).to receive(:Visible=).twice.with(false)
|
152
157
|
quick.connect do |emulator|
|
153
158
|
emulator.visible = false
|
154
159
|
end
|
155
160
|
quick.screenshot('image.png')
|
156
161
|
end
|
157
162
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
quick.text.should == 'row 0\nrow 1\nrow 2\n'
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'should get the screen text' do
|
166
|
+
expect(quick_screen).to receive(:Rows).and_return(3)
|
167
|
+
expect(quick_screen).to receive(:Cols).and_return(10)
|
168
|
+
3.times do |time|
|
169
|
+
expect(quick_screen).to receive(:GetString).with(time+1, 1, 10).and_return("row #{time}")
|
166
170
|
end
|
171
|
+
quick.connect
|
172
|
+
expect(quick.text).to eql 'row 0\nrow 1\nrow 2\n'
|
167
173
|
end
|
168
174
|
end
|
169
|
-
|
170
175
|
end
|
176
|
+
|
177
|
+
|
@@ -6,43 +6,43 @@ describe TE3270::Emulators::X3270 do
|
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
@x3270_io = double('x3270_io')
|
9
|
-
Open3.
|
9
|
+
allow(Open3).to receive(:popen2e).and_return [@x3270_io,@x3270_io,nil]
|
10
10
|
x3270.instance_variable_set(:@executable_command, "the_command")
|
11
11
|
x3270.instance_variable_set(:@host, "the_host")
|
12
|
-
@x3270_io.
|
13
|
-
@x3270_io.
|
14
|
-
@x3270_io.
|
12
|
+
allow(@x3270_io).to receive(:print)
|
13
|
+
allow(@x3270_io).to receive(:flush)
|
14
|
+
allow(@x3270_io).to receive(:gets).and_return('goo','ok')
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "global behaviors" do
|
18
18
|
it 'should open pipe to x3270' do
|
19
|
-
Open3.
|
19
|
+
expect(Open3).to receive(:popen2e).and_return(x3270_system)
|
20
20
|
x3270.connect
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should take the timeout value from a block' do
|
24
|
-
x3270.
|
24
|
+
expect(x3270).to receive(:executable_command=).with('path to the x3270 executable')
|
25
25
|
x3270.connect do |platform|
|
26
26
|
platform.executable_command = 'path to the x3270 executable'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'should take the host to connect to from a block' do
|
31
|
-
x3270.
|
31
|
+
expect(x3270).to receive(:host=).with('name of host to connect to')
|
32
32
|
x3270.connect do |platform|
|
33
33
|
platform.host = 'name of host to connect to'
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'should take the max timeout value from a block' do
|
38
|
-
x3270.
|
38
|
+
expect(x3270).to receive(:max_wait_time=).with(42)
|
39
39
|
x3270.connect do |platform|
|
40
40
|
platform.max_wait_time = 42
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should take the connection port from a block' do
|
45
|
-
x3270.
|
45
|
+
expect(x3270).to receive(:port=).with(3270)
|
46
46
|
x3270.connect do |platform|
|
47
47
|
platform.port = 3270
|
48
48
|
end
|
@@ -59,25 +59,24 @@ describe TE3270::Emulators::X3270 do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should default to max_wait_time being 10 when not provided' do
|
62
|
-
#x3270.should_receive(:max_wait_time=).with(10)
|
63
62
|
x3270.connect
|
64
|
-
x3270.instance_variable_get(:@max_wait_time).
|
63
|
+
expect(x3270.instance_variable_get(:@max_wait_time)).to eql(10)
|
65
64
|
end
|
66
65
|
|
67
66
|
it 'should default to port being 23 when not provided' do
|
68
67
|
x3270.connect
|
69
|
-
x3270.instance_variable_get(:@port).
|
68
|
+
expect(x3270.instance_variable_get(:@port)).to eql(23)
|
70
69
|
end
|
71
70
|
|
72
71
|
it 'should display an error when cannot popen supplied x3270 program' do
|
73
|
-
Open3.
|
72
|
+
allow(Open3).to receive(:popen2e).and_raise('darn it, popen failed')
|
74
73
|
expect { x3270.connect }.to raise_error( "Could not start x3270 'the_command': darn it, popen failed")
|
75
74
|
end
|
76
75
|
|
77
76
|
it 'should close input and output on pipe when disconnect called' do
|
78
77
|
io = double('IO')
|
79
|
-
Open3.
|
80
|
-
io.
|
78
|
+
expect(Open3).to receive(:popen2e).and_return [io,io,io]
|
79
|
+
allow(io).to receive(:close).twice
|
81
80
|
x3270.connect
|
82
81
|
x3270.disconnect
|
83
82
|
end
|
@@ -85,23 +84,22 @@ describe TE3270::Emulators::X3270 do
|
|
85
84
|
|
86
85
|
describe "interacting with text fields" do
|
87
86
|
it 'should get the value from the screen' do
|
88
|
-
@x3270_io.
|
89
|
-
@x3270_io.
|
90
|
-
#@x3270_io.stub(:gets).and_return('ok')
|
87
|
+
expect(@x3270_io).to receive(:print).with("ascii(0,1,7)\n")
|
88
|
+
expect(@x3270_io).to receive(:gets).and_return('data: blah','goo','ok')
|
91
89
|
x3270.connect
|
92
|
-
x3270.get_string(1, 2, 7).
|
90
|
+
expect(x3270.get_string(1, 2, 7)).to eql 'blah'
|
93
91
|
end
|
94
92
|
|
95
93
|
it 'should put a value on the screen' do
|
96
|
-
@x3270_io.
|
97
|
-
@x3270_io.
|
94
|
+
expect(@x3270_io).to receive(:print).with("MoveCursor(14,55)\n")
|
95
|
+
expect(@x3270_io).to receive(:print).with('string "blah"'+"\n")
|
98
96
|
x3270.connect
|
99
97
|
x3270.put_string('blah', 15, 56)
|
100
98
|
end
|
101
99
|
|
102
100
|
it 'should put proper escape value on the screen' do
|
103
|
-
@x3270_io.
|
104
|
-
@x3270_io.
|
101
|
+
expect(@x3270_io).to receive(:print).with("MoveCursor(14,55)\n")
|
102
|
+
expect(@x3270_io).to receive(:print).with('string "ab\"cd"'+"\n")
|
105
103
|
x3270.connect
|
106
104
|
x3270.put_string('ab"cd', 15, 56)
|
107
105
|
end
|
@@ -109,83 +107,83 @@ describe TE3270::Emulators::X3270 do
|
|
109
107
|
|
110
108
|
describe "interacting with the screen" do
|
111
109
|
it 'should know how to send function keys' do
|
112
|
-
@x3270_io.
|
113
|
-
@x3270_io.
|
110
|
+
expect(@x3270_io).to receive(:print).with("Home\n")
|
111
|
+
expect(@x3270_io).to receive(:print).with("wait(output)\n")
|
114
112
|
x3270.connect
|
115
113
|
x3270.send_keys(TE3270.Home)
|
116
114
|
end
|
117
115
|
|
118
116
|
it 'should know how to send program function keys ' do
|
119
|
-
@x3270_io.
|
120
|
-
@x3270_io.
|
117
|
+
expect(@x3270_io).to receive(:print).with("Pf(13)\n")
|
118
|
+
expect(@x3270_io).to receive(:print).with("wait(output)\n")
|
121
119
|
x3270.connect
|
122
120
|
x3270.send_keys(TE3270.Pf13)
|
123
121
|
end
|
124
122
|
|
125
123
|
it 'should know how to send program attention keys ' do
|
126
|
-
@x3270_io.
|
127
|
-
@x3270_io.
|
124
|
+
expect(@x3270_io).to receive(:print).with("Pa(2)\n")
|
125
|
+
expect(@x3270_io).to receive(:print).with("wait(output)\n")
|
128
126
|
x3270.connect
|
129
127
|
x3270.send_keys(TE3270.Pa2)
|
130
128
|
end
|
131
129
|
|
132
130
|
it 'should wait for a string to appear' do
|
133
|
-
@x3270_io.
|
134
|
-
@x3270_io.
|
135
|
-
x3270.
|
131
|
+
expect(@x3270_io).to receive(:print).with("ascii(2,9,6)\n")
|
132
|
+
expect(@x3270_io).to receive(:gets).and_return('data: string','goo','ok')
|
133
|
+
expect(x3270).not_to receive(:sleep)
|
136
134
|
x3270.connect
|
137
135
|
x3270.wait_for_string('string', 3, 10)
|
138
136
|
end
|
139
137
|
|
140
138
|
it 'should timeout when wait for a string does not appear' do
|
141
|
-
@x3270_io.
|
142
|
-
@x3270_io.
|
143
|
-
x3270.
|
139
|
+
expect(@x3270_io).to receive(:print).with("ascii(2,9,6)\n").exactly(20).times
|
140
|
+
expect(@x3270_io).to receive(:gets).and_return('data: stuff','goo','ok')
|
141
|
+
expect(x3270).to receive(:sleep).exactly(20).times
|
144
142
|
x3270.connect
|
145
143
|
x3270.wait_for_string('string', 3, 10)
|
146
144
|
end
|
147
145
|
|
148
146
|
it 'should find string after one sleep when waiting for a string to appear' do
|
149
|
-
@x3270_io.
|
150
|
-
@x3270_io.
|
151
|
-
x3270.
|
147
|
+
expect(@x3270_io).to receive(:print).with("ascii(2,9,6)\n").twice
|
148
|
+
expect(@x3270_io).to receive(:gets).and_return('data: blah','goo','ok','data: string','goo','ok')
|
149
|
+
expect(x3270).to receive(:sleep).with(0.5).once
|
152
150
|
x3270.connect
|
153
151
|
x3270.wait_for_string('string', 3, 10)
|
154
152
|
end
|
155
153
|
|
156
154
|
it 'should wait for host' do
|
157
|
-
@x3270_io.
|
155
|
+
expect(@x3270_io).to receive(:print).with("Wait(10,Output)\n")
|
158
156
|
x3270.connect
|
159
157
|
x3270.wait_for_host(10)
|
160
158
|
end
|
161
159
|
|
162
160
|
it 'should wait until the cursor is at a position' do
|
163
|
-
@x3270_io.
|
161
|
+
expect(@x3270_io).to receive(:print).with("MoveCursor(5,8)\n")
|
164
162
|
x3270.connect
|
165
163
|
x3270.wait_until_cursor_at(6,9)
|
166
164
|
end
|
167
165
|
|
168
166
|
it 'should take screenshots' do
|
169
|
-
File.
|
170
|
-
File.
|
171
|
-
@x3270_io.
|
167
|
+
expect(File).to receive(:exists?).and_return(false)
|
168
|
+
expect(File).not_to receive(:delete)
|
169
|
+
expect(@x3270_io).to receive(:print).with("printtext(file,image.txt)\n")
|
172
170
|
x3270.connect
|
173
171
|
x3270.screenshot("image.txt")
|
174
172
|
end
|
175
173
|
|
176
174
|
it 'should delete existing file when taking screenshots' do
|
177
|
-
File.
|
178
|
-
File.
|
179
|
-
@x3270_io.
|
175
|
+
expect(File).to receive(:exists?).and_return(true)
|
176
|
+
expect(File).to receive(:delete)
|
177
|
+
expect(@x3270_io).to receive(:print).with("printtext(file,image.txt)\n")
|
180
178
|
x3270.connect
|
181
179
|
x3270.screenshot("image.txt")
|
182
180
|
end
|
183
181
|
|
184
182
|
it 'should get all text from screen' do
|
185
|
-
@x3270_io.
|
186
|
-
@x3270_io.
|
183
|
+
expect(@x3270_io).to receive(:print).with("ascii(0,0,1920)\n")
|
184
|
+
expect(@x3270_io).to receive(:gets).and_return('data: string','goo','ok')
|
187
185
|
x3270.connect
|
188
|
-
x3270.text.
|
186
|
+
expect(x3270.text).to eql 'string'
|
189
187
|
end
|
190
188
|
end
|
191
189
|
end
|