ztk 1.0.0.rc.0 → 1.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,12 +24,6 @@ describe ZTK::Config do
24
24
 
25
25
  subject { class C; extend(ZTK::Config); end; C }
26
26
 
27
- before(:all) do
28
- $stdout = File.open("/dev/null", "w")
29
- $stderr = File.open("/dev/null", "w")
30
- $stdin = File.open("/dev/null", "r")
31
- end
32
-
33
27
  describe "class" do
34
28
 
35
29
  it "should be a kind of ZTK::Config" do
data/spec/ztk/dsl_spec.rb CHANGED
@@ -29,13 +29,6 @@ describe ZTK::DSL do
29
29
  DSLTest.new
30
30
  }
31
31
 
32
- before(:all) do
33
- $stdout = File.open("/dev/null", "w")
34
- $stderr = File.open("/dev/null", "w")
35
- $stdin = File.open("/dev/null", "r")
36
- end
37
-
38
-
39
32
  describe "class" do
40
33
 
41
34
  it "should be an instance of ZTK::DSL" do
@@ -24,42 +24,12 @@ describe ZTK::Parallel do
24
24
 
25
25
  subject { ZTK::Parallel.new }
26
26
 
27
- before(:all) do
28
- $stdout = File.open("/dev/null", "w")
29
- $stderr = File.open("/dev/null", "w")
30
- $stdin = File.open("/dev/null", "r")
31
- end
32
-
33
27
  describe "class" do
34
28
 
35
29
  it "should be an instance of ZTK::Parallel" do
36
30
  subject.should be_an_instance_of ZTK::Parallel
37
31
  end
38
32
 
39
- describe "default config" do
40
-
41
- it "should use $stdout as the default" do
42
- subject.config.stdout.should be_a_kind_of $stdout.class
43
- subject.config.stdout.should == $stdout
44
- end
45
-
46
- it "should use $stderr as the default" do
47
- subject.config.stderr.should be_a_kind_of $stderr.class
48
- subject.config.stderr.should == $stderr
49
- end
50
-
51
- it "should use $stdin as the default" do
52
- subject.config.stdin.should be_a_kind_of $stdin.class
53
- subject.config.stdin.should == $stdin
54
- end
55
-
56
- it "should use $logger as the default" do
57
- subject.config.logger.should be_a_kind_of ZTK::Logger
58
- subject.config.logger.should == $logger
59
- end
60
-
61
- end
62
-
63
33
  end
64
34
 
65
35
  describe "behaviour" do
@@ -24,12 +24,6 @@ describe ZTK::RescueRetry do
24
24
 
25
25
  subject { ZTK::RescueRetry }
26
26
 
27
- before(:all) do
28
- $stdout = File.open("/dev/null", "w")
29
- $stderr = File.open("/dev/null", "w")
30
- $stdin = File.open("/dev/null", "r")
31
- end
32
-
33
27
  describe "class" do
34
28
 
35
29
  it "should be ZTK::RescueRetry" do
@@ -24,12 +24,6 @@ describe ZTK::Spinner do
24
24
 
25
25
  subject { ZTK::Spinner }
26
26
 
27
- before(:all) do
28
- $stdout = File.open("/dev/null", "w")
29
- $stderr = File.open("/dev/null", "w")
30
- $stdin = File.open("/dev/null", "r")
31
- end
32
-
33
27
  describe "class" do
34
28
 
35
29
  it "should be ZTK::Spinner" do
data/spec/ztk/ssh_spec.rb CHANGED
@@ -24,42 +24,12 @@ describe ZTK::SSH do
24
24
 
25
25
  subject { ZTK::SSH.new }
26
26
 
27
- before(:all) do
28
- $stdout = File.open("/dev/null", "w")
29
- $stderr = File.open("/dev/null", "w")
30
- $stdin = File.open("/dev/null", "r")
31
- end
32
-
33
27
  describe "class" do
34
28
 
35
29
  it "should be an instance of ZTK::SSH" do
36
30
  subject.should be_an_instance_of ZTK::SSH
37
31
  end
38
32
 
