dotify 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ module Dotify
4
+ describe List do
5
+
6
+ describe List, "#home" do
7
+ it "should call List#list with the correct path" do
8
+ List.should_receive(:units).with("/tmp/home/.*").once.and_return([])
9
+ List.home
10
+ end
11
+ it "should drop files that have been specified to be ignored" do
12
+ List.stub(:units) do
13
+ [
14
+ Unit.new('.zshrc'),
15
+ Unit.new('.bashrc'),
16
+ Unit.new('.vimrc'),
17
+ Unit.new('.gitconfig')
18
+ ]
19
+ end
20
+ Config.stub(:ignore).with(:dotfiles).and_return %w[.zshrc .vimrc]
21
+ result = List.home.map(&:filename)
22
+ result.should include '.bashrc'
23
+ result.should include '.gitconfig'
24
+ result.should_not include '.zshrc'
25
+ result.should_not include '.vimrc'
26
+ end
27
+ end
28
+
29
+ describe List, "#dotify" do
30
+ it "should call List#list with the correct path" do
31
+ List.should_receive(:units).with("/tmp/home/.dotify/.*").once.and_return([])
32
+ List.dotify
33
+ end
34
+ it "should drop files that have been specified to be ignored" do
35
+ List.stub(:units) do
36
+ [
37
+ Unit.new(".gitconfig"),
38
+ Unit.new('.vimrc'),
39
+ Unit.new('.zshrc'),
40
+ Unit.new('.bashrc'),
41
+ Unit.new('.fakefile')
42
+ ]
43
+ end
44
+ Config.stub(:ignore).with(:dotify).and_return %w[.gitconfig .bashrc]
45
+ result = List.filenames(List.dotify)
46
+ result.should include '.vimrc'
47
+ result.should include '.zshrc'
48
+ result.should include '.fakefile'
49
+ result.should_not include '.bashrc'
50
+ result.should_not include '.gitconfig'
51
+ end
52
+ end
53
+
54
+ describe List, "#units" do
55
+ let(:glob) { '/spec/test/.*' }
56
+ it "should pull the glob of dotfiles from a directory" do
57
+ Dir.should_receive(:[]).with(glob).and_return(%w[. .. /spec/test/.vimrc /spec/test/.bashrc /spec/test/.zshrc])
58
+ List.units(glob)
59
+ end
60
+ describe "return values" do
61
+ before do
62
+ Dir.stub(:[]).with(glob).and_return(%w[. .. /spec/test/.vimrc /spec/test/.bashrc /spec/test/.zshrc])
63
+ end
64
+ let(:files) { List.units(glob) }
65
+ it "should return the right directories" do
66
+ f = files.map(&:filename)
67
+ f.should include '.vimrc'
68
+ f.should include '.bashrc'
69
+ f.should include '.zshrc'
70
+ end
71
+ it "should filter out . and .. directories" do
72
+ f = files.map(&:filename)
73
+ f.should_not include '.'
74
+ f.should_not include '..'
75
+ end
76
+ end
77
+ end
78
+
79
+ describe List, "#filenames" do
80
+ let(:files) { [
81
+ Unit.new('.vimrc'), Unit.new('.bashrc'), Unit.new('.zshrc')
82
+ ] }
83
+ it "return only the filenames of the units" do
84
+ result = List.filenames(files)
85
+ result.should include '.vimrc'
86
+ result.should include '.bashrc'
87
+ result.should include '.zshrc'
88
+ end
89
+ end
90
+
91
+
92
+ end
93
+ end
@@ -0,0 +1,172 @@
1
+ require 'spec_helper'
2
+ require 'dotify/unit'
3
+
4
+ class DummyUnit
5
+ def dotfile
6
+ '.dummy'
7
+ end
8
+ def dotify
9
+ '.dotify/.dummy'
10
+ end
11
+
12
+ def linked?; end
13
+ def in_home_dir?; true; end
14
+ def in_dotify?; true; end
15
+ end
16
+
17
+ module Dotify
18
+
19
+ describe Actions do
20
+ let!(:dummy) { DummyUnit.new }
21
+ subject { dummy }
22
+ before { dummy.extend(Actions) }
23
+ it { should respond_to :link }
24
+ it { should respond_to :unlink }
25
+
26
+ describe Actions, "#link" do
27
+ before do
28
+ subject.stub(:linked?) { false }
29
+ end
30
+ it "should not do anything if the file is linked" do
31
+ subject.stub(:linked?) { true }
32
+ subject.link.should == false
33
+ end
34
+ it "should not do anything if the is not in the home directory" do
35
+ subject.stub(:linked?) { true }
36
+ subject.stub(:in_home_dir?) { false }
37
+ subject.link.should == false
38
+ end
39
+ it "should copy the file from the home directory if it is not in Dotify" do
40
+ FileUtils.should_receive(:rm_rf).with(subject.dotfile, :verbose => false)
41
+ FileUtils.should_receive(:ln_sf).with(subject.dotify, subject.dotfile, :verbose => false)
42
+ subject.link
43
+ end
44
+ it "should simply remove the file from the home and relink it" do
45
+ subject.stub(:in_dotify?) { false }
46
+ FileUtils.should_receive(:cp_r).with(subject.dotfile, subject.dotify, :verbose => false)
47
+ FileUtils.stub(:rm_rf)
48
+ FileUtils.stub(:ln_sf)
49
+ subject.link
50
+ end
51
+ end
52
+ describe Actions, "#unlink" do
53
+ it "should not do anything if the file is not linked" do
54
+ subject.stub(:linked?) { false }
55
+ FileUtils.should_not_receive(:rm_rf)
56
+ FileUtils.should_not_receive(:cp_r)
57
+ FileUtils.should_not_receive(:rm_rf)
58
+ subject.unlink.should == false
59
+ end
60
+ it "should call the right FileUtils methods" do
61
+ subject.stub(:linked?) { true }
62
+ FileUtils.should_receive(:rm_rf).with(subject.dotfile, :verbose => false)
63
+ FileUtils.should_receive(:cp_r).with(subject.dotify, subject.dotfile, :verbose => false)
64
+ FileUtils.should_receive(:rm_rf).with(subject.dotify, :verbose => false)
65
+ subject.unlink
66
+ end
67
+ end
68
+ end
69
+ describe Unit do
70
+
71
+ describe "populates the attributes correctly" do
72
+ let(:unit) { Unit.new(".vimrc") }
73
+ subject { unit }
74
+ it { should respond_to :filename }
75
+ it { should respond_to :dotify }
76
+ it { should respond_to :dotfile }
77
+ it { should respond_to :linked? }
78
+ it { should respond_to :linked }
79
+ it { should respond_to :added? }
80
+ it { should respond_to :added }
81
+
82
+ it "should set the attributes properly" do
83
+ unit.filename.should == '.vimrc'
84
+ unit.dotify.should == '/tmp/home/.dotify/.vimrc'
85
+ unit.dotfile.should == '/tmp/home/.vimrc'
86
+ end
87
+ it "should puts the filename" do
88
+ unit.to_s.should == unit.filename
89
+ end
90
+ end
91
+
92
+ describe "existence in directories" do
93
+ let(:unit) { Unit.new(".bashrc") }
94
+ it "should check for the existence in the home directory" do
95
+ File.stub(:exists?).with(unit.dotfile).and_return true
96
+ unit.in_home_dir?.should == true
97
+ end
98
+ it "should return false if the file is not in the home directory" do
99
+ File.stub(:exists?).with(unit.dotfile).and_return false
100
+ unit.in_home_dir?.should_not == true
101
+ end
102
+ it "should check for the existence of the file in Dotify" do
103
+ File.stub(:exists?).with(unit.dotify).and_return true
104
+ unit.in_dotify?.should == true
105
+ end
106
+ it "should return false if the file is not in Dotify" do
107
+ File.stub(:exists?).with(unit.dotify).and_return false
108
+ unit.in_dotify?.should == false
109
+ end
110
+ end
111
+
112
+ describe Unit, "#linked_to_dotify?" do
113
+ let(:unit) { Unit.new(".bashrc") }
114
+ it "should return false when an error is raised" do
115
+ unit.stub(:symlink).and_return NoSymlink
116
+ unit.linked_to_dotify?.should be_false
117
+ end
118
+ it "should return true if the dotfile is linked to the Dotify file" do
119
+ unit.stub(:symlink).and_return unit.dotify
120
+ unit.linked_to_dotify?.should be_true
121
+ end
122
+ it "should return false if the dotfile is not linked to the Dotify file" do
123
+ File.stub(:readlink).with(unit.dotfile).and_return '/tmp/home/.another_file'
124
+ unit.linked_to_dotify?.should be_false
125
+ end
126
+ end
127
+
128
+ describe Unit, "#linked?" do
129
+ let(:unit) { Unit.new(".bashrc") }
130
+ before do
131
+ unit.stub(:in_dotify?).and_return true # stub identical file check
132
+ end
133
+ it "should return true if all checks work" do
134
+ unit.stub(:linked_to_dotify?).and_return true # stub dotify file exist check
135
+ unit.linked?.should == true
136
+ end
137
+ it "should return false if one or more checks fail" do
138
+ unit.stub(:linked_to_dotify?).and_return false # stub dotify file exist check
139
+ unit.linked?.should == false
140
+ end
141
+ end
142
+
143
+ describe Unit, "#added?" do
144
+ let(:unit) { Unit.new(".added") }
145
+ before do
146
+ unit.stub(:in_dotify?).and_return true # stub dotify file exist check
147
+ end
148
+ it "should return true if all checks work" do
149
+ unit.stub(:linked_to_dotify?).and_return false # stub identical file check
150
+ unit.should be_added
151
+ end
152
+ it "should return false if one or more checks fail" do
153
+ unit.stub(:linked_to_dotify?).and_return true # stub identical file check
154
+ unit.should_not be_added
155
+ end
156
+ end
157
+
158
+ describe Unit, "#symlink" do
159
+ let!(:unit) { Unit.new(".symlinked") }
160
+ it "should return the symlink for the file" do
161
+ File.should_receive(:readlink).with(unit.dotfile).once
162
+ unit.symlink
163
+ end
164
+ it "should return NoSymlink if error or no symlink" do
165
+ File.stub(:readlink).with(unit.dotfile).and_raise(StandardError)
166
+ expect { unit.symlink }.not_to raise_error
167
+ unit.symlink.should == NoSymlink
168
+ end
169
+ end
170
+
171
+ end
172
+ end
@@ -1,32 +1,33 @@
1
1
  require 'spec_helper'
