dotify 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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::Unit.new(file).link }
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
@@ -8,7 +8,7 @@ module Dotify
8
8
  autoload :Config, 'dotify/config'
9
9
  autoload :Collection, 'dotify/collection'
10
10
  autoload :Filter, 'dotify/filter'
11
- autoload :Unit, 'dotify/unit'
11
+ autoload :Dot, 'dotify/dot'
12
12
  autoload :CLI, 'dotify/cli'
13
13
 
14
14
  def self.installed?
@@ -46,10 +46,10 @@ module Dotify
46
46
  say message, :yellow, :verbose => options[:verbose]
47
47
  repo.commit(message)
48
48
  else
49
- say "No files have been changed in Dotify.", :blue
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
- say 'Pushing up to Github...', :blue
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
- say "Successfully pushed!", :blue
60
+ inform "Successfully pushed!"
61
61
  end
62
62
  else
63
- say 'Dotify has nothing to save.', :blue
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
- say "Dotify is managing #{Dotify.collection.linked.count} files:\n", :blue
70
- Dotify.collection.linked.each do |unit|
71
- say " * #{unit.filename}", :yellow
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 = Unit.new(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
- say "'#{file}' has not been linked by Dotify. Please run `dotify link #{file}` to edit this file.", :blue
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
- say " Your Version: #{Dotify.version}", :blue
96
- say " Latest Version: #{VersionChecker.version}", :blue
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
- say "Your version of Dotify is up to date: #{Dotify.version}", :blue
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
- say "Editing config file...", :blue
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
- say "Config file updated.", :blue
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, Unit.new(file), options unless file.nil?
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, Unit.new(file), options unless file.nil?
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
- no_tasks do
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 say "'#{file.dotfile}' does not exist.", :blue unless file.in_home_dir?
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 say "'#{file}' does not exist in Dotify.", :blue unless file.linked?
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
@@ -3,17 +3,22 @@ module Dotify
3
3
 
4
4
  include Enumerable
5
5
 
6
- attr_accessor :units
6
+ attr_accessor :dots
7
7
 
8
- # Pulls an array of Units from the home
8
+ # Pulls an array of Dots from the home
9
9
  # directory.
10
- def initialize
11
- @units ||= Filter.home
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
- units.each(&block)
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
- units.to_s
38
+ dots.to_s
34
39
  end
35
40
 
36
41
  def inspect
37
- units.map(&:inspect)
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 Unit
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::Unit filename: '#{@filename}' linked: #{linked?}>"
76
+ "#<Dotify::Dot filename: '#{@filename}' linked: #{linked?}>"
68
77
  end
69
78
 
70
79
  def linked_to_dotify?
@@ -1,4 +1,4 @@
1
1
  module Dotify
2
2
  class NonValidShell < StandardError; end
3
- class UnitDoesNotExist < StandardError; end
3
+ class DotDoesNotExist < StandardError; end
4
4
  end
@@ -5,30 +5,30 @@ module Dotify
5
5
  class << self
6
6
 
7
7
  def home
8
- result = units(Config.home('.*'))
8
+ result = dots(Config.home('.*'))
9
9
  filter_ignore_files!(result, :dotfiles)
10
10
  end
11
11
 
12
12
  def dotify
13
- result = units(Config.path('.*'))
13
+ result = dots(Config.path('.*'))
14
14
  filter_ignore_files!(result, :dotify)
15
15
  end
16
16
 
17
- def units(glob)
18
- filter_dot_directories! Dir[glob].map{ |file| Unit.new(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!(units)
22
- [*units].delete_if { |f| %w[. ..].include? f.filename }
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!(units, ignore)
25
+ def filter_ignore_files!(dots, ignore)
26
26
  ignoring = Config.ignore(ignore)
27
- [*units].delete_if { |f| ignoring.include?(f.filename) }
27
+ [*dots].delete_if { |f| ignoring.include?(f.filename) }
28
28
  end
29
29
 
30
- def filenames(units)
31
- units.map(&:filename)
30
+ def filenames(dots)
31
+ dots.map(&:filename)
32
32
  end
33
33
 
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module Dotify
2
- VERSION = "0.6.5"
2
+ VERSION = "0.6.6"
3
3
  end
@@ -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 = Unit.new('.zshrc')
10
+ vimrc = Dot.new('.zshrc')
11
11
  vimrc.stub(:linked?).and_return(true)
12
- bash_profile = Unit.new('.bash_profile')
12
+ bash_profile = Dot.new('.bash_profile')
13
13
  bash_profile.stub(:linked?).and_return(true)
14
- gitconfig = Unit.new('.gitconfig')
14
+ gitconfig = Dot.new('.gitconfig')
15
15
  gitconfig.stub(:linked?).and_return(false)
16
- zshrc = Unit.new('.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(:unit) { double('unit', :linked? => true, :dotify => '/tmp/dotify/.vimrc') }
22
+ let(:dot) { double('dot', :linked? => true, :dotify => '/tmp/dotify/.vimrc') }
23
23
  before do
24
- Unit.stub(:new).and_return(unit)
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, unit.dotify].join(" "))
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
- unit.stub(:linked?).and_return false
38
- cli.should_receive(:say).with("'#{unit}' has not been linked by Dotify. Please run `dotify link #{unit}` to edit this file.", :blue)
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(Unit), {})
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(Unit), {})
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('unit1', :filename => '.bashrc', :linked? => false),
10
- @gitconfig = double('unit2', :filename => '.gitconfig', :linked? => false),
11
- @vimrc = double('unit3', :filename => '.vimrc', :linked? => true),
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.units.should == files
39
+ collection.dots.should == files
26
40
  end
