ruby_clone 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## 1.0.2
2
+
3
+ ### bug fix
4
+ * Fixed ssh input password
5
+ * Fixed dry-run mode to not delete files from backup folder
6
+
7
+ ## 1.0.1
8
+ * The Real first release. Just improved the README.
9
+
10
+ ## 1.0
11
+
12
+ * First release.
@@ -52,14 +52,12 @@ module RubyClone
52
52
  command = rsync_command(profile_name)
53
53
  @output.puts "\n#{command}\n\n" if @configurations[:show_command]
54
54
 
55
- pty = @pty || PTY
55
+ run_with_pty command
56
56
 
57
- pty.spawn(command) do |r, w, pid|
58
- r.each { |line| print line } if @configurations[:show_output]
57
+ unless @dry_run
58
+ profile = @profiles[profile_name.to_s]
59
+ profile.to_folder.delete_files
59
60
  end
60
-
61
- profile = @profiles[profile_name.to_s]
62
- profile.to_folder.delete_files
63
61
  end
64
62
 
65
63
  private
@@ -90,5 +88,38 @@ module RubyClone
90
88
  "-e ssh"
91
89
  end
92
90
  end
91
+
92
+ def run_with_pty(command)
93
+ pty = @pty || PTY
94
+
95
+ pty.spawn(command) do |r, w, pid|
96
+ begin
97
+ loop {
98
+ buffer = ""
99
+
100
+ until r.eof? do
101
+ char = r.getc
102
+ buffer << char
103
+ @output.print char
104
+
105
+ break if buffer =~ /password:/i
106
+ end
107
+
108
+ if buffer =~ /password:/i
109
+ @output.print " "
110
+
111
+ `stty -echo`
112
+ w.printf(STDIN.gets)
113
+ `stty echo`
114
+ else
115
+ break
116
+ end
117
+ }
118
+ rescue Errno::EIO # GNU/Linux raises EIO.
119
+ end
120
+ end
121
+
122
+ end
123
+
93
124
  end
94
125
  end
@@ -1,3 +1,3 @@
1
1
  module RubyClone
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -203,6 +203,8 @@ module RubyClone
203
203
  end
204
204
 
205
205
  FakerPTY.r.stub(:each).and_yield(nil)
206
+ FakerPTY.r.stub(:eof?).and_return(false, true)
207
+ FakerPTY.r.stub(:getc).and_return('')
206
208
  end
207
209
 
208
210
  describe "profile of string type" do
@@ -246,7 +248,7 @@ module RubyClone
246
248
 
247
249
  describe "changing configurations" do
248
250
 
249
- it "should change the rsync options when configurations has 'optionas' as '-a'" do
251
+ it "should change the rsync options when configurations has 'options' as '-a'" do
250
252
  @rsync.update_configurations options: "-a"
251
253
  @rsync.run 'test_profile'
252
254
 
@@ -270,12 +272,12 @@ module RubyClone
270
272
  end
271
273
 
272
274
  it "should as default output the rsync results in console" do
273
- FakerPTY.r.should_receive(:each)
275
+ FakerPTY.r.stub(:getc).and_return('my result')
274
276
 
275
277
  @rsync.run 'test_profile'
276
278
 
277
279
  @output.seek 0
278
- @output.read.should == "\n#{@rsync_command} #{@folders}\n\n"
280
+ @output.read.should == "\n#{@rsync_command} #{@folders}\n\nmy result"
279
281
  end
280
282
 
281
283
  it "should not output the rsync results in console when configurations has 'show_output' as false" do
@@ -289,19 +291,70 @@ module RubyClone
289
291
  end
290
292
  end
291
293
 
292
- it "should not run when it's in dry-run mode" do
293
- @rsync.dry_run = true
294
+ it "should allow the user to fill a password" do
295
+ FakerPTY.r.stub(:eof?).and_return(false, false, true)
296
+ FakerPTY.r.should_receive(:getc).and_return('Password:', 'my result')
297
+
298
+ FakerPTY.w.should_receive(:printf).with('my password')
299
+
300
+ STDIN.stub(:gets).and_return('my password')
301
+
302
+ @rsync.run 'test_profile'
303
+
304
+ @output.seek 0
305
+ @output.read.should == "\n#{@rsync_command} #{@folders}\n\nPassword: my result"
306
+ end
307
+
308
+ it "should keep allowing the user to fill a password if it's asked again" do
309
+ FakerPTY.r.stub(:eof?).and_return(false, false, false, false, true)
310
+ FakerPTY.r.should_receive(:getc).and_return('Password:', 'Password:', 'Password:', 'my result')
311
+
312
+ FakerPTY.w.stub(:printf).with('my password')
313
+
314
+ STDIN.stub(:gets).and_return('my password')
294
315
 
295
316
  @rsync.run 'test_profile'
296
317
 
297
318
  @output.seek 0
298
- @output.read.should == "\n#{@rsync_command} -n #{@folders}\n\n"
319
+ @output.read.should == "\n#{@rsync_command} #{@folders}\n\nPassword: Password: Password: my result"
299
320
  end
300
321
 
301
- it "should call profile#to_folder#delete_files" do
302
- @to_folder.should_receive(:delete_files)
322
+ it "should quit the running program after throwing Errno::EIO" do
323
+ FakerPTY.r.stub(:eof?).and_raise(Errno::EIO)
324
+ FakerPTY.r.stub(:getc).and_return('my result')
303
325
 
304
326
  @rsync.run 'test_profile'
327
+
328
+ @output.seek 0
329
+ @output.read.should == "\n#{@rsync_command} #{@folders}\n\n"
330
+ end
331
+
332
+ describe "dry-run mode" do
333
+
334
+ it "should have the option '-n'" do
335
+ @rsync.dry_run = true
336
+
337
+ @rsync.run 'test_profile'
338
+
339
+ @output.seek 0
340
+ @output.read.should == "\n#{@rsync_command} -n #{@folders}\n\n"
341
+ end
342
+
343
+ it "should not delete files from backup folder if it's in dry-run mode" do
344
+ @rsync.dry_run = true
345
+ @to_folder.should_not_receive(:delete_files)
346
+
347
+ @rsync.run 'test_profile'
348
+
349
+ @output.seek 0
350
+ @output.read.should == "\n#{@rsync_command} -n #{@folders}\n\n"
351
+ end
352
+
353
+ it "should call profile#to_folder#delete_files if it's not in dry-run mode" do
354
+ @to_folder.should_receive(:delete_files)
355
+
356
+ @rsync.run 'test_profile'
357
+ end
305
358
  end
306
359
  end
307
360
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_clone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2012-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
16
- requirement: &70236612351040 !ruby/object:Gem::Requirement
16
+ requirement: &70344141036160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.3.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70236612351040
24
+ version_requirements: *70344141036160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: guard-rspec
27
- requirement: &70236612350320 !ruby/object:Gem::Requirement
27
+ requirement: &70344141034220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.2.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70236612350320
35
+ version_requirements: *70344141034220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70236612349580 !ruby/object:Gem::Requirement
38
+ requirement: &70344141033540 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 2.11.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70236612349580
46
+ version_requirements: *70344141033540
47
47
  description: Ruby clone is a command line tool to work with Rsync using DSL!
48
48
  email:
49
49
  - fredbene@gmail.com
@@ -53,6 +53,7 @@ extensions: []
53
53
  extra_rdoc_files: []
54
54
  files:
55
55
  - .gitignore
56
+ - CHANGELOG.md
56
57
  - Gemfile
57
58
  - Guardfile
58
59
  - LICENSE