Sha256: 12a8e7bf6a369326d2e21c16f40a08b1c05c2bd0693847f0519d01bc7921f6cb

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

require 'rspec'
require 'dotfile_linker'

describe DotfileLinker do
  describe ".exclude_file?" do
    it "excludes files in blacklist" do
      %w{ . .. .git }.each { |filename| DotfileLinker.exclude_file?(filename).should be }
    end

    it "doesn't exclude files prefixed with dot" do
      %w{ .bash_profile .emacs .gitconfig .tmux.conf }.each { |filename| DotfileLinker.exclude_file?(filename).should_not be }
    end

    it "doesn't exclude files that aren't prefixed with dot" do
      ['my_script' 'sample.rb'].each { |filename| DotfileLinker.exclude_file?(filename).should_not be }
    end
  end

  describe ".link_file when symlink doesn't already exist" do
    before do
      DotfileLinker.stub!(:positive_user_response?).and_return(true)
      File.stub!(:symlink?).and_return(false)

      @bad_filenames = %w{ . .. .git }
      @good_filenames = %w{.bash_profile .bashrc .dotrc  .emacs .gemrc .gitconfig .gitignore_global .irbrc .oh-my-zsh
                          .pryrc .rvmrc .ssh .tmux.conf .zshrc .zshrc.pre-oh-my-zsh}
    end

    it "links accepted files to home directory" do
      @good_filenames.each do |filename|
        File.should_receive(:symlink).with("#{ Dir.pwd }/#{ filename }", "#{ Dir.home }/#{ filename }")
        DotfileLinker.link_file(filename)
      end
    end

    it "doesn't link blacklisted files" do
      @bad_filenames.each do |filename|
        File.should_not_receive(:symlink)
        DotfileLinker.link_file(filename)
      end
    end
  end

  describe "String#human_filename" do
    it "replaces home dir for short path" do
      File.expand_path("~/.bash_rc").human_filename.should == '~/.bash_rc'
    end

    it "replaces home dir for long path" do
      File.expand_path("#{ Dir.home }/some/test/dir/.gitignore").human_filename.should == '~/some/test/dir/.gitignore'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dotfile_linker-0.0.2 spec/dotfile_linker_spec.rb
dotfile_linker-0.0.1 spec/dotfile_linker_spec.rb