27
41
 
28
42
  describe Collection, "#linked" do
29
43
  before do
30
- collection.stub(:units).and_return home_files
44
+ collection.stub(:dots).and_return home_files
31
45
  end
32
46
  let(:linked) { collection.linked }
33
- it "should return the right Units" do
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 Units" do
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(:units).and_return home_files
59
+ collection.stub(:dots).and_return home_files
46
60
  end
47
61
  let(:unlinked) { collection.unlinked }
48
- it "should return the right Units" do
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 Units" do
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 units" do
59
- collection.units.should_receive(:to_s)
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 units" do
64
- collection.units.each { |u| u.should_receive(:inspect) }
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
 
@@ -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 "unit tests" do
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/unit'
2
+ require 'dotify/dot'
3
3
 
4
- class DummyUnit
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) { DummyUnit.new }
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 Unit do
85
+ describe Dot do
70
86
 
71
87
  describe "populates the attributes correctly" do
72
- let(:unit) { Unit.new(".vimrc") }
73
- subject { unit }
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
- unit.filename.should == '.vimrc'
83
- unit.dotify.should == '/tmp/home/.dotify/.vimrc'
84
- unit.dotfile.should == '/tmp/home/.vimrc'
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
- unit.to_s.should == unit.filename
103
+ dot.to_s.should == dot.filename
88
104
  end
89
105
  end
90
106
 
91
107
  describe "existence in directories" do
92
- let(:unit) { Unit.new(".bashrc") }
108
+ let(:dot) { Dot.new(".bashrc") }
93
109
  it "should check for the existence in the home directory" do
94
- File.stub(:exists?).with(unit.dotfile).and_return true
95
- unit.in_home_dir?.should == true
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(unit.dotfile).and_return false
99
- unit.in_home_dir?.should_not == true
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(unit.dotify).and_return true
103
- unit.in_dotify?.should == true
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(unit.dotify).and_return false
107
- unit.in_dotify?.should == false
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 Unit, "#linked_to_dotify?" do
112
- let(:unit) { Unit.new(".bashrc") }
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
- unit.stub(:symlink).and_return NoSymlink
115
- unit.linked_to_dotify?.should be_false
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
- unit.stub(:symlink).and_return unit.dotify
119
- unit.linked_to_dotify?.should be_true
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(unit.dotfile).and_return '/tmp/home/.another_file'
123
- unit.linked_to_dotify?.should be_false
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 Unit, "#linked?" do
128
- let(:unit) { Unit.new(".bashrc") }
143
+ describe Dot, "#linked?" do
144
+ let(:dot) { Dot.new(".bashrc") }
129
145
  before do
130
- unit.stub(:in_dotify?).and_return true # stub identical file check
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
- unit.stub(:linked_to_dotify?).and_return true # stub dotify file exist check
134
- unit.linked?.should == true
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
- unit.stub(:linked_to_dotify?).and_return false # stub dotify file exist check
138
- unit.linked?.should == false
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 Unit, "#symlink" do
143
- let!(:unit) { Unit.new(".symlinked") }
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(unit.dotfile).once
146
- unit.symlink
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(unit.dotfile).and_raise(StandardError)
150
- expect { unit.symlink }.not_to raise_error
151
- unit.symlink.should == NoSymlink
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 unit" do
171
+ describe "inspecting dot" do
156
172
  it "should display properly" do
157
- Unit.new(".zshrc").inspect.should == "#<Dotify::Unit filename: '.zshrc' linked: false>"
158
- bash = Unit.new(".bashrc")
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::Unit filename: '.bashrc' linked: true>"
176
+ bash.inspect.should == "#<Dotify::Dot filename: '.bashrc' linked: true>"
161
177
 
162
178
  end
163
179
  end
@@ -4,17 +4,17 @@ module Dotify
4
4
  describe Filter do
5
5
 
6
6
  describe Filter, "#home" do
7
- it "should call Filter#units with the correct path" do
8
- Filter.should_receive(:units).with("/tmp/home/.*").once.and_return([])
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(:units) do
12
+ Filter.stub(:dots) do
13
13
  [
14
- Unit.new('.zshrc'),
15
- Unit.new('.bashrc'),
16
- Unit.new('.vimrc'),
17
- Unit.new('.gitconfig')
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#units with the correct path" do
31
- Filter.should_receive(:units).with("/tmp/home/.dotify/.*").once.and_return([])
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(:units) do
35
+ Filter.stub(:dots) do
36
36
  [
37
- Unit.new(".gitconfig"),
38
- Unit.new('.vimrc'),
39
- Unit.new('.zshrc'),
40
- Unit.new('.bashrc'),
41
- Unit.new('.fakefile')
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, "#units" do
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.units(glob)
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.units(glob) }
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
- Unit.new('.vimrc'), Unit.new('.bashrc'), Unit.new('.zshrc')
81
+ Dot.new('.vimrc'), Dot.new('.bashrc'), Dot.new('.zshrc')
82
82
  ] }
83
- it "return only the filenames of the units" do
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.5
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-14 00:00:00.000000000 Z
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