2
- require 'dotify'
3
2
  require 'dotify/version_checker'
4
3
 
5
- describe Dotify::VersionChecker do
6
- it Dotify::VersionChecker, "#run_check!" do
7
- VCR.use_cassette "version_check" do
8
- Dotify::VersionChecker.version.should == '0.2.0'
9
- end
10
- end
11
- describe Dotify::VersionChecker, "#out_of_date?" do
12
- it "should be return the correct value if version is not current" do
13
- Dotify::VersionChecker.stub(:current?).and_return(false)
14
- Dotify::VersionChecker.out_of_date?.should == true
15
- Dotify::VersionChecker.stub(:current?).and_return(true)
16
- Dotify::VersionChecker.out_of_date?.should == false
4
+ module Dotify
5
+ describe VersionChecker do
6
+ it "#run_check! should return the right version number" do
7
+ VCR.use_cassette "version_check" do
8
+ VersionChecker.version.should == '0.2.0'
9
+ end
17
10
  end
18
- end
19
- describe Dotify::VersionChecker, "#current?" do
20
- it "should be false if version is not current" do
21
- with_constants "Dotify::VERSION" => '0.2.0' do
22
- Dotify::VersionChecker.stub(:version).and_return('0.1.9')
23
- Dotify::VersionChecker.current?.should == false
11
+ describe VersionChecker, "#out_of_date?" do
12
+ it "should be return the correct value if version is not current" do
13
+ VersionChecker.stub(:current?).and_return(false)
14
+ VersionChecker.out_of_date?.should == true
15
+ VersionChecker.stub(:current?).and_return(true)
16
+ VersionChecker.out_of_date?.should == false
24
17
  end
