diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 51d62e4..47289eb 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -10,7 +10,7 @@ describe 'homesick' do 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 context 'has a .homesickrc' do @@ -28,7 +28,7 @@ describe 'homesick' do expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname)) homesick.clone local_repo - castles.join('some_repo').join('testing').should exist + expect(castles.join('some_repo').join('testing')).to exist end end @@ -39,7 +39,7 @@ describe 'homesick' do homesick.clone local_repo - castles.join('wtf').readlink.should == local_repo + expect(castles.join('wtf').readlink).to eq(local_repo) end context 'when it exists in a repo directory' do @@ -49,7 +49,7 @@ describe 'homesick' do end it 'should raise 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) end end @@ -63,51 +63,51 @@ describe 'homesick' do Capture.stderr do homesick.clone "file://#{bare_repo}" end - File.directory?(File.join(home.to_s, '.homesick/repos/dotfiles')) - .should be_true + expect(File.directory?(File.join(home.to_s, '.homesick/repos/dotfiles'))) + .to be_true end it 'should clone 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') homesick.clone 'git://github.com/technicalpickles/pickled-vim.git' end it 'should clone 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') homesick.clone 'git@github.com:technicalpickles/pickled-vim.git' end it 'should clone 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') homesick.clone 'http://github.com/technicalpickles/pickled-vim.git' end it 'should clone 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') homesick.clone 'http://github.com/technicalpickles/pickled-vim' end it 'should clone 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' end it 'should throw 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 end it 'should clone a github repo' do - homesick.should_receive(:git_clone) + expect(homesick).to receive(:git_clone) .with('https://github.com/wfarr/dotfiles.git', 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)) homesick.rc castle - castle.join('testing').should exist + expect(castle.join('testing')).to exist 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) homesick.rc castle - castle.join('testing').should_not exist + expect(castle.join('testing')).not_to exist end end end @@ -167,7 +167,7 @@ describe 'homesick' do homesick.link('glencairn') - home.join('.some_dotfile').readlink.should == dotfile + expect(home.join('.some_dotfile').readlink).to eq(dotfile) end it 'links non-dotfiles from a castle to the home folder' do @@ -175,7 +175,7 @@ describe 'homesick' do homesick.link('glencairn') - home.join('bin').readlink.should == dotfile + expect(home.join('bin').readlink).to eq(dotfile) end context 'when forced' do @@ -190,7 +190,7 @@ describe 'homesick' do homesick.link('glencairn') - existing_dotdir_link.readlink.should == dotdir + expect(existing_dotdir_link.readlink).to eq(dotdir) end it 'can override existing directory' do @@ -200,7 +200,7 @@ describe 'homesick' do homesick.link('glencairn') - existing_dotdir.readlink.should == dotdir + expect(existing_dotdir.readlink).to eq(dotdir) end end @@ -213,8 +213,8 @@ describe 'homesick' do homesick.link('glencairn') home_dotdir = home.join('.config') - home_dotdir.symlink?.should be == false - home_dotdir.join('.some_dotfile').readlink.should == dotfile + expect(home_dotdir.symlink?).to eq(false) + expect(home_dotdir.join('.some_dotfile').readlink).to eq(dotfile) end end @@ -227,8 +227,8 @@ describe 'homesick' do homesick.link('glencairn') home_dotdir = home.join('.config').join('appA') - home_dotdir.symlink?.should be == false - home_dotdir.join('.some_dotfile').readlink.should == dotfile + expect(home_dotdir.symlink?).to eq(false) + expect(home_dotdir.join('.some_dotfile').readlink).to eq(dotfile) end end @@ -246,12 +246,12 @@ describe 'homesick' do home_config_dir = home.join('.config') home_someapp_dir = home_config_dir.join('someapp') - home_config_dir.symlink?.should be == false - home_config_dir.join('.some_dotfile').readlink - .should be == config_dotfile - home_someapp_dir.symlink?.should be == false - home_someapp_dir.join('.some_appfile').readlink - .should == someapp_dotfile + expect(home_config_dir.symlink?).to eq(false) + expect(home_config_dir.join('.some_dotfile').readlink) + .to eq(config_dotfile) + expect(home_someapp_dir.symlink?).to eq(false) + expect(home_someapp_dir.join('.some_appfile').readlink) + .to eq(someapp_dotfile) end end @@ -262,7 +262,7 @@ describe 'homesick' do homesick.link - home.join('.some_dotfile').readlink.should == dotfile + expect(home.join('.some_dotfile').readlink).to eq(dotfile) end end end @@ -276,7 +276,7 @@ describe 'homesick' do homesick.link('glencairn') homesick.unlink('glencairn') - home.join('.some_dotfile').should_not exist + expect(home.join('.some_dotfile')).not_to exist end it 'unlinks non-dotfiles from the home folder' do @@ -285,7 +285,7 @@ describe 'homesick' do homesick.link('glencairn') homesick.unlink('glencairn') - home.join('bin').should_not exist + expect(home.join('bin')).not_to exist end context "with '.config' in .homesick_subdir" do @@ -298,8 +298,8 @@ describe 'homesick' do homesick.unlink('glencairn') home_dotdir = home.join('.config') - home_dotdir.should exist - home_dotdir.join('.some_dotfile').should_not exist + expect(home_dotdir).to exist + expect(home_dotdir.join('.some_dotfile')).not_to exist end end @@ -313,8 +313,8 @@ describe 'homesick' do homesick.unlink('glencairn') home_dotdir = home.join('.config').join('appA') - home_dotdir.should exist - home_dotdir.join('.some_dotfile').should_not exist + expect(home_dotdir).to exist + expect(home_dotdir.join('.some_dotfile')).not_to exist end end @@ -333,10 +333,10 @@ describe 'homesick' do home_config_dir = home.join('.config') home_someapp_dir = home_config_dir.join('someapp') - home_config_dir.should exist - home_config_dir.join('.some_dotfile').should_not exist - home_someapp_dir.should exist - home_someapp_dir.join('.some_appfile').should_not exist + expect(home_config_dir).to exist + expect(home_config_dir.join('.some_dotfile')).not_to exist + expect(home_someapp_dir).to exist + expect(home_someapp_dir.join('.some_appfile')).not_to exist end end @@ -349,7 +349,7 @@ describe 'homesick' do homesick.link homesick.unlink - home.join('.some_dotfile').should_not exist + expect(home.join('.some_dotfile')).not_to exist end end end @@ -359,11 +359,11 @@ describe 'homesick' do given_castle('zomg') given_castle('wtf/zomg') - homesick.should_receive(:say_status) + expect(homesick).to receive(:say_status) .with('zomg', 'git://github.com/technicalpickles/zomg.git', :cyan) - homesick.should_receive(:say_status) + expect(homesick).to receive(:say_status) .with('wtf/zomg', 'git://github.com/technicalpickles/zomg.git', :cyan) @@ -376,7 +376,7 @@ describe 'homesick' do it 'should say "nothing to commit" when there are no changes' do given_castle('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 it 'should say "Changes to be committed" when there are changes' do @@ -384,8 +384,9 @@ describe 'homesick' do some_rc_file = home.file '.some_rc_file' homesick.track(some_rc_file.to_s, '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 + ) end end @@ -398,7 +399,7 @@ describe 'homesick' do homesick.commit 'castle_repo', 'Adding a file to the test' end text = Capture.stdout { homesick.diff('castle_repo') } - text.should eq('') + expect(text).to eq('') end it 'should output a diff message when there are changes to commit' do @@ -412,7 +413,7 @@ describe 'homesick' do file.puts 'Some test text' end 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 @@ -420,7 +421,7 @@ describe 'homesick' do it 'should say the path of a castle' do 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') end @@ -429,14 +430,14 @@ describe 'homesick' do describe 'pull' do it 'should perform a pull, submodule init and update when the given castle exists' do given_castle('castle_repo') - homesick.stub(:system).once.with('git pull --quiet') - homesick.stub(: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 pull --quiet') + allow(homesick).to receive(:system).once.with('git submodule --quiet init') + allow(homesick).to receive(:system).once.with('git submodule --quiet update --init --recursive >/dev/null 2>&1') homesick.pull 'castle_repo' end it 'should print 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, %r{Could not pull castle_repo, expected .* exist and contain dotfiles}, :red) @@ -447,10 +448,10 @@ describe 'homesick' do it 'should pull each castle when invoked with --all' do given_castle('castle_repo') given_castle('glencairn') - homesick.stub(:system).exactly(2).times.with('git pull --quiet') - homesick.stub(:system).exactly(2).times + allow(homesick).to receive(:system).exactly(2).times.with('git pull --quiet') + allow(homesick).to receive(:system).exactly(2).times .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') Capture.stdout do Capture.stderr { homesick.invoke 'pull', [], all: true } @@ -463,12 +464,12 @@ describe 'homesick' do describe 'push' do it 'should perform a git push on the given castle' do given_castle('castle_repo') - homesick.stub(:system).once.with('git push') + allow(homesick).to receive(:system).once.with('git push') homesick.push 'castle_repo' end it 'should print 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, %r{Could not push castle_repo, expected .* exist and contain dotfiles}, :red) @@ -485,9 +486,9 @@ describe 'homesick' do homesick.track(some_rc_file.to_s, 'castle_repo') 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 it 'should handle files with parens' do @@ -498,9 +499,9 @@ describe 'homesick' do homesick.track(some_rc_file.to_s, 'castle_repo') 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 it 'should track a file in nested folder structure' do @@ -510,8 +511,8 @@ describe 'homesick' do homesick.track(some_nested_file.to_s, 'castle_repo') tracked_file = castle.join('some/nested/file.txt') - tracked_file.should exist - some_nested_file.readlink.should == tracked_file + expect(tracked_file).to exist + expect(some_nested_file.readlink).to eq(tracked_file) end it 'should track a nested directory' do @@ -521,8 +522,8 @@ describe 'homesick' do homesick.track(some_nested_dir.to_s, 'castle_repo') tracked_file = castle.join('some/nested/directory/') - tracked_file.should exist - some_nested_dir.realpath.should == tracked_file.realpath + expect(tracked_file).to exist + expect(some_nested_dir.realpath).to eq(tracked_file.realpath) end context 'when call with no castle name' do @@ -534,9 +535,9 @@ describe 'homesick' do homesick.track(some_rc_file.to_s) 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 @@ -548,7 +549,7 @@ describe 'homesick' do text = Capture.stdout do homesick.commit('castle_repo', 'Test message') end - text.should =~ /^\[master \(root-commit\) \w+\] Test message/ + expect(text).to match(/^\[master \(root-commit\) \w+\] Test message/) end end @@ -564,7 +565,7 @@ describe 'homesick' do subdir_file = castle.parent.join(Homesick::SUBDIR_FILENAME) File.open(subdir_file, 'r') do |f| - f.readline.should == "some/nested\n" + expect(f.readline).to eq("some/nested\n") end end @@ -578,7 +579,7 @@ describe 'homesick' do subdir_file = castle.parent.join(Homesick::SUBDIR_FILENAME) File.open(subdir_file, 'r') do |f| - f.readlines.size.should == 1 + expect(f.readlines.size).to eq(1) end end @@ -592,7 +593,7 @@ describe 'homesick' do subdir_file = castle.parent.join(Homesick::SUBDIR_FILENAME) 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 @@ -606,7 +607,7 @@ describe 'homesick' do homesick.track(some_rc_file.to_s, 'stronghold') homesick.destroy('stronghold') - some_rc_file.should_not be_exist + expect(some_rc_file).not_to be_exist end it 'deletes the cloned repository' do @@ -616,20 +617,20 @@ describe 'homesick' do homesick.track(some_rc_file.to_s, 'stronghold') homesick.destroy('stronghold') - castle.should_not be_exist + expect(castle).not_to be_exist end end describe 'cd' do it "cd's to the root directory of the given castle" do given_castle('castle_repo') - homesick.should_receive('inside').once.with(kind_of(Pathname)).and_yield - homesick.should_receive('system').once.with(ENV['SHELL']) + expect(homesick).to receive('inside').once.with(kind_of(Pathname)).and_yield + expect(homesick).to receive('system').once.with(ENV['SHELL']) Capture.stdout { homesick.cd 'castle_repo' } end 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, %r{Could not cd castle_repo, expected .* exist and contain dotfiles}, :red) @@ -640,19 +641,19 @@ describe 'homesick' do describe 'open' 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... - ENV.stub(:[]).and_call_original + allow(ENV).to receive(:[]).and_call_original # 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' - homesick.should_receive('inside').once.with(kind_of(Pathname)).and_yield - homesick.should_receive('system').once.with('vim') + expect(homesick).to receive('inside').once.with(kind_of(Pathname)).and_yield + expect(homesick).to receive('system').once.with('vim') Capture.stdout { homesick.open 'castle_repo' } end it 'returns an error message when the $EDITOR environment variable is not set' do # Set the default editor to make sure it fails. - ENV.stub(:[]).with('EDITOR').and_return(nil) - homesick.should_receive('say_status').once + allow(ENV).to receive(:[]).with('EDITOR').and_return(nil) + expect(homesick).to receive('say_status').once .with(:error, 'The $EDITOR environment variable must be set to use this command', :red) @@ -661,8 +662,8 @@ describe 'homesick' do it 'returns an error message when the given castle does not exist' do # Set a default just in case none is set - ENV.stub(:[]).with('EDITOR').and_return('vim') - homesick.should_receive('say_status').once + allow(ENV).to receive(:[]).with('EDITOR').and_return('vim') + expect(homesick).to receive('say_status').once .with(:error, %r{Could not open castle_repo, expected .* exist and contain dotfiles}, :red) @@ -673,7 +674,7 @@ describe 'homesick' do describe 'version' do it 'should print the current version of homesick' do text = Capture.stdout { homesick.version } - text.chomp.should =~ /\d+\.\d+\.\d+/ + expect(text.chomp).to match(/\d+\.\d+\.\d+/) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e594897..3a0e6b7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,7 +14,7 @@ RSpec.configure do |config| config.before { silence! } def silence! - homesick.stub(:say_status) + allow(homesick).to receive(:say_status) end def given_castle(path, subdirs = [])