39
- describe "default config" do
40
-
41
- it "should use $stdout as the default" do
42
- subject.config.stdout.should be_a_kind_of $stdout.class
43
- subject.config.stdout.should == $stdout
44
- end
45
-
46
- it "should use $stderr as the default" do
47
- subject.config.stderr.should be_a_kind_of $stderr.class
48
- subject.config.stderr.should == $stderr
49
- end
50
-
51
- it "should use $stdin as the default" do
52
- subject.config.stdin.should be_a_kind_of $stdin.class
53
- subject.config.stdin.should == $stdin
54
- end
55
-
56
- it "should use $logger as the default" do
57
- subject.config.logger.should be_a_kind_of ZTK::Logger
58
- subject.config.logger.should == $logger
59
- end
60
-
61
- end
62
-
63
33
  end
64
34
 
65
35
  # this stuff doesn't work as is under travis-ci right now
@@ -68,9 +38,8 @@ describe ZTK::SSH do
68
38
  describe "execute" do
69
39
 
70
40
  it "should be able to connect to 127.0.0.1 as the current user and execute a command (your key must be in ssh-agent)" do
71
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
72
41
  subject.config do |config|
73
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
42
+ config.ui = $ui
74
43
 
75
44
  config.user = ENV["USER"]
76
45
  config.host_name = "127.0.0.1"
@@ -80,14 +49,13 @@ describe ZTK::SSH do
80
49
 
81
50
  status = subject.exec("hostname -f")
82
51
  status.exit_code.should == 0
83
- stdout.rewind
84
- stdout.read.chomp.should == data
52
+ $ui.stdout.rewind
53
+ $ui.stdout.read.chomp.should == data
85
54
  end
86
55
 
87
56
  it "should timeout after the period specified" do
88
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
89
57
  subject.config do |config|
90
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
58
+ config.ui = $ui
91
59
 
92
60
  config.user = ENV["USER"]
93
61
  config.host_name = "127.0.0.1"
@@ -98,9 +66,8 @@ describe ZTK::SSH do
98
66
  end
99
67
 
100
68
  it "should throw an exception if the exit status is not as expected" do
101
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
102
69
  subject.config do |config|
103
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
70
+ config.ui = $ui
104
71
 
105
72
  config.user = ENV["USER"]
106
73
  config.host_name = "127.0.0.1"
@@ -109,9 +76,8 @@ describe ZTK::SSH do
109
76
  end
110
77
 
111
78
  it "should return a instance of an OpenStruct object" do
112
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
113
79
  subject.config do |config|
114
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
80
+ config.ui = $ui
115
81
 
116
82
  config.user = ENV["USER"]
117
83
  config.host_name = "127.0.0.1"
@@ -121,9 +87,8 @@ describe ZTK::SSH do
121
87
  end
122
88
 
123
89
  it "should return the exit code" do
124
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
125
90
  subject.config do |config|
126
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
91
+ config.ui = $ui
127
92
 
128
93
  config.user = ENV["USER"]
129
94
  config.host_name = "127.0.0.1"
@@ -135,9 +100,8 @@ describe ZTK::SSH do
135
100
  end
136
101
 
137
102
  it "should return the output" do
138
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
139
103
  subject.config do |config|
140
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
104
+ config.ui = $ui
141
105
 
142
106
  config.user = ENV["USER"]
143
107
  config.host_name = "127.0.0.1"
@@ -149,9 +113,8 @@ describe ZTK::SSH do
149
113
  end
150
114
 
151
115
  it "should allow us to change the expected exit code" do
152
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
153
116
  subject.config do |config|
154
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
117
+ config.ui = $ui
155
118
 
156
119
  config.user = ENV["USER"]
157
120
  config.host_name = "127.0.0.1"
@@ -163,9 +126,8 @@ describe ZTK::SSH do
163
126
  describe "stdout" do
164
127
 
165
128
  it "should capture STDOUT and send it to the appropriate pipe" do
166
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
167
129
  subject.config do |config|
168
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
130
+ config.ui = $ui
169
131
 
170
132
  config.user = ENV["USER"]
171
133
  config.host_name = "127.0.0.1"
@@ -174,14 +136,14 @@ describe ZTK::SSH do
174
136
 
175
137
  subject.exec(%Q{echo "#{data}" -f >&1})
176
138
 
177
- stdout.rewind
178
- stdout.read.match(data).should_not be nil
139
+ $ui.stdout.rewind
140
+ $ui.stdout.read.match(data).should_not be nil
179
141
 