25
18
  end
26
- it "should be true if version is current" do
27
- with_constants "Dotify::VERSION" => '0.2.0' do
28
- Dotify::VersionChecker.stub(:version).and_return('0.2.0')
29
- Dotify::VersionChecker.current?.should == true
19
+ describe VersionChecker, "#current?" do
20
+ it "should be false if version is not current" do
21
+ with_constants "Dotify::VERSION" => '0.2.0' do
22
+ VersionChecker.stub(:version).and_return('0.1.9')
23
+ VersionChecker.current?.should == false
24
+ end
25
+ end
26
+ it "should be true if version is current" do
27
+ with_constants "Dotify::VERSION" => '0.2.0' do
28
+ VersionChecker.stub(:version).and_return('0.2.0')
29
+ VersionChecker.current?.should == true
30
+ end
30
31
  end
31
32
  end
32
33
  end
@@ -5,10 +5,15 @@
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
7
  $:.unshift File.expand_path("../../lib", __FILE__)
8
+ require 'dotify'
8
9
  Dir["./spec/support/**/*.rb"].each { |f| require f }
9
10
 
10
11
  RSpec.configure do |config|
11
12
  config.treat_symbols_as_metadata_keys_with_true_values = true
12
13
  config.run_all_when_everything_filtered = true
