Merge pull request #95 from nicolasmccurdy/use-expect-syntax
Use expect syntax
This commit is contained in:
@@ -10,11 +10,11 @@ describe 'homesick' do
|
|||||||
|
|
||||||
let(:homesick) { Homesick.new }
|
let(:homesick) { Homesick.new }
|
||||||
|
|
||||||
before { homesick.stub(:repos_dir).and_return(castles) }
|
before { allow(homesick).to receive(:repos_dir).and_return(castles) }
|
||||||
|
|
||||||
describe 'clone' do
|
describe 'clone' do
|
||||||
context 'has a .homesickrc' do
|
context 'has a .homesickrc' do
|
||||||
it 'should run the .homesickrc' do
|
it 'runs the .homesickrc' do
|
||||||
somewhere = create_construct
|
somewhere = create_construct
|
||||||
local_repo = somewhere.directory('some_repo')
|
local_repo = somewhere.directory('some_repo')
|
||||||
local_repo.file('.homesickrc') do |file|
|
local_repo.file('.homesickrc') do |file|
|
||||||
@@ -28,18 +28,18 @@ describe 'homesick' do
|
|||||||
expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname))
|
expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname))
|
||||||
homesick.clone local_repo
|
homesick.clone local_repo
|
||||||
|
|
||||||
castles.join('some_repo').join('testing').should exist
|
expect(castles.join('some_repo').join('testing')).to exist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'of a file' do
|
context 'of a file' do
|
||||||
it 'should symlink existing directories' do
|
it 'symlinks existing directories' do
|
||||||
somewhere = create_construct
|
somewhere = create_construct
|
||||||
local_repo = somewhere.directory('wtf')
|
local_repo = somewhere.directory('wtf')
|
||||||
|
|
||||||
homesick.clone local_repo
|
homesick.clone local_repo
|
||||||
|
|
||||||
castles.join('wtf').readlink.should == local_repo
|
expect(castles.join('wtf').readlink).to eq(local_repo)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when it exists in a repo directory' do
|
context 'when it exists in a repo directory' do
|
||||||
@@ -48,14 +48,14 @@ describe 'homesick' do
|
|||||||
@existing_dir = existing_castle.parent
|
@existing_dir = existing_castle.parent
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should raise an error' do
|
it 'raises an error' do
|
||||||
homesick.should_not_receive(:git_clone)
|
expect(homesick).not_to receive(:git_clone)
|
||||||
expect { homesick.clone @existing_dir.to_s }.to raise_error(/already cloned/i)
|
expect { homesick.clone @existing_dir.to_s }.to raise_error(/already cloned/i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should clone git repo like file:///path/to.git' do
|
it 'clones git repo like file:///path/to.git' do
|
||||||
bare_repo = File.join(create_construct.to_s, 'dotfiles.git')
|
bare_repo = File.join(create_construct.to_s, 'dotfiles.git')
|
||||||
system "git init --bare #{bare_repo} >/dev/null 2>&1"
|
system "git init --bare #{bare_repo} >/dev/null 2>&1"
|
||||||
|
|
||||||
@@ -63,51 +63,51 @@ describe 'homesick' do
|
|||||||
Capture.stderr do
|
Capture.stderr do
|
||||||
homesick.clone "file://#{bare_repo}"
|
homesick.clone "file://#{bare_repo}"
|
||||||
end
|
end
|
||||||
File.directory?(File.join(home.to_s, '.homesick/repos/dotfiles'))
|
expect(File.directory?(File.join(home.to_s, '.homesick/repos/dotfiles')))
|
||||||
.should be_true
|
.to be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should clone git repo like git://host/path/to.git' do
|
it 'clones git repo like git://host/path/to.git' do
|
||||||
homesick.should_receive(:git_clone)
|
expect(homesick).to receive(:git_clone)
|
||||||
.with('git://github.com/technicalpickles/pickled-vim.git')
|
.with('git://github.com/technicalpickles/pickled-vim.git')
|
||||||
|
|
||||||
homesick.clone 'git://github.com/technicalpickles/pickled-vim.git'
|
homesick.clone 'git://github.com/technicalpickles/pickled-vim.git'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should clone git repo like git@host:path/to.git' do
|
it 'clones git repo like git@host:path/to.git' do
|
||||||
homesick.should_receive(:git_clone)
|
expect(homesick).to receive(:git_clone)
|
||||||
.with('git@github.com:technicalpickles/pickled-vim.git')
|
.with('git@github.com:technicalpickles/pickled-vim.git')
|
||||||
|
|
||||||
homesick.clone 'git@github.com:technicalpickles/pickled-vim.git'
|
homesick.clone 'git@github.com:technicalpickles/pickled-vim.git'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should clone git repo like http://host/path/to.git' do
|
it 'clones git repo like http://host/path/to.git' do
|
||||||
homesick.should_receive(:git_clone)
|
expect(homesick).to receive(:git_clone)
|
||||||
.with('http://github.com/technicalpickles/pickled-vim.git')
|
.with('http://github.com/technicalpickles/pickled-vim.git')
|
||||||
|
|
||||||
homesick.clone 'http://github.com/technicalpickles/pickled-vim.git'
|
homesick.clone 'http://github.com/technicalpickles/pickled-vim.git'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should clone git repo like http://host/path/to' do
|
it 'clones git repo like http://host/path/to' do
|
||||||
homesick.should_receive(:git_clone)
|
expect(homesick).to receive(:git_clone)
|
||||||
.with('http://github.com/technicalpickles/pickled-vim')
|
.with('http://github.com/technicalpickles/pickled-vim')
|
||||||
|
|
||||||
homesick.clone 'http://github.com/technicalpickles/pickled-vim'
|
homesick.clone 'http://github.com/technicalpickles/pickled-vim'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should clone git repo like host-alias:repos.git' do
|
it 'clones git repo like host-alias:repos.git' do
|
||||||
homesick.should_receive(:git_clone).with('gitolite:pickled-vim.git')
|
expect(homesick).to receive(:git_clone).with('gitolite:pickled-vim.git')
|
||||||
|
|
||||||
homesick.clone 'gitolite:pickled-vim.git'
|
homesick.clone 'gitolite:pickled-vim.git'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should throw an exception when trying to clone a malformed uri like malformed' do
|
it 'throws an exception when trying to clone a malformed uri like malformed' do
|
||||||
homesick.should_not_receive(:git_clone)
|
expect(homesick).not_to receive(:git_clone)
|
||||||
expect { homesick.clone 'malformed' }.to raise_error
|
expect { homesick.clone 'malformed' }.to raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should clone a github repo' do
|
it 'clones a github repo' do
|
||||||
homesick.should_receive(:git_clone)
|
expect(homesick).to receive(:git_clone)
|
||||||
.with('https://github.com/wfarr/dotfiles.git',
|
.with('https://github.com/wfarr/dotfiles.git',
|
||||||
destination: Pathname.new('dotfiles'))
|
destination: Pathname.new('dotfiles'))
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ describe 'homesick' do
|
|||||||
expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname))
|
expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname))
|
||||||
homesick.rc castle
|
homesick.rc castle
|
||||||
|
|
||||||
castle.join('testing').should exist
|
expect(castle.join('testing')).to exist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ describe 'homesick' do
|
|||||||
expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval skip', /not evaling.+/, :blue)
|
expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval skip', /not evaling.+/, :blue)
|
||||||
homesick.rc castle
|
homesick.rc castle
|
||||||
|
|
||||||
castle.join('testing').should_not exist
|
expect(castle.join('testing')).not_to exist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -167,7 +167,7 @@ describe 'homesick' do
|
|||||||
|
|
||||||
homesick.link('glencairn')
|
homesick.link('glencairn')
|
||||||
|
|
||||||
home.join('.some_dotfile').readlink.should == dotfile
|
expect(home.join('.some_dotfile').readlink).to eq(dotfile)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'links non-dotfiles from a castle to the home folder' do
|
it 'links non-dotfiles from a castle to the home folder' do
|
||||||
@@ -175,7 +175,7 @@ describe 'homesick' do
|
|||||||
|
|
||||||
homesick.link('glencairn')
|
homesick.link('glencairn')
|
||||||
|
|
||||||
home.join('bin').readlink.should == dotfile
|
expect(home.join('bin').readlink).to eq(dotfile)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when forced' do
|
context 'when forced' do
|
||||||
@@ -190,7 +190,7 @@ describe 'homesick' do
|
|||||||
|
|
||||||
homesick.link('glencairn')
|
homesick.link('glencairn')
|
||||||
|
|
||||||
existing_dotdir_link.readlink.should == dotdir
|
expect(existing_dotdir_link.readlink).to eq(dotdir)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can override existing directory' do
|
it 'can override existing directory' do
|
||||||
@@ -200,7 +200,7 @@ describe 'homesick' do
|
|||||||
|
|
||||||
homesick.link('glencairn')
|
homesick.link('glencairn')
|
||||||
|
|
||||||
existing_dotdir.readlink.should == dotdir
|
expect(existing_dotdir.readlink).to eq(dotdir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -213,8 +213,8 @@ describe 'homesick' do
|
|||||||
homesick.link('glencairn')
|
homesick.link('glencairn')
|
||||||
|
|
||||||
home_dotdir = home.join('.config')
|
home_dotdir = home.join('.config')
|
||||||
home_dotdir.symlink?.should be == false
|
expect(home_dotdir.symlink?).to eq(false)
|
||||||
home_dotdir.join('.some_dotfile').readlink.should == dotfile
|
expect(home_dotdir.join('.some_dotfile').readlink).to eq(dotfile)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -227,8 +227,8 @@ describe 'homesick' do
|
|||||||
homesick.link('glencairn')
|
homesick.link('glencairn')
|
||||||
|
|
||||||
home_dotdir = home.join('.config').join('appA')
|
home_dotdir = home.join('.config').join('appA')
|
||||||
home_dotdir.symlink?.should be == false
|
expect(home_dotdir.symlink?).to eq(false)
|
||||||
home_dotdir.join('.some_dotfile').readlink.should == dotfile
|
expect(home_dotdir.join('.some_dotfile').readlink).to eq(dotfile)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -246,12 +246,12 @@ describe 'homesick' do
|
|||||||
|
|
||||||
home_config_dir = home.join('.config')
|
home_config_dir = home.join('.config')
|
||||||
home_someapp_dir = home_config_dir.join('someapp')
|
home_someapp_dir = home_config_dir.join('someapp')
|
||||||
home_config_dir.symlink?.should be == false
|
expect(home_config_dir.symlink?).to eq(false)
|
||||||
home_config_dir.join('.some_dotfile').readlink
|
expect(home_config_dir.join('.some_dotfile').readlink)
|
||||||
.should be == config_dotfile
|
.to eq(config_dotfile)
|
||||||
home_someapp_dir.symlink?.should be == false
|
expect(home_someapp_dir.symlink?).to eq(false)
|
||||||
home_someapp_dir.join('.some_appfile').readlink
|
expect(home_someapp_dir.join('.some_appfile').readlink)
|
||||||
.should == someapp_dotfile
|
.to eq(someapp_dotfile)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -262,7 +262,7 @@ describe 'homesick' do
|
|||||||
|
|
||||||
homesick.link
|
homesick.link
|
||||||
|
|
||||||
home.join('.some_dotfile').readlink.should == dotfile
|
expect(home.join('.some_dotfile').readlink).to eq(dotfile)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -276,7 +276,7 @@ describe 'homesick' do
|
|||||||
homesick.link('glencairn')
|
homesick.link('glencairn')
|
||||||
homesick.unlink('glencairn')
|
homesick.unlink('glencairn')
|
||||||
|
|
||||||
home.join('.some_dotfile').should_not exist
|
expect(home.join('.some_dotfile')).not_to exist
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'unlinks non-dotfiles from the home folder' do
|
it 'unlinks non-dotfiles from the home folder' do
|
||||||
@@ -285,7 +285,7 @@ describe 'homesick' do
|
|||||||
homesick.link('glencairn')
|
homesick.link('glencairn')
|
||||||
homesick.unlink('glencairn')
|
homesick.unlink('glencairn')
|
||||||
|
|
||||||
home.join('bin').should_not exist
|
expect(home.join('bin')).not_to exist
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with '.config' in .homesick_subdir" do
|
context "with '.config' in .homesick_subdir" do
|
||||||
@@ -298,8 +298,8 @@ describe 'homesick' do
|
|||||||
homesick.unlink('glencairn')
|
homesick.unlink('glencairn')
|
||||||
|
|
||||||
home_dotdir = home.join('.config')
|
home_dotdir = home.join('.config')
|
||||||
home_dotdir.should exist
|
expect(home_dotdir).to exist
|
||||||
home_dotdir.join('.some_dotfile').should_not exist
|
expect(home_dotdir.join('.some_dotfile')).not_to exist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -313,8 +313,8 @@ describe 'homesick' do
|
|||||||
homesick.unlink('glencairn')
|
homesick.unlink('glencairn')
|
||||||
|
|
||||||
home_dotdir = home.join('.config').join('appA')
|
home_dotdir = home.join('.config').join('appA')
|
||||||
home_dotdir.should exist
|
expect(home_dotdir).to exist
|
||||||
home_dotdir.join('.some_dotfile').should_not exist
|
expect(home_dotdir.join('.some_dotfile')).not_to exist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -333,10 +333,10 @@ describe 'homesick' do
|
|||||||
|
|
||||||
home_config_dir = home.join('.config')
|
home_config_dir = home.join('.config')
|
||||||
home_someapp_dir = home_config_dir.join('someapp')
|
home_someapp_dir = home_config_dir.join('someapp')
|
||||||
home_config_dir.should exist
|
expect(home_config_dir).to exist
|
||||||
home_config_dir.join('.some_dotfile').should_not exist
|
expect(home_config_dir.join('.some_dotfile')).not_to exist
|
||||||
home_someapp_dir.should exist
|
expect(home_someapp_dir).to exist
|
||||||
home_someapp_dir.join('.some_appfile').should_not exist
|
expect(home_someapp_dir.join('.some_appfile')).not_to exist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -349,21 +349,21 @@ describe 'homesick' do
|
|||||||
homesick.link
|
homesick.link
|
||||||
homesick.unlink
|
homesick.unlink
|
||||||
|
|
||||||
home.join('.some_dotfile').should_not exist
|
expect(home.join('.some_dotfile')).not_to exist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'list' do
|
describe 'list' do
|
||||||
it 'should say each castle in the castle directory' do
|
it 'says each castle in the castle directory' do
|
||||||
given_castle('zomg')
|
given_castle('zomg')
|
||||||
given_castle('wtf/zomg')
|
given_castle('wtf/zomg')
|
||||||
|
|
||||||
homesick.should_receive(:say_status)
|
expect(homesick).to receive(:say_status)
|
||||||
.with('zomg',
|
.with('zomg',
|
||||||
'git://github.com/technicalpickles/zomg.git',
|
'git://github.com/technicalpickles/zomg.git',
|
||||||
:cyan)
|
:cyan)
|
||||||
homesick.should_receive(:say_status)
|
expect(homesick).to receive(:say_status)
|
||||||
.with('wtf/zomg',
|
.with('wtf/zomg',
|
||||||
'git://github.com/technicalpickles/zomg.git',
|
'git://github.com/technicalpickles/zomg.git',
|
||||||
:cyan)
|
:cyan)
|
||||||
@@ -373,24 +373,25 @@ describe 'homesick' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'status' do
|
describe 'status' do
|
||||||
it 'should say "nothing to commit" when there are no changes' do
|
it 'says "nothing to commit" when there are no changes' do
|
||||||
given_castle('castle_repo')
|
given_castle('castle_repo')
|
||||||
text = Capture.stdout { homesick.status('castle_repo') }
|
text = Capture.stdout { homesick.status('castle_repo') }
|
||||||
text.should =~ /nothing to commit \(create\/copy files and use "git add" to track\)$/
|
expect(text).to match(/nothing to commit \(create\/copy files and use "git add" to track\)$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should say "Changes to be committed" when there are changes' do
|
it 'says "Changes to be committed" when there are changes' do
|
||||||
given_castle('castle_repo')
|
given_castle('castle_repo')
|
||||||
some_rc_file = home.file '.some_rc_file'
|
some_rc_file = home.file '.some_rc_file'
|
||||||
homesick.track(some_rc_file.to_s, 'castle_repo')
|
homesick.track(some_rc_file.to_s, 'castle_repo')
|
||||||
text = Capture.stdout { homesick.status('castle_repo') }
|
text = Capture.stdout { homesick.status('castle_repo') }
|
||||||
text.should =~
|
expect(text).to match(
|
||||||
/Changes to be committed:.*new file:\s*home\/.some_rc_file/m
|
/Changes to be committed:.*new file:\s*home\/.some_rc_file/m
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'diff' do
|
describe 'diff' do
|
||||||
it 'should output an empty message when there are no changes to commit' do
|
it 'outputs an empty message when there are no changes to commit' do
|
||||||
given_castle('castle_repo')
|
given_castle('castle_repo')
|
||||||
some_rc_file = home.file '.some_rc_file'
|
some_rc_file = home.file '.some_rc_file'
|
||||||
homesick.track(some_rc_file.to_s, 'castle_repo')
|
homesick.track(some_rc_file.to_s, 'castle_repo')
|
||||||
@@ -398,10 +399,10 @@ describe 'homesick' do
|
|||||||
homesick.commit 'castle_repo', 'Adding a file to the test'
|
homesick.commit 'castle_repo', 'Adding a file to the test'
|
||||||
end
|
end
|
||||||
text = Capture.stdout { homesick.diff('castle_repo') }
|
text = Capture.stdout { homesick.diff('castle_repo') }
|
||||||
text.should eq('')
|
expect(text).to eq('')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should output a diff message when there are changes to commit' do
|
it 'outputs a diff message when there are changes to commit' do
|
||||||
given_castle('castle_repo')
|
given_castle('castle_repo')
|
||||||
some_rc_file = home.file '.some_rc_file'
|
some_rc_file = home.file '.some_rc_file'
|
||||||
homesick.track(some_rc_file.to_s, 'castle_repo')
|
homesick.track(some_rc_file.to_s, 'castle_repo')
|
||||||
@@ -412,31 +413,31 @@ describe 'homesick' do
|
|||||||
file.puts 'Some test text'
|
file.puts 'Some test text'
|
||||||
end
|
end
|
||||||
text = Capture.stdout { homesick.diff('castle_repo') }
|
text = Capture.stdout { homesick.diff('castle_repo') }
|
||||||
text.should =~ /diff --git.+Some test text$/m
|
expect(text).to match(/diff --git.+Some test text$/m)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'show_path' do
|
describe 'show_path' do
|
||||||
it 'should say the path of a castle' do
|
it 'says the path of a castle' do
|
||||||
castle = given_castle('castle_repo')
|
castle = given_castle('castle_repo')
|
||||||
|
|
||||||
homesick.should_receive(:say).with(castle.dirname)
|
expect(homesick).to receive(:say).with(castle.dirname)
|
||||||
|
|
||||||
homesick.show_path('castle_repo')
|
homesick.show_path('castle_repo')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'pull' do
|
describe 'pull' do
|
||||||
it 'should perform a pull, submodule init and update when the given castle exists' do
|
it 'performs a pull, submodule init and update when the given castle exists' do
|
||||||
given_castle('castle_repo')
|
given_castle('castle_repo')
|
||||||
homesick.stub(:system).once.with('git pull --quiet')
|
allow(homesick).to receive(:system).once.with('git pull --quiet')
|
||||||
homesick.stub(:system).once.with('git submodule --quiet init')
|
allow(homesick).to receive(:system).once.with('git submodule --quiet init')
|
||||||
homesick.stub(:system).once.with('git submodule --quiet update --init --recursive >/dev/null 2>&1')
|
allow(homesick).to receive(:system).once.with('git submodule --quiet update --init --recursive >/dev/null 2>&1')
|
||||||
homesick.pull 'castle_repo'
|
homesick.pull 'castle_repo'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should print an error message when trying to pull a non-existant castle' do
|
it 'prints an error message when trying to pull a non-existant castle' do
|
||||||
homesick.should_receive('say_status').once
|
expect(homesick).to receive('say_status').once
|
||||||
.with(:error,
|
.with(:error,
|
||||||
%r{Could not pull castle_repo, expected .* exist and contain dotfiles},
|
%r{Could not pull castle_repo, expected .* exist and contain dotfiles},
|
||||||
:red)
|
:red)
|
||||||
@@ -444,13 +445,13 @@ describe 'homesick' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '--all' do
|
describe '--all' do
|
||||||
it 'should pull each castle when invoked with --all' do
|
it 'pulls each castle when invoked with --all' do
|
||||||
given_castle('castle_repo')
|
given_castle('castle_repo')
|
||||||
given_castle('glencairn')
|
given_castle('glencairn')
|
||||||
homesick.stub(:system).exactly(2).times.with('git pull --quiet')
|
allow(homesick).to receive(:system).exactly(2).times.with('git pull --quiet')
|
||||||
homesick.stub(:system).exactly(2).times
|
allow(homesick).to receive(:system).exactly(2).times
|
||||||
.with('git submodule --quiet init')
|
.with('git submodule --quiet init')
|
||||||
homesick.stub(:system).exactly(2).times
|
allow(homesick).to receive(:system).exactly(2).times
|
||||||
.with('git submodule --quiet update --init --recursive >/dev/null 2>&1')
|
.with('git submodule --quiet update --init --recursive >/dev/null 2>&1')
|
||||||
Capture.stdout do
|
Capture.stdout do
|
||||||
Capture.stderr { homesick.invoke 'pull', [], all: true }
|
Capture.stderr { homesick.invoke 'pull', [], all: true }
|
||||||
@@ -461,14 +462,14 @@ describe 'homesick' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'push' do
|
describe 'push' do
|
||||||
it 'should perform a git push on the given castle' do
|
it 'performs a git push on the given castle' do
|
||||||
given_castle('castle_repo')
|
given_castle('castle_repo')
|
||||||
homesick.stub(:system).once.with('git push')
|
allow(homesick).to receive(:system).once.with('git push')
|
||||||
homesick.push 'castle_repo'
|
homesick.push 'castle_repo'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should print an error message when trying to push a non-existant castle' do
|
it 'prints an error message when trying to push a non-existant castle' do
|
||||||
homesick.should_receive('say_status').once
|
expect(homesick).to receive('say_status').once
|
||||||
.with(:error,
|
.with(:error,
|
||||||
%r{Could not push castle_repo, expected .* exist and contain dotfiles},
|
%r{Could not push castle_repo, expected .* exist and contain dotfiles},
|
||||||
:red)
|
:red)
|
||||||
@@ -477,7 +478,7 @@ describe 'homesick' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'track' do
|
describe 'track' do
|
||||||
it 'should move the tracked file into the castle' do
|
it 'moves the tracked file into the castle' do
|
||||||
castle = given_castle('castle_repo')
|
castle = given_castle('castle_repo')
|
||||||
|
|
||||||
some_rc_file = home.file '.some_rc_file'
|
some_rc_file = home.file '.some_rc_file'
|
||||||
@@ -485,12 +486,12 @@ describe 'homesick' do
|
|||||||
homesick.track(some_rc_file.to_s, 'castle_repo')
|
homesick.track(some_rc_file.to_s, 'castle_repo')
|
||||||
|
|
||||||
tracked_file = castle.join('.some_rc_file')
|
tracked_file = castle.join('.some_rc_file')
|
||||||
tracked_file.should exist
|
expect(tracked_file).to exist
|
||||||
|
|
||||||
some_rc_file.readlink.should == tracked_file
|
expect(some_rc_file.readlink).to eq(tracked_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should handle files with parens' do
|
it 'handles files with parens' do
|
||||||
castle = given_castle('castle_repo')
|
castle = given_castle('castle_repo')
|
||||||
|
|
||||||
some_rc_file = home.file 'Default (Linux).sublime-keymap'
|
some_rc_file = home.file 'Default (Linux).sublime-keymap'
|
||||||
@@ -498,31 +499,31 @@ describe 'homesick' do
|
|||||||
homesick.track(some_rc_file.to_s, 'castle_repo')
|
homesick.track(some_rc_file.to_s, 'castle_repo')
|
||||||
|
|
||||||
tracked_file = castle.join('Default (Linux).sublime-keymap')
|
tracked_file = castle.join('Default (Linux).sublime-keymap')
|
||||||
tracked_file.should exist
|
expect(tracked_file).to exist
|
||||||
|
|
||||||
some_rc_file.readlink.should == tracked_file
|
expect(some_rc_file.readlink).to eq(tracked_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should track a file in nested folder structure' do
|
it 'tracks a file in nested folder structure' do
|
||||||
castle = given_castle('castle_repo')
|
castle = given_castle('castle_repo')
|
||||||
|
|
||||||
some_nested_file = home.file('some/nested/file.txt')
|
some_nested_file = home.file('some/nested/file.txt')
|
||||||
homesick.track(some_nested_file.to_s, 'castle_repo')
|
homesick.track(some_nested_file.to_s, 'castle_repo')
|
||||||
|
|
||||||
tracked_file = castle.join('some/nested/file.txt')
|
tracked_file = castle.join('some/nested/file.txt')
|
||||||
tracked_file.should exist
|
expect(tracked_file).to exist
|
||||||
some_nested_file.readlink.should == tracked_file
|
expect(some_nested_file.readlink).to eq(tracked_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should track a nested directory' do
|
it 'tracks a nested directory' do
|
||||||
castle = given_castle('castle_repo')
|
castle = given_castle('castle_repo')
|
||||||
|
|
||||||
some_nested_dir = home.directory('some/nested/directory/')
|
some_nested_dir = home.directory('some/nested/directory/')
|
||||||
homesick.track(some_nested_dir.to_s, 'castle_repo')
|
homesick.track(some_nested_dir.to_s, 'castle_repo')
|
||||||
|
|
||||||
tracked_file = castle.join('some/nested/directory/')
|
tracked_file = castle.join('some/nested/directory/')
|
||||||
tracked_file.should exist
|
expect(tracked_file).to exist
|
||||||
some_nested_dir.realpath.should == tracked_file.realpath
|
expect(some_nested_dir.realpath).to eq(tracked_file.realpath)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when call with no castle name' do
|
context 'when call with no castle name' do
|
||||||
@@ -534,21 +535,21 @@ describe 'homesick' do
|
|||||||
homesick.track(some_rc_file.to_s)
|
homesick.track(some_rc_file.to_s)
|
||||||
|
|
||||||
tracked_file = castle.join('.some_rc_file')
|
tracked_file = castle.join('.some_rc_file')
|
||||||
tracked_file.should exist
|
expect(tracked_file).to exist
|
||||||
|
|
||||||
some_rc_file.readlink.should == tracked_file
|
expect(some_rc_file.readlink).to eq(tracked_file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'commit' do
|
describe 'commit' do
|
||||||
it 'should have a commit message when the commit succeeds' do
|
it 'has a commit message when the commit succeeds' do
|
||||||
given_castle('castle_repo')
|
given_castle('castle_repo')
|
||||||
some_rc_file = home.file '.a_random_rc_file'
|
some_rc_file = home.file '.a_random_rc_file'
|
||||||
homesick.track(some_rc_file.to_s, 'castle_repo')
|
homesick.track(some_rc_file.to_s, 'castle_repo')
|
||||||
text = Capture.stdout do
|
text = Capture.stdout do
|
||||||
homesick.commit('castle_repo', 'Test message')
|
homesick.commit('castle_repo', 'Test message')
|
||||||
end
|
end
|
||||||
text.should =~ /^\[master \(root-commit\) \w+\] Test message/
|
expect(text).to match(/^\[master \(root-commit\) \w+\] Test message/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -556,7 +557,7 @@ describe 'homesick' do
|
|||||||
# not for the subdir_file method itself.
|
# not for the subdir_file method itself.
|
||||||
describe 'subdir_file' do
|
describe 'subdir_file' do
|
||||||
|
|
||||||
it 'should add the nested files parent to the subdir_file' do
|
it 'adds the nested files parent to the subdir_file' do
|
||||||
castle = given_castle('castle_repo')
|
castle = given_castle('castle_repo')
|
||||||
|
|
||||||
some_nested_file = home.file('some/nested/file.txt')
|
some_nested_file = home.file('some/nested/file.txt')
|
||||||
@@ -564,11 +565,11 @@ describe 'homesick' do
|
|||||||
|
|
||||||
subdir_file = castle.parent.join(Homesick::SUBDIR_FILENAME)
|
subdir_file = castle.parent.join(Homesick::SUBDIR_FILENAME)
|
||||||
File.open(subdir_file, 'r') do |f|
|
File.open(subdir_file, 'r') do |f|
|
||||||
f.readline.should == "some/nested\n"
|
expect(f.readline).to eq("some/nested\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should NOT add anything if the files parent is already listed' do
|
it 'does NOT add anything if the files parent is already listed' do
|
||||||
castle = given_castle('castle_repo')
|
castle = given_castle('castle_repo')
|
||||||
|
|
||||||
some_nested_file = home.file('some/nested/file.txt')
|
some_nested_file = home.file('some/nested/file.txt')
|
||||||
@@ -578,11 +579,11 @@ describe 'homesick' do
|
|||||||
|
|
||||||
subdir_file = castle.parent.join(Homesick::SUBDIR_FILENAME)
|
subdir_file = castle.parent.join(Homesick::SUBDIR_FILENAME)
|
||||||
File.open(subdir_file, 'r') do |f|
|
File.open(subdir_file, 'r') do |f|
|
||||||
f.readlines.size.should == 1
|
expect(f.readlines.size).to eq(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should remove the parent of a tracked file from the subdir_file if the parent itself is tracked' do
|
it 'removes the parent of a tracked file from the subdir_file if the parent itself is tracked' do
|
||||||
castle = given_castle('castle_repo')
|
castle = given_castle('castle_repo')
|
||||||
|
|
||||||
some_nested_file = home.file('some/nested/file.txt')
|
some_nested_file = home.file('some/nested/file.txt')
|
||||||
@@ -592,7 +593,7 @@ describe 'homesick' do
|
|||||||
|
|
||||||
subdir_file = castle.parent.join(Homesick::SUBDIR_FILENAME)
|
subdir_file = castle.parent.join(Homesick::SUBDIR_FILENAME)
|
||||||
File.open(subdir_file, 'r') do |f|
|
File.open(subdir_file, 'r') do |f|
|
||||||
f.each_line { |line| line.should_not == "some/nested\n" }
|
f.each_line { |line| expect(line).not_to eq("some/nested\n") }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -606,7 +607,7 @@ describe 'homesick' do
|
|||||||
homesick.track(some_rc_file.to_s, 'stronghold')
|
homesick.track(some_rc_file.to_s, 'stronghold')
|
||||||
homesick.destroy('stronghold')
|
homesick.destroy('stronghold')
|
||||||
|
|
||||||
some_rc_file.should_not be_exist
|
expect(some_rc_file).not_to be_exist
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deletes the cloned repository' do
|
it 'deletes the cloned repository' do
|
||||||
@@ -616,20 +617,20 @@ describe 'homesick' do
|
|||||||
homesick.track(some_rc_file.to_s, 'stronghold')
|
homesick.track(some_rc_file.to_s, 'stronghold')
|
||||||
homesick.destroy('stronghold')
|
homesick.destroy('stronghold')
|
||||||
|
|
||||||
castle.should_not be_exist
|
expect(castle).not_to be_exist
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'cd' do
|
describe 'cd' do
|
||||||
it "cd's to the root directory of the given castle" do
|
it "cd's to the root directory of the given castle" do
|
||||||
given_castle('castle_repo')
|
given_castle('castle_repo')
|
||||||
homesick.should_receive('inside').once.with(kind_of(Pathname)).and_yield
|
expect(homesick).to receive('inside').once.with(kind_of(Pathname)).and_yield
|
||||||
homesick.should_receive('system').once.with(ENV['SHELL'])
|
expect(homesick).to receive('system').once.with(ENV['SHELL'])
|
||||||
Capture.stdout { homesick.cd 'castle_repo' }
|
Capture.stdout { homesick.cd 'castle_repo' }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns an error message when the given castle does not exist' do
|
it 'returns an error message when the given castle does not exist' do
|
||||||
homesick.should_receive('say_status').once
|
expect(homesick).to receive('say_status').once
|
||||||
.with(:error,
|
.with(:error,
|
||||||
%r{Could not cd castle_repo, expected .* exist and contain dotfiles},
|
%r{Could not cd castle_repo, expected .* exist and contain dotfiles},
|
||||||
:red)
|
:red)
|
||||||
@@ -640,19 +641,19 @@ describe 'homesick' do
|
|||||||
describe 'open' do
|
describe 'open' do
|
||||||
it 'opens the system default editor in the root of the given castle' do
|
it 'opens the system default editor in the root of the given castle' do
|
||||||
# Make sure calls to ENV use default values for most things...
|
# Make sure calls to ENV use default values for most things...
|
||||||
ENV.stub(:[]).and_call_original
|
allow(ENV).to receive(:[]).and_call_original
|
||||||
# Set a default value for 'EDITOR' just in case none is set
|
# Set a default value for 'EDITOR' just in case none is set
|
||||||
ENV.stub(:[]).with('EDITOR').and_return('vim')
|
allow(ENV).to receive(:[]).with('EDITOR').and_return('vim')
|
||||||
given_castle 'castle_repo'
|
given_castle 'castle_repo'
|
||||||
homesick.should_receive('inside').once.with(kind_of(Pathname)).and_yield
|
expect(homesick).to receive('inside').once.with(kind_of(Pathname)).and_yield
|
||||||
homesick.should_receive('system').once.with('vim')
|
expect(homesick).to receive('system').once.with('vim')
|
||||||
Capture.stdout { homesick.open 'castle_repo' }
|
Capture.stdout { homesick.open 'castle_repo' }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns an error message when the $EDITOR environment variable is not set' do
|
it 'returns an error message when the $EDITOR environment variable is not set' do
|
||||||
# Set the default editor to make sure it fails.
|
# Set the default editor to make sure it fails.
|
||||||
ENV.stub(:[]).with('EDITOR').and_return(nil)
|
allow(ENV).to receive(:[]).with('EDITOR').and_return(nil)
|
||||||
homesick.should_receive('say_status').once
|
expect(homesick).to receive('say_status').once
|
||||||
.with(:error,
|
.with(:error,
|
||||||
'The $EDITOR environment variable must be set to use this command',
|
'The $EDITOR environment variable must be set to use this command',
|
||||||
:red)
|
:red)
|
||||||
@@ -661,8 +662,8 @@ describe 'homesick' do
|
|||||||
|
|
||||||
it 'returns an error message when the given castle does not exist' do
|
it 'returns an error message when the given castle does not exist' do
|
||||||
# Set a default just in case none is set
|
# Set a default just in case none is set
|
||||||
ENV.stub(:[]).with('EDITOR').and_return('vim')
|
allow(ENV).to receive(:[]).with('EDITOR').and_return('vim')
|
||||||
homesick.should_receive('say_status').once
|
expect(homesick).to receive('say_status').once
|
||||||
.with(:error,
|
.with(:error,
|
||||||
%r{Could not open castle_repo, expected .* exist and contain dotfiles},
|
%r{Could not open castle_repo, expected .* exist and contain dotfiles},
|
||||||
:red)
|
:red)
|
||||||
@@ -671,9 +672,9 @@ describe 'homesick' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'version' do
|
describe 'version' do
|
||||||
it 'should print the current version of homesick' do
|
it 'prints the current version of homesick' do
|
||||||
text = Capture.stdout { homesick.version }
|
text = Capture.stdout { homesick.version }
|
||||||
text.chomp.should =~ /\d+\.\d+\.\d+/
|
expect(text.chomp).to match(/\d+\.\d+\.\d+/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ require 'tempfile'
|
|||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.include TestConstruct::Helpers
|
config.include TestConstruct::Helpers
|
||||||
|
|
||||||
|
config.expect_with(:rspec) { |c| c.syntax = :expect }
|
||||||
|
|
||||||
config.before { ENV['HOME'] = home.to_s }
|
config.before { ENV['HOME'] = home.to_s }
|
||||||
|
|
||||||
config.before { silence! }
|
config.before { silence! }
|
||||||
|
|
||||||
def silence!
|
def silence!
|
||||||
homesick.stub(:say_status)
|
allow(homesick).to receive(:say_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
def given_castle(path, subdirs = [])
|
def given_castle(path, subdirs = [])
|
||||||
|
|||||||
Reference in New Issue
Block a user