dotify 0.5.1 → 0.6.0
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/Guardfile +9 -0
- data/README.md +23 -65
- data/dotify.gemspec +1 -0
- data/lib/dotify.rb +10 -2
- data/lib/dotify/cli.rb +49 -132
- data/lib/dotify/config.rb +7 -7
- data/lib/dotify/errors.rb +1 -0
- data/lib/dotify/files.rb +31 -36
- data/lib/dotify/list.rb +36 -0
- data/lib/dotify/unit.rb +91 -0
- data/lib/dotify/version.rb +1 -1
- data/spec/dotify/cli_spec.rb +65 -3
- data/spec/dotify/config_spec.rb +62 -53
- data/spec/dotify/files_spec.rb +86 -126
- data/spec/dotify/list_spec.rb +93 -0
- data/spec/dotify/unit_spec.rb +172 -0
- data/spec/dotify/version_checker_spec.rb +24 -23
- data/spec/spec_helper.rb +5 -0
- metadata +25 -5
- data/lib/dotify/file_list.rb +0 -41
- data/spec/dotify/file_list_spec.rb +0 -113
data/lib/dotify/errors.rb
CHANGED
data/lib/dotify/files.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'dotify'
|
2
1
|
require 'thor/actions'
|
3
2
|
require 'thor/shell'
|
4
3
|
|
@@ -7,55 +6,51 @@ Dotify::Config.load_config!
|
|
7
6
|
module Dotify
|
8
7
|
class Files
|
9
8
|
class << self
|
10
|
-
|
11
|
-
|
9
|
+
# All
|
10
|
+
#
|
11
|
+
# Pulls an array of Units from the home
|
12
|
+
# directory.
|
13
|
+
def all
|
14
|
+
@all ||= List.home
|
15
|
+
end
|
12
16
|
|
17
|
+
# Linked files are those files which have a
|
18
|
+
# symbolic link pointing to the Dotify file.
|
13
19
|
def linked
|
14
|
-
|
15
|
-
return
|
16
|
-
|
20
|
+
links = self.all.select { |f| f.linked? }
|
21
|
+
return links unless block_given?
|
22
|
+
links.each {|u| yield u }
|
17
23
|
end
|
18
24
|
|
25
|
+
# Unlinked files are, of course, the opposite
|
26
|
+
# of linked files. These are Dotify files which
|
27
|
+
# Have no home dir files that are linked to them.
|
19
28
|
def unlinked
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
return unlinked unless block_given?
|
24
|
-
unlinked.each {|u| yield(u, filename(u)) }
|
25
|
-
end
|
26
|
-
|
27
|
-
def installed
|
28
|
-
linked = self.linked.map { |f| filename(f) }
|
29
|
-
installed = FileList.home.select do |d|
|
30
|
-
linked.include?(filename(d))
|
31
|
-
end
|
32
|
-
return installed unless block_given?
|
33
|
-
installed.each {|i| yield(i, filename(i)) }
|
29
|
+
unl = self.all.select { |f| !f.linked? }
|
30
|
+
return unl unless block_given?
|
31
|
+
unl.each {|u| yield u }
|
34
32
|
end
|
35
33
|
|
34
|
+
# Uninstalled dotfiles are the dotfiles in the home
|
35
|
+
# directory that have not been loaded into Dotify or
|
36
|
+
# linked to the corresponding Dotify path.
|
36
37
|
def uninstalled
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
return installed unless block_given?
|
42
|
-
installed.each {|i| yield(i, filename(i)) }
|
38
|
+
uni = self.all.select { |f| !f.added? && !f.linked? }
|
39
|
+
return uni unless block_given?
|
40
|
+
uni.each {|u| yield u }
|
43
41
|
end
|
44
42
|
|
45
43
|
def filename(file)
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
def template?(file)
|
50
|
-
filename(file).match(/(tt|erb)\Z/) ? true : false
|
44
|
+
File.basename(file)
|
51
45
|
end
|
52
46
|
|
53
|
-
def dotfile(file)
|
54
|
-
File.join(Config.home, filename(file))
|
47
|
+
def dotfile(file = nil)
|
48
|
+
file.nil? ? Config.home : File.join(Config.home, filename(file))
|
55
49
|
end
|
50
|
+
alias :home :dotfile
|
56
51
|
|
57
|
-
def dotify(file)
|
58
|
-
File.join(Config.path, filename(file))
|
52
|
+
def dotify(file = nil)
|
53
|
+
file.nil? ? Config.path : File.join(Config.path, filename(file))
|
59
54
|
end
|
60
55
|
|
61
56
|
def link_dotfile(file)
|
@@ -63,7 +58,7 @@ module Dotify
|
|
63
58
|
end
|
64
59
|
|
65
60
|
def unlink_dotfile(file)
|
66
|
-
FileUtils.rm_rf
|
61
|
+
FileUtils.rm_rf dotfile(file)
|
67
62
|
end
|
68
63
|
|
69
64
|
end
|
data/lib/dotify/list.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'dotify'
|
2
|
+
|
3
|
+
module Dotify
|
4
|
+
class List
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def home
|
8
|
+
result = units(Files.dotfile('.*'))
|
9
|
+
filter_ignore_files!(result, :dotfiles)
|
10
|
+
end
|
11
|
+
|
12
|
+
def dotify
|
13
|
+
result = units(Files.dotify('.*'))
|
14
|
+
filter_ignore_files!(result, :dotify)
|
15
|
+
end
|
16
|
+
|
17
|
+
def units(glob)
|
18
|
+
filter_dot_directories! Dir[glob].map{ |file| Unit.new(file) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def filter_dot_directories!(units)
|
22
|
+
[*units].delete_if { |f| %w[. ..].include? f.filename }
|
23
|
+
end
|
24
|
+
|
25
|
+
def filter_ignore_files!(units, ignore)
|
26
|
+
ignoring = Config.ignore(ignore)
|
27
|
+
[*units].delete_if { |f| ignoring.include?(f.filename) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def filenames(units)
|
31
|
+
units.map(&:filename)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/dotify/unit.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'dotify/errors'
|
2
|
+
|
3
|
+
module Dotify
|
4
|
+
|
5
|
+
class NoSymlink; end
|
6
|
+
|
7
|
+
module Actions
|
8
|
+
|
9
|
+
# Link the file from the home directory into Dotify
|
10
|
+
def link
|
11
|
+
return false if !in_home_dir? || linked?
|
12
|
+
if in_home_dir? && !in_dotify?
|
13
|
+
FileUtils.cp_r(self.dotfile, self.dotify, :verbose => false)
|
14
|
+
end
|
15
|
+
FileUtils.rm_rf(self.dotfile, :verbose => false)
|
16
|
+
FileUtils.ln_sf(self.dotify, self.dotfile, :verbose => false)
|
17
|
+
return true
|
18
|
+
end
|
19
|
+
|
20
|
+
# Unlink the file from Dotify and replace it into the home directory.
|
21
|
+
def unlink
|
22
|
+
return false unless linked?
|
23
|
+
FileUtils.rm_rf(self.dotfile, :verbose => false)
|
24
|
+
FileUtils.cp_r(self.dotify, self.dotfile, :verbose => false)
|
25
|
+
FileUtils.rm_rf(self.dotify, :verbose => false)
|
26
|
+
return true
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
class Unit
|
32
|
+
|
33
|
+
include Actions
|
34
|
+
|
35
|
+
# Attributes on the file itself
|
36
|
+
attr_accessor :filename, :dotify, :dotfile
|
37
|
+
|
38
|
+
# Attributes about the file's status in the filesystem
|
39
|
+
attr_accessor :linked, :added
|
40
|
+
|
41
|
+
def initialize(file)
|
42
|
+
@filename = File.basename(file)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
|
46
|
+
def dotify
|
47
|
+
@dotify ||= Files.dotify(@filename)
|
48
|
+
end
|
49
|
+
|
50
|
+
def dotfile
|
51
|
+
@dotfile ||= Files.dotfile(@filename)
|
52
|
+
end
|
53
|
+
|
54
|
+
def added?
|
55
|
+
in_dotify? && !linked_to_dotify?
|
56
|
+
end
|
57
|
+
|
58
|
+
def linked?
|
59
|
+
in_dotify? && linked_to_dotify?
|
60
|
+
end
|
61
|
+
|
62
|
+
def in_dotify?
|
63
|
+
File.exists?(dotify)
|
64
|
+
end
|
65
|
+
|
66
|
+
def in_home_dir?
|
67
|
+
File.exists?(dotfile)
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_s
|
71
|
+
self.filename
|
72
|
+
end
|
73
|
+
|
74
|
+
def inspect
|
75
|
+
"#<Dotify::Unit @filename='#{@filename}' @added=#{added?} @linked=#{linked?}>"
|
76
|
+
end
|
77
|
+
|
78
|
+
def linked_to_dotify?
|
79
|
+
self.symlink == dotify
|
80
|
+
end
|
81
|
+
|
82
|
+
def symlink
|
83
|
+
begin
|
84
|
+
File.readlink dotfile
|
85
|
+
rescue
|
86
|
+
NoSymlink
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
data/lib/dotify/version.rb
CHANGED
data/spec/dotify/cli_spec.rb
CHANGED
@@ -1,7 +1,69 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'dotify/cli'
|
3
2
|
require 'thor'
|
4
3
|
|
5
|
-
|
6
|
-
|
4
|
+
module Dotify
|
5
|
+
describe CLI do
|
6
|
+
let!(:cli) { CLI.new }
|
7
|
+
before do
|
8
|
+
Dotify.stub(:installed?).and_return true
|
9
|
+
cli.stub(:exec)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe CLI, "#edit" do
|
13
|
+
let(:unit) { double('unit', :linked? => true, :dotify => '/tmp/dotify/.vimrc') }
|
14
|
+
before { Unit.stub(:new).and_return(unit) }
|
15
|
+
it "should open the editor with the passed file" do
|
16
|
+
cli.should_receive(:exec).with([Config.editor, unit.dotify].join(" "))
|
17
|
+
cli.edit('.vimrc')
|
18
|
+
end
|
19
|
+
it "should the editor with the passed file" do
|
20
|
+
cli.should_receive(:save)
|
21
|
+
cli.stub(:options).and_return({ :save => true })
|
22
|
+
cli.edit '.vimrc'
|
23
|
+
end
|
24
|
+
it "should not edit the file if it has not been linked" do
|
25
|
+
unit.stub(:linked?).and_return false
|
26
|
+
cli.should_receive(:say).with("'#{unit}' has not been linked by Dotify. Please run `dotify link #{unit}` to edit this file.", :blue)
|
27
|
+
cli.edit('.vimrc')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe CLI, "#link" do
|
32
|
+
it "should loop through all unlinked files" do
|
33
|
+
Files.should_receive(:unlinked)
|
34
|
+
cli.link
|
35
|
+
end
|
36
|
+
it "should relink all of the files located in Dotify" do
|
37
|
+
Files.should_not_receive(:unlinked)
|
38
|
+
Files.should_receive(:linked)
|
39
|
+
cli.stub(:options).and_return({ :relink => true })
|
40
|
+
cli.link
|
41
|
+
end
|
42
|
+
it "attempt to link one single file" do
|
43
|
+
cli.should_receive(:link_file).with(an_instance_of(Unit), {})
|
44
|
+
cli.link('.vimrc')
|
45
|
+
end
|
46
|
+
it "should output a warning if Dotify is not installed" do
|
47
|
+
Dotify.stub(:installed?).and_return false
|
48
|
+
cli.should_receive(:not_setup_warning).once
|
49
|
+
cli.link
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe CLI, "#unlink" do
|
54
|
+
it "should loop through all unlinked files" do
|
55
|
+
Files.should_receive(:linked)
|
56
|
+
cli.unlink
|
57
|
+
end
|
58
|
+
it "attempt to link one single file" do
|
59
|
+
cli.should_receive(:unlink_file).with(an_instance_of(Unit), {})
|
60
|
+
cli.unlink('.vimrc')
|
61
|
+
end
|
62
|
+
it "should output a warning if Dotify is not installed" do
|
63
|
+
Dotify.stub(:installed?).and_return false
|
64
|
+
cli.should_receive(:not_setup_warning).once
|
65
|
+
cli.unlink
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
7
69
|
end
|
data/spec/dotify/config_spec.rb
CHANGED
@@ -1,67 +1,76 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'dotify/errors'
|
3
|
-
require 'dotify/config'
|
4
2
|
|
5
|
-
|
6
|
-
describe
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
describe "options" do
|
17
|
-
before do
|
18
|
-
Dotify::Config.stub(:config) do
|
19
|
-
{ :ignore => { :dotfiles => %w[.gemrc], :dotify => %w[.gitmodule] } }
|
3
|
+
module Dotify
|
4
|
+
describe Config do
|
5
|
+
before {
|
6
|
+
Config.unstub(:home)
|
7
|
+
Thor::Util.stub(:user_home).and_return '/home/tmp'
|
8
|
+
}
|
9
|
+
describe Config, "#installed?" do
|
10
|
+
it "should return true if Dotify has been setup" do
|
11
|
+
File.should_receive(:exists?).with(Config.path).and_return(true)
|
12
|
+
File.should_receive(:directory?).with(Config.path).and_return(true)
|
13
|
+
Config.installed?.should == true
|
20
14
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
it "should be able to show the dotify path" do
|
26
|
-
Dotify::Config.path.should == File.join(Dotify::Config.home, '.dotify')
|
27
|
-
end
|
28
|
-
it "should set a default editor" do
|
29
|
-
Dotify::Config.editor.should == Dotify::Config::EDITOR
|
30
|
-
end
|
31
|
-
it "should allow a custom editor" do
|
32
|
-
Dotify::Config.stub(:config) do
|
33
|
-
{ :editor => 'subl' }
|
15
|
+
it "should return false if Dotify has not been setup" do
|
16
|
+
File.should_receive(:exists?).with(Config.path).and_return(true)
|
17
|
+
File.should_receive(:directory?).with(Config.path).and_return(false)
|
18
|
+
Config.installed?.should == false
|
34
19
|
end
|
35
|
-
Dotify::Config.editor.should == 'subl'
|
36
20
|
end
|
37
|
-
end
|
38
21
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
22
|
+
describe Config, "#home" do
|
23
|
+
it "should return the home directory when called without a filename" do
|
24
|
+
Config.home.should == Thor::Util.user_home
|
25
|
+
end
|
43
26
|
end
|
44
|
-
end
|
45
27
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
28
|
+
describe "options" do
|
29
|
+
before do
|
30
|
+
Config.stub(:config) do
|
31
|
+
{ :ignore => { :dotfiles => %w[.gemrc], :dotify => %w[.gitmodule] } }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
it "should be able to show the dotify path" do
|
35
|
+
Config.path.should == File.join(Config.home, '.dotify')
|
36
|
+
end
|
37
|
+
it "should set a default editor" do
|
38
|
+
Config.editor.should == Config::EDITOR
|
39
|
+
end
|
40
|
+
it "should allow a custom editor" do
|
41
|
+
Config.stub(:config) do
|
42
|
+
{ :editor => 'subl' }
|
43
|
+
end
|
44
|
+
Config.editor.should == 'subl'
|
50
45
|
end
|
51
46
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
Dotify::Config.ignore(:dotfiles).should include '.Trash'
|
58
|
-
Dotify::Config.ignore(:dotfiles).should include '.dotify'
|
59
|
-
end
|
60
|
-
it "should retrieve the list of dotfiles to ignore in the home directory" do
|
61
|
-
Dotify::Config.ignore(:dotfiles).should include '.gemrc'
|
47
|
+
|
48
|
+
describe Config, "#file" do
|
49
|
+
it "should return the right page" do
|
50
|
+
Config.file.should == '/home/tmp/.dotrc'
|
51
|
+
end
|
62
52
|
end
|
63
|
-
|
64
|
-
|
53
|
+
|
54
|
+
describe "ignore files" do
|
55
|
+
before do
|
56
|
+
Config.stub(:config) do
|
57
|
+
{ :ignore => { :dotfiles => %w[.gemrc], :dotify => %w[.gitmodule] } }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
it "should have a default set of dotfiles" do
|
61
|
+
Config.stub(:config).and_return({})
|
62
|
+
Config.ignore(:dotify).should include '.git'
|
63
|
+
Config.ignore(:dotify).should include '.gitmodule'
|
64
|
+
Config.ignore(:dotfiles).should include '.dropbox'
|
65
|
+
Config.ignore(:dotfiles).should include '.Trash'
|
66
|
+
Config.ignore(:dotfiles).should include '.dotify'
|
67
|
+
end
|
68
|
+
it "should retrieve the list of dotfiles to ignore in the home directory" do
|
69
|
+
Config.ignore(:dotfiles).should include '.gemrc'
|
70
|
+
end
|
71
|
+
it "should retrieve the list of dotify files to ignore" do
|
72
|
+
Config.ignore(:dotify).should include '.gitmodule'
|
73
|
+
end
|
65
74
|
end
|
66
75
|
end
|
67
76
|
end
|
data/spec/dotify/files_spec.rb
CHANGED
@@ -1,156 +1,116 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'dotify/config'
|
3
|
-
require 'dotify/files'
|
4
|
-
require 'fileutils'
|
5
2
|
|
6
|
-
|
3
|
+
module Dotify
|
4
|
+
describe Files do
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
Dotify::Files.filename("some/random/path/to/file.txt").should == 'file.txt'
|
22
|
-
Dotify::Files.filename("another/path/no_extension").should == 'no_extension'
|
23
|
-
end
|
24
|
-
|
25
|
-
describe Dotify::Files, "#dotfile" do
|
26
|
-
it "should return the path to the file when it is linked in the root" do
|
27
|
-
Dotify::Config.stub(:home).and_return '/home'
|
28
|
-
Dotify::Files.dotfile(".vimrc").should == '/home/.vimrc'
|
29
|
-
Dotify::Files.dotfile("/spec/home/.bashrc").should == '/home/.bashrc'
|
6
|
+
let(:home_files) {
|
7
|
+
[
|
8
|
+
@bashrc = double('unit1', :filename => '.bashrc', :added? => true, :linked? => false),
|
9
|
+
@gitconfig = double('unit2', :filename => '.gitconfig', :added? => false, :linked? => false),
|
10
|
+
@vimrc = double('unit3', :filename => '.vimrc', :added? => true, :linked? => true),
|
11
|
+
]
|
12
|
+
}
|
13
|
+
describe "methods" do
|
14
|
+
%w[all linked unlinked uninstalled].each do |name|
|
15
|
+
it "should respond to #{name}" do
|
16
|
+
Files.should respond_to name
|
17
|
+
end
|
18
|
+
end
|
30
19
|
end
|
31
|
-
end
|
32
20
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
21
|
+
describe Files, "#all" do
|
22
|
+
it "should pull the right files from List.home" do
|
23
|
+
files = [stub, stub, stub]
|
24
|
+
List.stub(:home).and_return files
|
25
|
+
Files.all.should == files
|
26
|
+
end
|
38
27
|
end
|
39
|
-
end
|
40
28
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
29
|
+
describe Files, "#linked" do
|
30
|
+
before do
|
31
|
+
Files.stub(:all).and_return home_files
|
32
|
+
end
|
33
|
+
let(:filenames) { Files.linked }
|
34
|
+
it "should return the right Units" do
|
35
|
+
filenames.should include @vimrc
|
36
|
+
filenames.should_not include @gitconfig
|
37
|
+
filenames.should_not include @bashrc
|
38
|
+
end
|
39
|
+
it "should yield the correct Units" do
|
40
|
+
expect { |b| Files.linked(&b) }.to yield_successive_args(*filenames)
|
45
41
|
end
|
46
42
|
end
|
47
|
-
let!(:files) { Dotify::Files.linked }
|
48
|
-
it "should return the list of dotfiles in the dotify path" do
|
49
|
-
files.map! { |f| Dotify::Files.filename(f) }
|
50
|
-
files.should include '.bash_profile'
|
51
|
-
files.should include '.bashrc'
|
52
|
-
files.should include '.zshrc'
|
53
|
-
end
|
54
|
-
it "shoud yield the files if a block is given" do
|
55
|
-
yields = files.map { |f| [f, Dotify::Files.filename(f)] }
|
56
|
-
expect { |b| Dotify::Files.linked(&b) }.to yield_successive_args(*yields)
|
57
|
-
end
|
58
|
-
end
|
59
43
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
['/spec/test/.vimrc', '/spec/test/.bashrc', '/spec/test/.zshrc']
|
44
|
+
describe Files, "#unlinked" do
|
45
|
+
before do
|
46
|
+
Files.stub(:all).and_return home_files
|
64
47
|
end
|
65
|
-
|
66
|
-
|
48
|
+
let(:filenames) { Files.unlinked }
|
49
|
+
it "should return the right Units" do
|
50
|
+
filenames.should include @gitconfig
|
51
|
+
filenames.should include @bashrc
|
52
|
+
filenames.should_not include @vimrc
|
53
|
+
end
|
54
|
+
it "should yield the correct Units" do
|
55
|
+
expect { |b| Files.unlinked(&b) }.to yield_successive_args(*filenames)
|
67
56
|
end
|
68
57
|
end
|
69
|
-
it "should return the list of unlinked dotfiles in the root path" do
|
70
|
-
unlinked = Dotify::Files.unlinked.map { |u| Dotify::Files.filename(u) }
|
71
|
-
unlinked.should include '.vimrc'
|
72
|
-
unlinked.should_not include '.bashrc'
|
73
|
-
end
|
74
|
-
it "shoud yield the unlinked files if a block is given" do
|
75
|
-
unlinked = Dotify::Files.unlinked.map { |u| [u, Dotify::Files.filename(u)] }
|
76
|
-
expect { |b| Dotify::Files.unlinked(&b) }.to yield_successive_args(*unlinked)
|
77
|
-
end
|
78
|
-
end
|
79
58
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
%w[/spec/test/.zshrc /spec/test/.bashrc /spec/test/.vimrc /spec/test/.dotify]
|
59
|
+
describe Files, "#uninstalled" do
|
60
|
+
before do
|
61
|
+
Files.stub(:all).and_return home_files
|
84
62
|
end
|
85
|
-
|
86
|
-
|
63
|
+
let(:filenames) { Files.uninstalled }
|
64
|
+
it "should return the right Units" do
|
65
|
+
filenames.should include @gitconfig
|
66
|
+
filenames.should_not include @bashrc
|
67
|
+
filenames.should_not include @vimrc
|
68
|
+
end
|
69
|
+
it "should yield the correct Units" do
|
70
|
+
expect { |b| Files.uninstalled(&b) }.to yield_successive_args(*filenames)
|
87
71
|
end
|
88
72
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
installed.should_not include '.zshrc'
|
94
|
-
installed.should_not include '.dotify'
|
95
|
-
end
|
96
|
-
it "shoud yield the installed files if a block is given" do
|
97
|
-
installed = Dotify::Files.installed.map { |i| [i, Dotify::Files.filename(i)] }
|
98
|
-
expect { |b| Dotify::Files.installed(&b) }.to yield_successive_args(*installed)
|
73
|
+
|
74
|
+
it "should split a filename correct" do
|
75
|
+
Files.filename("some/random/path/to/file.txt").should == 'file.txt'
|
76
|
+
Files.filename("another/path/no_extension").should == 'no_extension'
|
99
77
|
end
|
100
|
-
end
|
101
78
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
%w[/spec/test/.zshrc /spec/test/.bashrc /spec/test/.vimrc /spec/test/.dotify]
|
79
|
+
describe Files, "#home" do
|
80
|
+
it "should point to the home directory" do
|
81
|
+
Files.home.should == '/tmp/home'
|
106
82
|
end
|
107
|
-
|
108
|
-
|
83
|
+
it "should return a absolute path to the file in the home directory" do
|
84
|
+
Files.home(".vimrc").should == '/tmp/home/.vimrc'
|
85
|
+
Files.home("/spec/home/.bashrc").should == '/tmp/home/.bashrc'
|
109
86
|
end
|
110
87
|
end
|
111
|
-
it "should return the list of uninstalled dotfiles in the root path" do
|
112
|
-
uninstalled = Dotify::Files.uninstalled.map { |i| Dotify::Files.filename(i) }
|
113
|
-
uninstalled.should_not include '.zshrc'
|
114
|
-
uninstalled.should_not include '.bashrc'
|
115
|
-
uninstalled.should include '.pryrc'
|
116
|
-
uninstalled.should include '.dropbox'
|
117
|
-
end
|
118
|
-
it "shoud yield the installed files if a block is given" do
|
119
|
-
uninstalled = Dotify::Files.uninstalled.map { |i| [i, Dotify::Files.filename(i)] }
|
120
|
-
expect { |b| Dotify::Files.uninstalled(&b) }.to yield_successive_args(*uninstalled)
|
121
|
-
end
|
122
|
-
end
|
123
88
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
Dotify::Files.template?(".tt.testing").should == false
|
133
|
-
Dotify::Files.template?("erbit.txt").should == false
|
134
|
-
Dotify::Files.template?(".erb.erbit.txt").should == false
|
135
|
-
Dotify::Files.template?("/Users/fake/path/to/testing.txt").should == false
|
136
|
-
Dotify::Files.template?("/Users/another/fake/path/to/testing.rb").should == false
|
89
|
+
describe Files, "#dotify" do
|
90
|
+
it "should point to the Dotify directory" do
|
91
|
+
Files.dotify.should == '/tmp/home/.dotify'
|
92
|
+
end
|
93
|
+
it "should return a absolute path to the file in Dotify" do
|
94
|
+
Files.dotify(".vimrc").should == '/tmp/home/.dotify/.vimrc'
|
95
|
+
Files.dotify("/spec/home/.bashrc").should == '/tmp/home/.dotify/.bashrc'
|
96
|
+
end
|
137
97
|
end
|
138
|
-
end
|
139
98
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
99
|
+
describe Files, "#link_dotfile" do
|
100
|
+
it "should receive a file and link it into the root path" do
|
101
|
+
first = File.join(Config.path, ".vimrc")
|
102
|
+
FileUtils.should_receive(:ln_s).with(Files.filename(first), Config.home).once
|
103
|
+
Files.link_dotfile first
|
104
|
+
end
|
145
105
|
end
|
146
|
-
end
|
147
106
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
107
|
+
describe Files, "#unlink_dotfile" do
|
108
|
+
it "should receive a file and remove it from the root" do
|
109
|
+
first = "/spec/test/.file"
|
110
|
+
FileUtils.stub(:rm_rf).with(File.join(Config.home, Files.filename(first))).once
|
111
|
+
Files.unlink_dotfile first
|
112
|
+
FileUtils.unstub(:rm_rf)
|
113
|
+
end
|
154
114
|
end
|
155
115
|
end
|
156
116
|
end
|