13
14
  config.filter_run :focus
15
+
16
+ config.before(:each) do
17
+ Dotify::Config.stub(:home) { '/tmp/home' }
18
+ end
14
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-04 00:00:00.000000000 Z
12
+ date: 2012-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: rspec
80
96
  requirement: !ruby/object:Gem::Requirement
@@ -135,6 +151,7 @@ files:
135
151
  - .rspec
136
152
  - .travis.yml
137
153
  - Gemfile
154
+ - Guardfile
138
155
  - LICENSE
139
156
  - README.md
140
157
  - Rakefile
@@ -144,16 +161,18 @@ files:
144
161
  - lib/dotify/cli.rb
145
162
  - lib/dotify/config.rb
146
163
  - lib/dotify/errors.rb
147
- - lib/dotify/file_list.rb
148
164
  - lib/dotify/files.rb
149
165
  - lib/dotify/git.rb
166
+ - lib/dotify/list.rb
167
+ - lib/dotify/unit.rb
150
168
  - lib/dotify/version.rb
151
169
  - lib/dotify/version_checker.rb
152
170
  - spec/dotify/cli_spec.rb
153
171
  - spec/dotify/config_spec.rb
154
- - spec/dotify/file_list_spec.rb
155
172
  - spec/dotify/files_spec.rb
156
173
  - spec/dotify/git_spec.rb
174
+ - spec/dotify/list_spec.rb
175
+ - spec/dotify/unit_spec.rb
157
176
  - spec/dotify/version_checker_spec.rb
158
177
  - spec/fixtures/.dotrc-default
159
178
  - spec/fixtures/vcr/version_check.yml
@@ -189,9 +208,10 @@ summary: A CLI Tool for managing your dotfiles
189
208
  test_files:
190
209
  - spec/dotify/cli_spec.rb
191
210
  - spec/dotify/config_spec.rb
192
- - spec/dotify/file_list_spec.rb
193
211
  - spec/dotify/files_spec.rb
194
212
  - spec/dotify/git_spec.rb
213
+ - spec/dotify/list_spec.rb
214
+ - spec/dotify/unit_spec.rb
195
215
  - spec/dotify/version_checker_spec.rb
196
216
  - spec/fixtures/.dotrc-default
197
217
  - spec/fixtures/vcr/version_check.yml
@@ -1,41 +0,0 @@
1
- require 'dotify'
2
- require 'dotify/config'
3
-
4
- module Dotify
5
- class FileList
6
- class << self
7
-
8
- def home
9
- result = paths(File.join(Config.home, '.*'))
10
- filter_ignore_files!(result, :dotfiles)
11
- end
12
-
13
- def dotify
14
- result = paths(File.join(Config.path, '.*'))
15
- filter_ignore_files!(result, :dotify)
16
- end
17
-
18
- def list(glob)
19
- filenames(paths(glob))
20
- end
21
-
22
- def paths(glob)
23
- filter_dot_directories!(Dir[glob])
24
- end
25
-
26
- def filter_dot_directories!(files)
27
- files.select { |f| !['.', '..'].include?(Files.filename(f)) }
28
- end
29
-
30
- def filter_ignore_files!(files, ignore)
31
- ignoring = Config.ignore(ignore)
32
- files.select { |f| !ignoring.include?(Files.filename(f)) }
33
- end
34
-
35
- def filenames(files)
36
- files.map { |f| Files.filename(f) }
37
- end
38
-
39
- end
40
- end
41
- end