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.
@@ -1,170 +1,177 @@
1
- if Gem.win_platform?
1
+ require 'spec_helper'
2
2
 
3
- require 'spec_helper'
3
+ describe TE3270::Emulators::Quick3270 do
4
4
 
5
- describe TE3270::Emulators::Quick3270 do
5
+ unless Gem.win_platform?
6
+ class WIN32OLE
7
+ end
8
+ end
6
9
 
7
- let(:quick) { TE3270::Emulators::Quick3270.new }
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
- before(:each) do
10
- WIN32OLE.stub(:new).and_return quick_system
11
- quick.instance_variable_set(:@session_file, 'the_host')
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
- describe "global behaviors" do
15
- it 'should start new terminal' do
16
- WIN32OLE.should_receive(:new).and_return(quick_system)
17
- quick.connect
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
- it 'should establish a session' do
21
- quick_system.should_receive(:ActiveSession).and_return(quick_session)
22
- quick.connect
23
- end
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
- it 'should get the screen from the active session' do
26
- quick_session.should_receive(:Screen).and_return(quick_screen)
27
- quick.connect
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
- it 'should take the Visible value from a block' do
31
- quick_system.should_receive(:Visible=).with(false)
32
- quick.connect do |platform|
33
- platform.visible = false
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
- it 'should take the session file from a block' do
38
- quick.should_receive(:session_file=).with('blah.txt')
39
- quick.connect do |platform|
40
- platform.session_file = 'blah.txt'
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
- it 'should display an error when the session file is not set' do
45
- quick.instance_variable_set(:@session_file, nil)
46
- expect { quick.connect }.to raise_error('The session file must be set in a block when calling connect with the Quick3270 emulator.')
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
- it 'should open the connection using the sesion file' do
50
- quick_session.should_receive(:Open).with('blah.txt')
51
- quick.connect do |platform|
52
- platform.session_file = 'blah.txt'
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
- it 'should default to Visible being true when not provided' do
57
- quick_system.should_receive(:Visible=).with(true)
58
- quick.connect
59
- end
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
- it 'should make the connection via the session' do
62
- quick_session.should_receive(:Connect)
63
- quick.connect
64
- end
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
- it 'should check to make sure the connection is successful before continuing' do
67
- quick_session.should_receive(:Connected).once.and_return(false)
68
- quick_screen.should_receive(:WaitHostQuiet).once.with(1000)
69
- quick_session.should_receive(:Connected).once.and_return(true)
70
- quick.connect
71
- end
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
- it 'should disconnect from a session' do
74
- application = double('application')
75
- quick_session.should_receive(:Disconnect)
76
- quick_system.should_receive(:Application).and_return(application)
77
- application.should_receive(:Quit)
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
- describe "interacting with text fields" do
84
- it 'should get the value from the screen' do
85
- quick_screen.should_receive(:GetString).with(1, 2, 7).and_return('blah')
86
- quick.connect
87
- quick.get_string(1, 2, 7).should == 'blah'
88
- end
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
- it 'should put a value on the screen' do
91
- quick_screen.should_receive(:MoveTo).with(15, 56)
92
- quick_screen.should_receive(:PutString).with('blah')
93
- quick_screen.should_receive(:WaitHostQuiet).with(3000)
94
- quick.connect
95
- quick.put_string('blah', 15, 56)
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
- describe "interacting with the screen" do
100
- it 'should know how to send function keys' do
101
- quick_screen.should_receive(:SendKeys).with('<Home>')
102
- quick_screen.should_receive(:WaitHostQuiet).with(3000)
103
- quick.connect
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
- it 'should wait for a string to appear' do
108
- quick_screen.should_receive(:WaitForString).with('string', 3, 10)
109
- quick.connect
110
- quick.wait_for_string('string', 3, 10)
111
- end
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
- it 'should wait for the host to be quiet' do
114
- quick_screen.should_receive(:WaitHostQuiet).with(6000)
115
- quick.connect
116
- quick.wait_for_host(6)
117
- end
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
- it 'should wait until the cursor is at a position' do
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.should_receive(:WindowTitle).and_return('The Title')
128
- Win32::Screenshot::Take.should_receive(:of).with(:window, title: 'The Title').and_return(take)
129
- take.should_receive(:write).with('image.png')
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.should_receive(:exists?).and_return(true)
136
- File.should_receive(:delete)
140
+ expect(File).to receive(:exists?).and_return(true)
141
+ expect(File).to receive(:delete)
137
142
  take = double('Take')