180
- stderr.rewind
181
- stderr.read.match(data).should be nil
142
+ $ui.stderr.rewind
143
+ $ui.stderr.read.match(data).should be nil
182
144
 
183
- stdin.rewind
184
- stdin.read.match(data).should be nil
145
+ $ui.stdin.rewind
146
+ $ui.stdin.read.match(data).should be nil
185
147
  end
186
148
 
187
149
  end
@@ -189,9 +151,8 @@ describe ZTK::SSH do
189
151
  describe "stderr" do
190
152
 
191
153
  it "should capture STDERR and send it to the appropriate pipe" do
192
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
193
154
  subject.config do |config|
194
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
155
+ config.ui = $ui
195
156
 
196
157
  config.user = ENV["USER"]
197
158
  config.host_name = "127.0.0.1"
@@ -200,14 +161,14 @@ describe ZTK::SSH do
200
161
 
201
162
  subject.exec(%Q{echo "#{data}" -f >&2})
202
163
 
203
- stdout.rewind
204
- stdout.read.match(data).should be nil
164
+ $ui.stdout.rewind
165
+ $ui.stdout.read.match(data).should be nil
205
166
 
206
- stderr.rewind
207
- stderr.read.match(data).should_not be nil
167
+ $ui.stderr.rewind
168
+ $ui.stderr.read.match(data).should_not be nil
208
169
 
209
- stdin.rewind
210
- stdin.read.match(data).should be nil
170
+ $ui.stdin.rewind
171
+ $ui.stdin.read.match(data).should be nil
211
172
  end
212
173
  end
213
174
 
@@ -216,9 +177,8 @@ describe ZTK::SSH do
216
177
  describe "upload" do
217
178
 
218
179
  it "should be able to upload a file to 127.0.0.1 as the current user and execute a command (your key must be in ssh-agent)" do
219
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
220
180
  subject.config do |config|
221
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
181
+ config.ui = $ui
222
182
 
223
183
  config.user = ENV["USER"]
224
184
  config.host_name = "127.0.0.1"
@@ -245,9 +205,8 @@ describe ZTK::SSH do
245
205
  describe "download" do
246
206
 
247
207
  it "should be able to download a file from 127.0.0.1 as the current user and execute a command (your key must be in ssh-agent)" do
248
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
249
208
  subject.config do |config|
250
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
209
+ config.ui = $ui
251
210
 
252
211
  config.user = ENV["USER"]
253
212
  config.host_name = "127.0.0.1"
@@ -278,9 +237,8 @@ describe ZTK::SSH do
278
237
  describe "execute" do
279
238
 
280
239
  it "should be able to proxy through 127.0.0.1, connecting to 127.0.0.1 as the current user and execute a command (your key must be in ssh-agent)" do
281
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
282
240
  subject.config do |config|
283
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
241
+ config.ui = $ui
284
242
 
285
243
  config.user = ENV["USER"]
286
244
  config.host_name = "127.0.0.1"
@@ -292,14 +250,13 @@ describe ZTK::SSH do
292
250
 
293
251
  status = subject.exec("hostname -f")
294
252
  status.exit_code.should == 0
295
- stdout.rewind
296
- stdout.read.chomp.should == data
253
+ $ui.stdout.rewind
254
+ $ui.stdout.read.chomp.should == data
297
255
  end
298
256
 
299
257
  it "should timeout after the period specified" do
300
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
301
258
  subject.config do |config|
302
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
259
+ config.ui = $ui
303
260
 
304
261
  config.user = ENV["USER"]
305
262
  config.host_name = "127.0.0.1"
@@ -312,9 +269,8 @@ describe ZTK::SSH do
312
269
  end
313
270
 
314
271
  it "should throw an exception if the exit status is not as expected" do
315
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
316
272
  subject.config do |config|
317
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
273
+ config.ui = $ui
318
274
 
319
275
  config.user = ENV["USER"]
320
276
  config.host_name = "127.0.0.1"
@@ -325,9 +281,8 @@ describe ZTK::SSH do
325
281
  end
326
282
 
327
283
  it "should return a instance of an OpenStruct object" do
328
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
329
284
  subject.config do |config|
330
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
285
+ config.ui = $ui
331
286
 
332
287
  config.user = ENV["USER"]
333
288
  config.host_name = "127.0.0.1"
@@ -339,9 +294,8 @@ describe ZTK::SSH do
339
294
  end
340
295
 
