rdiff-simple 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ module RdiffSimple
2
+ COMMANDS = {
3
+ rdiff: 'rdiff-backup',
4
+ installed: "which #{:rdiff}",
5
+ }
6
+ end
@@ -0,0 +1,3 @@
1
+ module RdiffSimple
2
+ class NotInstalledError < Exception; end
3
+ end
@@ -0,0 +1,5 @@
1
+ module RdiffSimple
2
+ EXIT_CODE = {
3
+ success: 0
4
+ }
5
+ end
@@ -0,0 +1,20 @@
1
+ require 'open3'
2
+
3
+ module RdiffSimple
4
+ module RdiffBackup
5
+ def self.execute(*args)
6
+ raise NotInstalledError, 'rdiff-backup not installed' unless installed?
7
+
8
+ command = ['rdiff-backup', args].flatten!.compact.join(' ').strip
9
+
10
+ output, status = Open3.capture2e(command)
11
+ STDOUT.write output
12
+ status == EXIT_CODE[:success]
13
+ end
14
+
15
+ def self.installed?
16
+ output, status = Open3.capture2e(COMMANDS[:installed])
17
+ status == EXIT_CODE[:success]
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module RdiffSimple
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/rdiff_simple.rb CHANGED
@@ -1,16 +1,6 @@
1
- require "rdiff_simple/version"
1
+ require 'rdiff_simple/version'
2
+ require 'rdiff_simple/exit_codes'
3
+ require 'rdiff_simple/errors'
4
+ require 'rdiff_simple/commands'
5
+ require 'rdiff_simple/rdiff_backup'
2
6
 
3
- module RdiffSimple
4
-
5
- class NotInstalledError < Exception; end
6
-
7
- def self.execute(args)
8
- raise NotInstalledError, 'rdiff-backup not installed' unless installed?
9
-
10
- system("rdiff-backup #{args}")
11
- end
12
-
13
- def self.installed?
14
- system('which rdiff-backup')
15
- end
16
- end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe RdiffSimple::RdiffBackup do
4
+ describe '.execute' do
5
+ context 'when rdiff-backup is installed' do
6
+ before do
7
+ Open3.stub(:capture2e).with(RdiffSimple::COMMANDS[:installed]).and_return(['', 0])
8
+ end
9
+
10
+ context 'when no arguments are given' do
11
+ before do
12
+ Open3.stub(:capture2e).with(RdiffSimple::COMMANDS[:rdiff]).and_return(['', 1])
13
+ end
14
+
15
+ subject { RdiffSimple::RdiffBackup.execute('') }
16
+
17
+ it { should be_false }
18
+ end
19
+
20
+ context 'when arguments are given' do
21
+ before do
22
+ Open3.stub(:capture2e).with("#{RdiffSimple::COMMANDS[:rdiff]} --version").and_return(['', 0])
23
+ end
24
+
25
+ subject { RdiffSimple::RdiffBackup.execute('--version') }
26
+
27
+ it { should be_true }
28
+ end
29
+ end
30
+
31
+ context 'when rdiff-backup is not installed' do
32
+ before do
33
+ Open3.stub(:capture2e).with(RdiffSimple::COMMANDS[:installed]).and_return(['', 1])
34
+ end
35
+
36
+ it 'should raise an exception' do
37
+ expect { subject.execute('--version') }.to raise_error(RdiffSimple::NotInstalledError)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '.installed?' do
43
+ context 'when rdiff-backup is installed' do
44
+ before do
45
+ Open3.stub(:capture2e).with(RdiffSimple::COMMANDS[:installed]).and_return(['', 0])
46
+ end
47
+
48
+ it { should be_installed }
49
+ end
50
+
51
+ context 'when rdiff-backup is not installed' do
52
+ before do
53
+ Open3.stub(:capture2e).with(RdiffSimple::COMMANDS[:installed]).and_return(['', 1])
54
+ end
55
+
56
+ it { should_not be_installed }
57
+ end
58
+ end
59
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,11 +11,9 @@ if RUBY_VERSION > "1.9"
11
11
  end