138
- quick_system.should_receive(:WindowTitle).and_return('The Title')
139
- Win32::Screenshot::Take.should_receive(:of).with(:window, title: 'The Title').and_return(take)
140
- take.should_receive(:write).with('image.png')
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.should_receive(:WindowTitle).and_return('The Title')
148
- Win32::Screenshot::Take.should_receive(:of).with(:window, title: 'The Title').and_return(take)
149
- take.should_receive(:write).with('image.png')
150
- quick_system.should_receive(:Visible=).once.with(true)
151
- quick_system.should_receive(:Visible=).twice.with(false)
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
- it 'should get the screen text' do
159
- quick_screen.should_receive(:Rows).and_return(3)
160
- quick_screen.should_receive(:Cols).and_return(10)
161
- 3.times do |time|
162
- quick_screen.should_receive(:GetString).with(time+1, 1, 10).and_return("row #{time}")
163
- end
164
- quick.connect
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.stub(:popen2e).and_return [@x3270_io,@x3270_io,nil]
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.stub(:print)
13
- @x3270_io.stub(:flush)
14
- @x3270_io.stub(:gets).and_return('goo','ok')
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.should_receive(:popen2e).and_return(x3270_system)
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.should_receive(:executable_command=).with('path to the x3270 executable')
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.should_receive(:host=).with('name of host to connect to')
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.should_receive(:max_wait_time=).with(42)
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.should_receive(:port=).with(3270)
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).should eq(10)
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).should eq(23)
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.stub(:popen2e).and_raise('darn it, popen failed')
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.stub(:popen2e).and_return([io,io,io])
80
- io.should_receive(:close).twice
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.should_receive(:print).with("ascii(0,1,7)\n")
89
- @x3270_io.stub(:gets).and_return('data: blah','goo','ok')
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).should == 'blah'
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.should_receive(:print).with("MoveCursor(14,55)\n")
97
- @x3270_io.should_receive(:print).with('string "blah"'+"\n")
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.should_receive(:print).with("MoveCursor(14,55)\n")
104
- @x3270_io.should_receive(:print).with('string "ab\"cd"'+"\n")
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.should_receive(:print).with("Home\n")
113
- @x3270_io.should_receive(:print).with("wait(output)\n")
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.should_receive(:print).with("Pf(13)\n")
120
- @x3270_io.should_receive(:print).with("wait(output)\n")
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.should_receive(:print).with("Pa(2)\n")
127
- @x3270_io.should_receive(:print).with("wait(output)\n")
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.should_receive(:print).with("ascii(2,9,6)\n")
134
- @x3270_io.should_receive(:gets).and_return('data: string','goo','ok')
135
- x3270.should_not_receive(:sleep)
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.should_receive(:print).with("ascii(2,9,6)\n").exactly(20).times
142
- @x3270_io.should_receive(:gets).and_return('data: stuff','goo','ok')
143
- x3270.should_receive(:sleep).exactly(20).times
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.should_receive(:print).with("ascii(2,9,6)\n").twice
150
- @x3270_io.should_receive(:gets).and_return('data: blah','goo','ok','data: string','goo','ok')
151
- x3270.stub(:sleep).with(0.5).once
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.should_receive(:print).with("Wait(10,Output)\n")
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.should_receive(:print).with("MoveCursor(5,8)\n")
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.should_receive(:exists?).and_return(false)
170
- File.should_not_receive(:delete)
171
- @x3270_io.should_receive(:print).with("printtext(file,image.txt)\n")
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.should_receive(:exists?).and_return(true)
178
- File.should_receive(:delete)
179
- @x3270_io.should_receive(:print).with("printtext(file,image.txt)\n")
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.should_receive(:print).with("ascii(0,0,1920)\n")
186
- @x3270_io.should_receive(:gets).and_return('data: string','goo','ok')
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.should == 'string'
186
+ expect(x3270.text).to eql 'string'
189
187
  end
190
188
  end
191
189
  end