341
296
  it "should return the exit code" do
342
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
343
297
  subject.config do |config|
344
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
298
+ config.ui = $ui
345
299
 
346
300
  config.user = ENV["USER"]
347
301
  config.host_name = "127.0.0.1"
@@ -355,9 +309,8 @@ describe ZTK::SSH do
355
309
  end
356
310
 
357
311
  it "should return the output" do
358
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
359
312
  subject.config do |config|
360
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
313
+ config.ui = $ui
361
314
 
362
315
  config.user = ENV["USER"]
363
316
  config.host_name = "127.0.0.1"
@@ -371,9 +324,8 @@ describe ZTK::SSH do
371
324
  end
372
325
 
373
326
  it "should allow us to change the expected exit code" do
374
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
375
327
  subject.config do |config|
376
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
328
+ config.ui = $ui
377
329
 
378
330
  config.user = ENV["USER"]
379
331
  config.host_name = "127.0.0.1"
@@ -387,9 +339,8 @@ describe ZTK::SSH do
387
339
  describe "stdout" do
388
340
 
389
341
  it "should capture STDOUT and send it to the appropriate pipe" do
390
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
391
342
  subject.config do |config|
392
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
343
+ config.ui = $ui
393
344
 
394
345
  config.user = ENV["USER"]
395
346
  config.host_name = "127.0.0.1"
@@ -400,14 +351,14 @@ describe ZTK::SSH do
400
351
 
401
352
  subject.exec(%Q{echo "#{data}" -f >&1})
402
353
 
403
- stdout.rewind
404
- stdout.read.match(data).should_not be nil
354
+ $ui.stdout.rewind
355
+ $ui.stdout.read.match(data).should_not be nil
405
356
 
406
- stderr.rewind
407
- stderr.read.match(data).should be nil
357
+ $ui.stderr.rewind
358
+ $ui.stderr.read.match(data).should be nil
408
359
 
409
- stdin.rewind
410
- stdin.read.match(data).should be nil
360
+ $ui.stdin.rewind
361
+ $ui.stdin.read.match(data).should be nil
411
362
  end
412
363
 
413
364
  end
@@ -415,9 +366,8 @@ describe ZTK::SSH do
415
366
  describe "stderr" do
416
367
 
417
368
  it "should capture STDERR and send it to the appropriate pipe" do
418
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
419
369
  subject.config do |config|
420
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
370
+ config.ui = $ui
421
371
 
422
372
  config.user = ENV["USER"]
423
373
  config.host_name = "127.0.0.1"
@@ -428,14 +378,14 @@ describe ZTK::SSH do
428
378
 
429
379
  subject.exec(%Q{echo "#{data}" -f >&2})
430
380
 
431
- stdout.rewind
432
- stdout.read.match(data).should be nil
381
+ $ui.stdout.rewind
382
+ $ui.stdout.read.match(data).should be nil
433
383
 
434
- stderr.rewind
435
- stderr.read.match(data).should_not be nil
384
+ $ui.stderr.rewind
385
+ $ui.stderr.read.match(data).should_not be nil
436
386
 
437
- stdin.rewind
438
- stdin.read.match(data).should be nil
387
+ $ui.stdin.rewind
388
+ $ui.stdin.read.match(data).should be nil
439
389
  end
440
390
  end
441
391
 
@@ -444,9 +394,8 @@ describe ZTK::SSH do
444
394
  describe "upload" do
445
395
 
446
396
  it "should be able to upload a file to 127.0.0.1 as the current user and execute a command (your key must be in ssh-agent)" do
447
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
448
397
  subject.config do |config|
449
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
398
+ config.ui = $ui
450
399
 
451
400
  config.user = ENV["USER"]
452
401
  config.host_name = "127.0.0.1"
@@ -475,9 +424,8 @@ describe ZTK::SSH do
475
424
  describe "download" do
476
425
 
477
426
  it "should be able to download a file from 127.0.0.1 as the current user and execute a command (your key must be in ssh-agent)" do
478
- stdout, stderr, stdin = StringIO.new, StringIO.new, StringIO.new
479
427
  subject.config do |config|
480
- config.stdout, config.stderr, config.stdin = stdout, stderr, stdin
428
+ config.ui = $ui
481
429
 
482
430
  config.user = ENV["USER"]
483
431
  config.host_name = "127.0.0.1"