12
12
  end
13
13
 
14
- require 'helpers'
15
14
  require 'rdiff_simple'
16
15
 
17
16
  RSpec.configure do |config|
18
17
  config.treat_symbols_as_metadata_keys_with_true_values = true
19
18
  config.run_all_when_everything_filtered = true
20
- config.include Helpers
21
19
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: rdiff-simple
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Hansen
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-14 00:00:00.000000000 Z
12
+ date: 2013-08-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple wrapper around rdiff-backup
15
15
  email:
@@ -29,10 +29,13 @@ files:
29
29
  - README.md
30
30
  - Rakefile
31
31
  - lib/rdiff_simple.rb
32
+ - lib/rdiff_simple/commands.rb
33
+ - lib/rdiff_simple/errors.rb
34
+ - lib/rdiff_simple/exit_codes.rb
35
+ - lib/rdiff_simple/rdiff_backup.rb
32
36
  - lib/rdiff_simple/version.rb
33
37
  - rdiff-simple.gemspec
34
- - spec/helpers.rb
35
- - spec/rdiff_simple_spec.rb
38
+ - spec/lib/rdiff_simple/rdiff_backup_spec.rb
36
39
  - spec/spec_helper.rb
37
40
  homepage: http://github.com/ketiko/rdiff-simple
38
41
  licenses:
@@ -48,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
51
  - !ruby/object:Gem::Version
49
52
  segments:
50
53
  - 0
51
- hash: 3687603787058545755
54
+ hash: 2071801012397692109
52
55
  version: '0'
53
56
  none: false
54
57
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -57,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
60
  - !ruby/object:Gem::Version
58
61
  segments:
59
62
  - 0
60
- hash: 3687603787058545755
63
+ hash: 2071801012397692109
61
64
  version: '0'
62
65
  none: false
63
66
  requirements: []
@@ -67,6 +70,5 @@ signing_key:
67
70
  specification_version: 3
68
71
  summary: A wrapper around the rdiff-backup executable
69
72
  test_files:
70
- - spec/helpers.rb
71
- - spec/rdiff_simple_spec.rb
73
+ - spec/lib/rdiff_simple/rdiff_backup_spec.rb
72
74
  - spec/spec_helper.rb
data/spec/helpers.rb DELETED
@@ -1,15 +0,0 @@
1
- module Helpers
2
- def mock_rdiff_installed(value)
3
- result = value == :yes
4
- RdiffSimple.stub(:system).with('which rdiff-backup').and_return(result)
5
- end
6
-
7
- def mock_rdiff_command(command, value)
8
- result = value == :succeeded
9
-
10
- commands = [ 'rdiff-backup' ]
11
- commands << command unless command.empty?
12
-
13
- RdiffSimple.stub(:system).with(*commands).and_return(result)
14
- end
15
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RdiffSimple do
4
- describe '#execute' do
5
- context 'when rdiff-backup is installed' do
6
- before { mock_rdiff_installed :yes }
7
-
8
- context 'when no arguments are given' do
9
- before { mock_rdiff_command '', :failed }
10
- subject { RdiffSimple.execute }
11
-
12
- it { should be_false }
13
- end
14
-
15
- context 'when arguments are given' do
16
- before { mock_rdiff_command '--version', :succeeded }
17
- subject { RdiffSimple.execute('--version') }
18
-
19
- it { should be_true }
20
- end
21
- end
22
-
23
- context 'when rdiff-backup is not installed' do
24
- before { mock_rdiff_installed false }
25
-
26
- it 'should raise an exception' do
27
- expect { subject.execute('--version') }.to raise_error(RdiffSimple::NotInstalledError)
28
- end
29
- end
30
- end
31
-
32
- describe '#installed?' do
33
- context 'when rdiff-backup is installed' do
34
- before { mock_rdiff_installed :yes }
35
-
36
- it { should be_installed }
37
- end
38
-
39
- context 'when rdiff-backup is not installed' do
40
- before { mock_rdiff_installed :no }
41
-
42
- it { should_not be_installed }
43
- end
44
- end
45
- end