dotify 0.6.5 → 0.6.6
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.
- data/features/step_definitions/linking_files.rb +1 -1
- data/lib/dotify.rb +1 -1
- data/lib/dotify/cli.rb +43 -24
- data/lib/dotify/collection.rb +12 -7
- data/lib/dotify/{unit.rb → dot.rb} +11 -2
- data/lib/dotify/errors.rb +1 -1
- data/lib/dotify/filter.rb +10 -10
- data/lib/dotify/version.rb +1 -1
- data/spec/dotify/cli_spec.rb +11 -11
- data/spec/dotify/collection_spec.rb +29 -15
- data/spec/dotify/config_spec.rb +5 -1
- data/spec/dotify/{unit_spec.rb → dot_spec.rb} +61 -45
- data/spec/dotify/filter_spec.rb +20 -20
- metadata +5 -5
@@ -9,7 +9,7 @@ Given /^(.*) does not exist in (home|dotify)$/i do |file, location|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
When /^they get linked by Dotify$/ do
|
12
|
-
@files_to_link.each { |file| Dotify::
|
12
|
+
@files_to_link.each { |file| Dotify::Dot.new(file).link }
|
13
13
|
end
|
14
14
|
|
15
15
|
Then /^they are all linked to the dotify path$/i do
|
data/lib/dotify.rb
CHANGED
data/lib/dotify/cli.rb
CHANGED
@@ -46,10 +46,10 @@ module Dotify
|
|
46
46
|
say message, :yellow, :verbose => options[:verbose]
|
47
47
|
repo.commit(message)
|
48
48
|
else
|
49
|
-
|
49
|
+
inform "No files have been changed in Dotify."
|
50
50
|
end
|
51
51
|
if options[:push] || yes?("Would you like to push these changed to Github? [Yn]", :blue)
|
52
|
-
|
52
|
+
inform 'Pushing up to Github...'
|
53
53
|
begin
|
54
54
|
repo.push
|
55
55
|
rescue Exception => e
|
@@ -57,18 +57,37 @@ module Dotify
|
|
57
57
|
say("Git Error: #{e.message}", :red) if options[:debug]
|
58
58
|
return
|
59
59
|
end
|
60
|
-
|
60
|
+
inform "Successfully pushed!"
|
61
61
|
end
|
62
62
|
else
|
63
|
-
|
63
|
+
inform 'Dotify has nothing to save.'
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
desc 'github [USERNAME]/[REPO]', "Install the dotfiles from a Github repo into Dotify. (Backs up any files that would be overwritten)"
|
68
|
+
method_option :debug, :aliases => '-d', :type => :boolean, :default => false, :desc => "Show error messages if there is a Git failure."
|
69
|
+
def github(repo)
|
70
|
+
return inform "Dotify has already been setup." if Dotify.installed?
|
71
|
+
git_repo_name = "git@github.com:#{repo}.git"
|
72
|
+
inform "Pulling #{repo} from Github into #{Config.path}..."
|
73
|
+
Git.clone(git_repo_name, Config.path)
|
74
|
+
inform "Backing up dotfile and installing Dotify files..."
|
75
|
+
Collection.new(:dotify).each { |file| file.backup_and_link }
|
76
|
+
if File.exists? File.join(Config.path, ".gitmodules")
|
77
|
+
inform "Initializing and updating submodules in Dotify now..."
|
78
|
+
system "cd #{Config.path} && git submodule init &> /dev/null && git submodule update &> /dev/null"
|
79
|
+
end
|
80
|
+
inform "Successfully installed #{repo} from Dotify!"
|
81
|
+
rescue Git::GitExecuteError => e
|
82
|
+
say "[ERROR]: There was an problem pulling from #{git_repo_name}.\nPlease make sure that the specified repo exists and you have access to it.", :red
|
83
|
+
say "Git Error: #{e.message}", :red if options[:debug]
|
84
|
+
end
|
85
|
+
|
67
86
|
desc :list, "List the installed dotfiles"
|
68
87
|
def list
|
69
|
-
|
70
|
-
Dotify.collection.linked.each do |
|
71
|
-
say " * #{
|
88
|
+
inform "Dotify is managing #{Dotify.collection.linked.count} files:\n"
|
89
|
+
Dotify.collection.linked.each do |dot|
|
90
|
+
say " * #{dot.filename}", :yellow
|
72
91
|
end
|
73
92
|
$stdout.write "\n"
|
74
93
|
end
|
@@ -76,12 +95,12 @@ module Dotify
|
|
76
95
|
desc 'edit [FILE]', "Edit a dotify file"
|
77
96
|
method_option :save, :aliases => '-s', :default => false, :type => :boolean, :require => true, :desc => "Save Dotify files and push to Github"
|
78
97
|
def edit(file)
|
79
|
-
file =
|
98
|
+
file = Dot.new(file)
|
80
99
|
if file.linked?
|
81
100
|
exec "#{Config.editor} #{file.dotify}"
|
82
101
|
save if options[:save] == true
|
83
102
|
else
|
84
|
-
|
103
|
+
inform "'#{file}' has not been linked by Dotify. Please run `dotify link #{file}` to edit this file."
|
85
104
|
end
|
86
105
|
end
|
87
106
|
|
@@ -92,11 +111,11 @@ module Dotify
|
|
92
111
|
return say "Dotify Version: v#{Dotify.version}", :blue unless options[:check]
|
93
112
|
if VersionChecker.out_of_date?
|
94
113
|
say "Your version of Dotify is out of date.", :yellow
|
95
|
-
|
96
|
-
|
114
|
+
inform " Your Version: #{Dotify.version}"
|
115
|
+
inform " Latest Version: #{VersionChecker.version}"
|
97
116
|
say "I recommend that you uninstall Dotify completely before updating", :yellow
|
98
117
|
else
|
99
|
-
|
118
|
+
inform "Your version of Dotify is up to date: #{Dotify.version}"
|
100
119
|
end
|
101
120
|
rescue Exception => e
|
102
121
|
say "There was an error checking your Dotify version. Please try again.", :red
|
@@ -109,9 +128,7 @@ module Dotify
|
|
109
128
|
method_options :verbose => true
|
110
129
|
def setup
|
111
130
|
# Warn if Dotify is already setup
|
112
|
-
if Dotify.installed?
|
113
|
-
say "Dotify is already setup", :blue
|
114
|
-
end
|
131
|
+
inform "Dotify is already setup" if Dotify.installed?
|
115
132
|
|
116
133
|
# Create the Dotify directory unless it already exists
|
117
134
|
unless File.exists?(Config.path)
|
@@ -123,10 +140,10 @@ module Dotify
|
|
123
140
|
template '.dotrc', Config.file, :verbose => options[:verbose]
|
124
141
|
end
|
125
142
|
|
126
|
-
|
143
|
+
inform "Editing config file..."
|
127
144
|
sleep 0.5 # Give a little time for reading the message
|
128
145
|
invoke :edit, [Config.file]
|
129
|
-
|
146
|
+
inform "Config file updated."
|
130
147
|
|
131
148
|
# Run install task if specified
|
132
149
|
invoke :install if options[:install] == true
|
@@ -149,7 +166,7 @@ module Dotify
|
|
149
166
|
def link(file = nil)
|
150
167
|
return not_setup_warning unless Dotify.installed?
|
151
168
|
# Link a single file
|
152
|
-
return file_action :link,
|
169
|
+
return file_action :link, Dot.new(file), options unless file.nil?
|
153
170
|
# Relink the files
|
154
171
|
return Dotify.collection.linked.each { |file| file_action(:link, file, options) } if options[:relink]
|
155
172
|
# Link the files
|
@@ -167,12 +184,16 @@ module Dotify
|
|
167
184
|
def unlink(file = nil)
|
168
185
|
return not_setup_warning unless Dotify.installed?
|
169
186
|
# Unlink a single file
|
170
|
-
return file_action :unlink,
|
187
|
+
return file_action :unlink, Dot.new(file), options unless file.nil?
|
171
188
|
# Unlink the files
|
172
189
|
Dotify.collection.linked.each { |file| file_action(:unlink, file, options) }
|
173
190
|
end
|
174
191
|
|
175
|
-
|
192
|
+
private
|
193
|
+
|
194
|
+
def inform(message)
|
195
|
+
say message, :blue
|
196
|
+
end
|
176
197
|
|
177
198
|
def not_setup_warning
|
178
199
|
say "Dotify has not been setup yet! You need to run 'dotify setup' first.", :yellow
|
@@ -181,10 +202,10 @@ module Dotify
|
|
181
202
|
def file_action(action, file, options = {})
|
182
203
|
case action.to_sym
|
183
204
|
when :link
|
184
|
-
return
|
205
|
+
return inform "'#{file.dotfile}' does not exist." unless file.in_home_dir?
|
185
206
|
return say_status :linked, file.dotfile if file.linked?
|
186
207
|
when :unlink
|
187
|
-
return
|
208
|
+
return inform "'#{file}' does not exist in Dotify."unless file.linked?
|
188
209
|
else
|
189
210
|
say "You can't run the action :#{action} on a file."
|
190
211
|
end
|
@@ -195,7 +216,5 @@ module Dotify
|
|
195
216
|
end
|
196
217
|
end
|
197
218
|
|
198
|
-
end
|
199
|
-
|
200
219
|
end
|
201
220
|
end
|
data/lib/dotify/collection.rb
CHANGED
@@ -3,17 +3,22 @@ module Dotify
|
|
3
3
|
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :dots
|
7
7
|
|
8
|
-
# Pulls an array of
|
8
|
+
# Pulls an array of Dots from the home
|
9
9
|
# directory.
|
10
|
-
def initialize
|
11
|
-
@
|
10
|
+
def initialize(location = :dotfiles)
|
11
|
+
@dots ||= case location
|
12
|
+
when :dotfiles then Filter.home
|
13
|
+
when :dotify then Filter.dotify
|
14
|
+
else
|
15
|
+
raise ArgumentError, "You must specify :dotfiles or :dotify when initializing Collection"
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
# Defined each method for Enumerable
|
15
20
|
def each(&block)
|
16
|
-
|
21
|
+
dots.each(&block)
|
17
22
|
end
|
18
23
|
|
19
24
|
# Linked files are those files which have a
|
@@ -30,11 +35,11 @@ module Dotify
|
|
30
35
|
end
|
31
36
|
|
32
37
|
def to_s
|
33
|
-
|
38
|
+
dots.to_s
|
34
39
|
end
|
35
40
|
|
36
41
|
def inspect
|
37
|
-
|
42
|
+
dots.map(&:inspect)
|
38
43
|
end
|
39
44
|
|
40
45
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'fileutils'
|
1
2
|
require 'dotify/errors'
|
2
3
|
|
3
4
|
module Dotify
|
@@ -17,6 +18,14 @@ module Dotify
|
|
17
18
|
return true
|
18
19
|
end
|
19
20
|
|
21
|
+
def backup_and_link
|
22
|
+
if File.exists? self.dotfile
|
23
|
+
FileUtils.rm_rf("#{self.dotfile}.bak", :verbose => false)
|
24
|
+
FileUtils.mv(self.dotfile, "#{self.dotfile}.bak", :verbose => false)
|
25
|
+
end
|
26
|
+
FileUtils.ln_sf(self.dotify, self.dotfile, :verbose => false)
|
27
|
+
end
|
28
|
+
|
20
29
|
# Unlink the file from Dotify and replace it into the home directory.
|
21
30
|
def unlink
|
22
31
|
return false unless linked?
|
@@ -28,7 +37,7 @@ module Dotify
|
|
28
37
|
|
29
38
|
end
|
30
39
|
|
31
|
-
class
|
40
|
+
class Dot
|
32
41
|
|
33
42
|
include Actions
|
34
43
|
|
@@ -64,7 +73,7 @@ module Dotify
|
|
64
73
|
end
|
65
74
|
|
66
75
|
def inspect
|
67
|
-
"#<Dotify::
|
76
|
+
"#<Dotify::Dot filename: '#{@filename}' linked: #{linked?}>"
|
68
77
|
end
|
69
78
|
|
70
79
|
def linked_to_dotify?
|
data/lib/dotify/errors.rb
CHANGED
data/lib/dotify/filter.rb
CHANGED
@@ -5,30 +5,30 @@ module Dotify
|
|
5
5
|
class << self
|
6
6
|
|
7
7
|
def home
|
8
|
-
result =
|
8
|
+
result = dots(Config.home('.*'))
|
9
9
|
filter_ignore_files!(result, :dotfiles)
|
10
10
|
end
|
11
11
|
|
12
12
|
def dotify
|
13
|
-
result =
|
13
|
+
result = dots(Config.path('.*'))
|
14
14
|
filter_ignore_files!(result, :dotify)
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
filter_dot_directories! Dir[glob].map{ |file|
|
17
|
+
def dots(glob)
|
18
|
+
filter_dot_directories! Dir[glob].map{ |file| Dot.new(file) }
|
19
19
|
end
|
20
20
|
|
21
|
-
def filter_dot_directories!(
|
22
|
-
[*
|
21
|
+
def filter_dot_directories!(dots)
|
22
|
+
[*dots].delete_if { |f| %w[. ..].include? f.filename }
|
23
23
|
end
|
24
24
|
|
25
|
-
def filter_ignore_files!(
|
25
|
+
def filter_ignore_files!(dots, ignore)
|
26
26
|
ignoring = Config.ignore(ignore)
|
27
|
-
[*
|
27
|
+
[*dots].delete_if { |f| ignoring.include?(f.filename) }
|
28
28
|
end
|
29
29
|
|
30
|
-
def filenames(
|
31
|
-
|
30
|
+
def filenames(dots)
|
31
|
+
dots.map(&:filename)
|
32
32
|
end
|
33
33
|
|
34
34
|
end
|
data/lib/dotify/version.rb
CHANGED
data/spec/dotify/cli_spec.rb
CHANGED
@@ -7,25 +7,25 @@ module Dotify
|
|
7
7
|
let!(:cli) { CLI.new }
|
8
8
|
before do
|
9
9
|
Dotify.stub(:installed?).and_return true
|
10
|
-
vimrc =
|
10
|
+
vimrc = Dot.new('.zshrc')
|
11
11
|
vimrc.stub(:linked?).and_return(true)
|
12
|
-
bash_profile =
|
12
|
+
bash_profile = Dot.new('.bash_profile')
|
13
13
|
bash_profile.stub(:linked?).and_return(true)
|
14
|
-
gitconfig =
|
14
|
+
gitconfig = Dot.new('.gitconfig')
|
15
15
|
gitconfig.stub(:linked?).and_return(false)
|
16
|
-
zshrc =
|
16
|
+
zshrc = Dot.new('.zshrc')
|
17
17
|
zshrc.stub(:linked?).and_return(false)
|
18
18
|
Filter.stub(:home).and_return([vimrc, bash_profile, gitconfig, zshrc])
|
19
19
|
end
|
20
20
|
|
21
21
|
describe CLI, "#edit" do
|
22
|
-
let(:
|
22
|
+
let(:dot) { double('dot', :linked? => true, :dotify => '/tmp/dotify/.vimrc') }
|
23
23
|
before do
|
24
|
-
|
24
|
+
Dot.stub(:new).and_return(dot)
|
25
25
|
cli.stub(:exec)
|
26
26
|
end
|
27
27
|
it "should open the editor with the passed file" do
|
28
|
-
cli.should_receive(:exec).with([Config.editor,
|
28
|
+
cli.should_receive(:exec).with([Config.editor, dot.dotify].join(" "))
|
29
29
|
cli.edit('.vimrc')
|
30
30
|
end
|
31
31
|
it "should the editor with the passed file" do
|
@@ -34,8 +34,8 @@ module Dotify
|
|
34
34
|
cli.edit '.vimrc'
|
35
35
|
end
|
36
36
|
it "should not edit the file if it has not been linked" do
|
37
|
-
|
38
|
-
cli.should_receive(:say).with("'#{
|
37
|
+
dot.stub(:linked?).and_return false
|
38
|
+
cli.should_receive(:say).with("'#{dot}' has not been linked by Dotify. Please run `dotify link #{dot}` to edit this file.", :blue)
|
39
39
|
cli.edit('.vimrc')
|
40
40
|
end
|
41
41
|
end
|
@@ -59,7 +59,7 @@ module Dotify
|
|
59
59
|
cli.link
|
60
60
|
end
|
61
61
|
it "attempt to link one single file" do
|
62
|
-
cli.should_receive(:file_action).with(:link, an_instance_of(
|
62
|
+
cli.should_receive(:file_action).with(:link, an_instance_of(Dot), {})
|
63
63
|
cli.link('.vimrc')
|
64
64
|
end
|
65
65
|
it "should output a warning if Dotify is not installed" do
|
@@ -82,7 +82,7 @@ module Dotify
|
|
82
82
|
cli.unlink
|
83
83
|
end
|
84
84
|
it "attempt to link one single file" do
|
85
|
-
cli.should_receive(:file_action).with(:unlink, an_instance_of(
|
85
|
+
cli.should_receive(:file_action).with(:unlink, an_instance_of(Dot), {})
|
86
86
|
cli.unlink('.vimrc')
|
87
87
|
end
|
88
88
|
it "should output a warning if Dotify is not installed" do
|
@@ -6,62 +6,76 @@ module Dotify
|
|
6
6
|
let(:collection) { Collection.new }
|
7
7
|
let(:home_files) {
|
8
8
|
[
|
9
|
-
@bashrc = double('
|
10
|
-
@gitconfig = double('
|
11
|
-
@vimrc = double('
|
9
|
+
@bashrc = double('dot1', :filename => '.bashrc', :linked? => false),
|
10
|
+
@gitconfig = double('dot2', :filename => '.gitconfig', :linked? => false),
|
11
|
+
@vimrc = double('dot3', :filename => '.vimrc', :linked? => true),
|
12
12
|
]
|
13
13
|
}
|
14
14
|
describe "methods" do
|
15
|
-
%w[linked unlinked].each do |name|
|
15
|
+
%w[each linked unlinked].each do |name|
|
16
16
|
it "should respond to #{name}" do
|
17
17
|
collection.should respond_to name
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
describe "pulling Filter#home or Filter#dotify files" do
|
23
|
+
it "should raise an error when not specifying :dotfiles or :dotify" do
|
24
|
+
expect { Collection.new(:fake) }.to raise_error ArgumentError
|
25
|
+
end
|
26
|
+
it "should pull from Filter#home when default or dotfiles" do
|
27
|
+
Filter.should_receive(:home).twice
|
28
|
+
Collection.new(:dotfiles)
|
29
|
+
Collection.new
|
30
|
+
end
|
31
|
+
it "should pull from Filter#dotify when default or dotfiles" do
|
32
|
+
Filter.should_receive(:dotify).once
|
33
|
+
Collection.new(:dotify)
|
34
|
+
end
|
35
|
+
end
|
22
36
|
it "should pull the right files from Filter.home" do
|
23
37
|
files = [stub, stub, stub]
|
24
38
|
Filter.stub(:home).and_return files
|
25
|
-
collection.
|
39
|
+
collection.dots.should == files
|
26
40
|
end
|
27
41
|
|
28
42
|
describe Collection, "#linked" do
|
29
43
|
before do
|
30
|
-
collection.stub(:
|
44
|
+
collection.stub(:dots).and_return home_files
|
31
45
|
end
|
32
46
|
let(:linked) { collection.linked }
|
33
|
-
it "should return the right
|
47
|
+
it "should return the right Dots" do
|
34
48
|
linked.should include @vimrc
|
35
49
|
linked.should_not include @gitconfig
|
36
50
|
linked.should_not include @bashrc
|
37
51
|
end
|
38
|
-
it "should yield the correct
|
52
|
+
it "should yield the correct Dots" do
|
39
53
|
expect { |b| collection.linked.each(&b) }.to yield_successive_args(*linked)
|
40
54
|
end
|
41
55
|
end
|
42
56
|
|
43
57
|
describe Collection, "#unlinked" do
|
44
58
|
before do
|
45
|
-
collection.stub(:
|
59
|
+
collection.stub(:dots).and_return home_files
|
46
60
|
end
|
47
61
|
let(:unlinked) { collection.unlinked }
|
48
|
-
it "should return the right
|
62
|
+
it "should return the right Dots" do
|
49
63
|
unlinked.should include @gitconfig
|
50
64
|
unlinked.should include @bashrc
|
51
65
|
unlinked.should_not include @vimrc
|
52
66
|
end
|
53
|
-
it "should yield the correct
|
67
|
+
it "should yield the correct Dots" do
|
54
68
|
expect { |b| collection.unlinked.each(&b) }.to yield_successive_args(*unlinked)
|
55
69
|
end
|
56
70
|
end
|
57
71
|
|
58
|
-
it "should call #to_s on the
|
59
|
-
collection.
|
72
|
+
it "should call #to_s on the dots" do
|
73
|
+
collection.dots.should_receive(:to_s)
|
60
74
|
collection.to_s
|
61
75
|
end
|
62
76
|
|
63
|
-
it "should call #inspect on the
|
64
|
-
collection.
|
77
|
+
it "should call #inspect on the dots" do
|
78
|
+
collection.dots.each { |u| u.should_receive(:inspect) }
|
65
79
|
collection.inspect
|
66
80
|
end
|
67
81
|
|
data/spec/dotify/config_spec.rb
CHANGED
@@ -10,7 +10,7 @@ module Dotify
|
|
10
10
|
Config.stub(:file).and_return Config.home(".fake-dotrc")
|
11
11
|
expect { Config.retrieve }.not_to raise_error TypeError
|
12
12
|
end
|
13
|
-
context "
|
13
|
+
context "dot tests" do
|
14
14
|
before do
|
15
15
|
Config.instance_variable_set("@hash", nil)
|
16
16
|
File.stub(:exists?).with(Config.file).and_return true
|
@@ -19,6 +19,10 @@ module Dotify
|
|
19
19
|
YAML.stub(:load_file).with(Config.file).and_return({})
|
20
20
|
Config.retrieve.should == {}
|
21
21
|
end
|
22
|
+
it "should catch the TypeError and return an empty hash" do
|
23
|
+
YAML.stub(:load_file).with(Config.file).and_raise(TypeError)
|
24
|
+
Config.retrieve.should == {}
|
25
|
+
end
|
22
26
|
it "should return an the hash returned by YAML#load_file" do
|
23
27
|
YAML.stub(:load_file).and_return({ :test => 'example' })
|
24
28
|
Config.retrieve.should == { :test => 'example' }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'dotify/
|
2
|
+
require 'dotify/dot'
|
3
3
|
|
4
|
-
class
|
4
|
+
class DummyDot
|
5
5
|
def dotfile
|
6
6
|
'.dummy'
|
7
7
|
end
|
@@ -17,7 +17,7 @@ end
|
|
17
17
|
module Dotify
|
18
18
|
|
19
19
|
describe Actions do
|
20
|
-
let!(:dummy) {
|
20
|
+
let!(:dummy) { DummyDot.new }
|
21
21
|
subject { dummy }
|
22
22
|
before { dummy.extend(Actions) }
|
23
23
|
it { should respond_to :link }
|
@@ -49,6 +49,22 @@ module Dotify
|
|
49
49
|
subject.link
|
50
50
|
end
|
51
51
|
end
|
52
|
+
describe Actions, "#backup_and_link" do
|
53
|
+
it "should call the right FileUtils methods when the dotfile exists" do
|
54
|
+
File.stub(:exists?).with(subject.dotfile).and_return true
|
55
|
+
FileUtils.should_receive(:rm_rf).with("#{subject.dotfile}.bak", :verbose => false)
|
56
|
+
FileUtils.should_receive(:mv).with(subject.dotfile, "#{subject.dotfile}.bak", :verbose => false)
|
57
|
+
FileUtils.should_receive(:ln_sf).with(subject.dotify, subject.dotfile, :verbose => false)
|
58
|
+
subject.backup_and_link
|
59
|
+
end
|
60
|
+
it "should call the right FileUtils methods when the dotfile does not existexists" do
|
61
|
+
File.stub(:exists?).with(subject.dotfile).and_return false
|
62
|
+
FileUtils.should_not_receive(:rm_rf)
|
63
|
+
FileUtils.should_not_receive(:mv)
|
64
|
+
FileUtils.should_receive(:ln_sf).with(subject.dotify, subject.dotfile, :verbose => false)
|
65
|
+
subject.backup_and_link
|
66
|
+
end
|
67
|
+
end
|
52
68
|
describe Actions, "#unlink" do
|
53
69
|
it "should not do anything if the file is not linked" do
|
54
70
|
subject.stub(:linked?) { false }
|
@@ -66,11 +82,11 @@ module Dotify
|
|
66
82
|
end
|
67
83
|
end
|
68
84
|
end
|
69
|
-
describe
|
85
|
+
describe Dot do
|
70
86
|
|
71
87
|
describe "populates the attributes correctly" do
|
72
|
-
let(:
|
73
|
-
subject {
|
88
|
+
let(:dot) { Dot.new(".vimrc") }
|
89
|
+
subject { dot }
|
74
90
|
it { should respond_to :filename }
|
75
91
|
it { should respond_to :dotify }
|
76
92
|
it { should respond_to :dotfile }
|
@@ -79,85 +95,85 @@ module Dotify
|
|
79
95
|
it { should respond_to :linked }
|
80
96
|
|
81
97
|
it "should set the attributes properly" do
|
82
|
-
|
83
|
-
|
84
|
-
|
98
|
+
dot.filename.should == '.vimrc'
|
99
|
+
dot.dotify.should == '/tmp/home/.dotify/.vimrc'
|
100
|
+
dot.dotfile.should == '/tmp/home/.vimrc'
|
85
101
|
end
|
86
102
|
it "should puts the filename" do
|
87
|
-
|
103
|
+
dot.to_s.should == dot.filename
|
88
104
|
end
|
89
105
|
end
|
90
106
|
|
91
107
|
describe "existence in directories" do
|
92
|
-
let(:
|
108
|
+
let(:dot) { Dot.new(".bashrc") }
|
93
109
|
it "should check for the existence in the home directory" do
|
94
|
-
File.stub(:exists?).with(
|
95
|
-
|
110
|
+
File.stub(:exists?).with(dot.dotfile).and_return true
|
111
|
+
dot.in_home_dir?.should == true
|
96
112
|
end
|
97
113
|
it "should return false if the file is not in the home directory" do
|
98
|
-
File.stub(:exists?).with(
|
99
|
-
|
114
|
+
File.stub(:exists?).with(dot.dotfile).and_return false
|
115
|
+
dot.in_home_dir?.should_not == true
|
100
116
|
end
|
101
117
|
it "should check for the existence of the file in Dotify" do
|
102
|
-
File.stub(:exists?).with(
|
103
|
-
|
118
|
+
File.stub(:exists?).with(dot.dotify).and_return true
|
119
|
+
dot.in_dotify?.should == true
|
104
120
|
end
|
105
121
|
it "should return false if the file is not in Dotify" do
|
106
|
-
File.stub(:exists?).with(
|
107
|
-
|
122
|
+
File.stub(:exists?).with(dot.dotify).and_return false
|
123
|
+
dot.in_dotify?.should == false
|
108
124
|
end
|
109
125
|
end
|
110
126
|
|
111
|
-
describe
|
112
|
-
let(:
|
127
|
+
describe Dot, "#linked_to_dotify?" do
|
128
|
+
let(:dot) { Dot.new(".bashrc") }
|
113
129
|
it "should return false when an error is raised" do
|
114
|
-
|
115
|
-
|
130
|
+
dot.stub(:symlink).and_return NoSymlink
|
131
|
+
dot.linked_to_dotify?.should be_false
|
116
132
|
end
|
117
133
|
it "should return true if the dotfile is linked to the Dotify file" do
|
118
|
-
|
119
|
-
|
134
|
+
dot.stub(:symlink).and_return dot.dotify
|
135
|
+
dot.linked_to_dotify?.should be_true
|
120
136
|
end
|
121
137
|
it "should return false if the dotfile is not linked to the Dotify file" do
|
122
|
-
File.stub(:readlink).with(
|
123
|
-
|
138
|
+
File.stub(:readlink).with(dot.dotfile).and_return '/tmp/home/.another_file'
|
139
|
+
dot.linked_to_dotify?.should be_false
|
124
140
|
end
|
125
141
|
end
|
126
142
|
|
127
|
-
describe
|
128
|
-
let(:
|
143
|
+
describe Dot, "#linked?" do
|
144
|
+
let(:dot) { Dot.new(".bashrc") }
|
129
145
|
before do
|
130
|
-
|
146
|
+
dot.stub(:in_dotify?).and_return true # stub identical file check
|
131
147
|
end
|
132
148
|
it "should return true if all checks work" do
|
133
|
-
|
134
|
-
|
149
|
+
dot.stub(:linked_to_dotify?).and_return true # stub dotify file exist check
|
150
|
+
dot.linked?.should == true
|
135
151
|
end
|
136
152
|
it "should return false if one or more checks fail" do
|
137
|
-
|
138
|
-
|
153
|
+
dot.stub(:linked_to_dotify?).and_return false # stub dotify file exist check
|
154
|
+
dot.linked?.should == false
|
139
155
|
end
|
140
156
|
end
|
141
157
|
|
142
|
-
describe
|
143
|
-
let!(:
|
158
|
+
describe Dot, "#symlink" do
|
159
|
+
let!(:dot) { Dot.new(".symlinked") }
|
144
160
|
it "should return the symlink for the file" do
|
145
|
-
File.should_receive(:readlink).with(
|
146
|
-
|
161
|
+
File.should_receive(:readlink).with(dot.dotfile).once
|
162
|
+
dot.symlink
|
147
163
|
end
|
148
164
|
it "should return NoSymlink if error or no symlink" do
|
149
|
-
File.stub(:readlink).with(
|
150
|
-
expect {
|
151
|
-
|
165
|
+
File.stub(:readlink).with(dot.dotfile).and_raise(StandardError)
|
166
|
+
expect { dot.symlink }.not_to raise_error
|
167
|
+
dot.symlink.should == NoSymlink
|
152
168
|
end
|
153
169
|
end
|
154
170
|
|
155
|
-
describe "inspecting
|
171
|
+
describe "inspecting dot" do
|
156
172
|
it "should display properly" do
|
157
|
-
|
158
|
-
bash =
|
173
|
+
Dot.new(".zshrc").inspect.should == "#<Dotify::Dot filename: '.zshrc' linked: false>"
|
174
|
+
bash = Dot.new(".bashrc")
|
159
175
|
bash.stub(:linked?).and_return true
|
160
|
-
bash.inspect.should == "#<Dotify::
|
176
|
+
bash.inspect.should == "#<Dotify::Dot filename: '.bashrc' linked: true>"
|
161
177
|
|
162
178
|
end
|
163
179
|
end
|
data/spec/dotify/filter_spec.rb
CHANGED
@@ -4,17 +4,17 @@ module Dotify
|
|
4
4
|
describe Filter do
|
5
5
|
|
6
6
|
describe Filter, "#home" do
|
7
|
-
it "should call Filter#
|
8
|
-
Filter.should_receive(:
|
7
|
+
it "should call Filter#dots with the correct path" do
|
8
|
+
Filter.should_receive(:dots).with("/tmp/home/.*").once.and_return([])
|
9
9
|
Filter.home
|
10
10
|
end
|
11
11
|
it "should drop files that have been specified to be ignored" do
|
12
|
-
Filter.stub(:
|
12
|
+
Filter.stub(:dots) do
|
13
13
|
[
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
Dot.new('.zshrc'),
|
15
|
+
Dot.new('.bashrc'),
|
16
|
+
Dot.new('.vimrc'),
|
17
|
+
Dot.new('.gitconfig')
|
18
18
|
]
|
19
19
|
end
|
20
20
|
Config.stub(:ignore).with(:dotfiles).and_return %w[.zshrc .vimrc]
|
@@ -27,18 +27,18 @@ module Dotify
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe Filter, "#dotify" do
|
30
|
-
it "should call Filter#
|
31
|
-
Filter.should_receive(:
|
30
|
+
it "should call Filter#dots with the correct path" do
|
31
|
+
Filter.should_receive(:dots).with("/tmp/home/.dotify/.*").once.and_return([])
|
32
32
|
Filter.dotify
|
33
33
|
end
|
34
34
|
it "should drop files that have been specified to be ignored" do
|
35
|
-
Filter.stub(:
|
35
|
+
Filter.stub(:dots) do
|
36
36
|
[
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
Dot.new(".gitconfig"),
|
38
|
+
Dot.new('.vimrc'),
|
39
|
+
Dot.new('.zshrc'),
|
40
|
+
Dot.new('.bashrc'),
|
41
|
+
Dot.new('.fakefile')
|
42
42
|
]
|
43
43
|
end
|
44
44
|
Config.stub(:ignore).with(:dotify).and_return %w[.gitconfig .bashrc]
|
@@ -51,17 +51,17 @@ module Dotify
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe Filter, "#
|
54
|
+
describe Filter, "#dots" do
|
55
55
|
let(:glob) { '/spec/test/.*' }
|
56
56
|
it "should pull the glob of dotfiles from a directory" do
|
57
57
|
Dir.should_receive(:[]).with(glob).and_return(%w[. .. /spec/test/.vimrc /spec/test/.bashrc /spec/test/.zshrc])
|
58
|
-
Filter.
|
58
|
+
Filter.dots(glob)
|
59
59
|
end
|
60
60
|
describe "return values" do
|
61
61
|
before do
|
62
62
|
Dir.stub(:[]).with(glob).and_return(%w[. .. /spec/test/.vimrc /spec/test/.bashrc /spec/test/.zshrc])
|
63
63
|
end
|
64
|
-
let(:files) { Filter.
|
64
|
+
let(:files) { Filter.dots(glob) }
|
65
65
|
it "should return the right directories" do
|
66
66
|
f = files.map(&:filename)
|
67
67
|
f.should include '.vimrc'
|
@@ -78,9 +78,9 @@ module Dotify
|
|
78
78
|
|
79
79
|
describe Filter, "#filenames" do
|
80
80
|
let(:files) { [
|
81
|
-
|
81
|
+
Dot.new('.vimrc'), Dot.new('.bashrc'), Dot.new('.zshrc')
|
82
82
|
] }
|
83
|
-
it "return only the filenames of the
|
83
|
+
it "return only the filenames of the dots" do
|
84
84
|
result = Filter.filenames(files)
|
85
85
|
result.should include '.vimrc'
|
86
86
|
result.should include '.bashrc'
|
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.6.
|
4
|
+
version: 0.6.6
|
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-
|
12
|
+
date: 2012-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -198,16 +198,16 @@ files:
|
|
198
198
|
- lib/dotify/cli.rb
|
199
199
|
- lib/dotify/collection.rb
|
200
200
|
- lib/dotify/config.rb
|
201
|
+
- lib/dotify/dot.rb
|
201
202
|
- lib/dotify/errors.rb
|
202
203
|
- lib/dotify/filter.rb
|
203
|
-
- lib/dotify/unit.rb
|
204
204
|
- lib/dotify/version.rb
|
205
205
|
- lib/dotify/version_checker.rb
|
206
206
|
- spec/dotify/cli_spec.rb
|
207
207
|
- spec/dotify/collection_spec.rb
|
208
208
|
- spec/dotify/config_spec.rb
|
209
|
+
- spec/dotify/dot_spec.rb
|
209
210
|
- spec/dotify/filter_spec.rb
|
210
|
-
- spec/dotify/unit_spec.rb
|
211
211
|
- spec/dotify/version_checker_spec.rb
|
212
212
|
- spec/dotify_spec.rb
|
213
213
|
- spec/fixtures/.dotrc-default
|
@@ -248,8 +248,8 @@ test_files:
|
|
248
248
|
- spec/dotify/cli_spec.rb
|
249
249
|
- spec/dotify/collection_spec.rb
|
250
250
|
- spec/dotify/config_spec.rb
|
251
|
+
- spec/dotify/dot_spec.rb
|
251
252
|
- spec/dotify/filter_spec.rb
|
252
|
-
- spec/dotify/unit_spec.rb
|
253
253
|
- spec/dotify/version_checker_spec.rb
|
254
254
|
- spec/dotify_spec.rb
|
255
255
|
- spec/fixtures/.dotrc-default
|