From 148d18565fa23ae568f82b56ee77b05718a9af46 Mon Sep 17 00:00:00 2001 From: Jeremy Cook Date: Thu, 2 Jan 2014 10:27:11 -0500 Subject: [PATCH] Added tests for untested methods. --- spec/homesick_spec.rb | 55 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 0c3084c..c5dad79 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -363,9 +363,26 @@ describe 'homesick' do end describe 'diff' do + it 'should output an empty message when there are no changes to commit' do + given_castle('castle_repo') + some_rc_file = home.file '.some_rc_file' + homesick.track(some_rc_file.to_s, 'castle_repo') + Capture.stdout { homesick.commit 'castle_repo', 'Adding a file to the test' } + text = Capture.stdout { homesick.diff('castle_repo') } + text.should eq('') + end - xit 'needs testing' - + it 'should output a diff message when there are changes to commit' do + given_castle('castle_repo') + some_rc_file = home.file '.some_rc_file' + homesick.track(some_rc_file.to_s, 'castle_repo') + Capture.stdout { homesick.commit 'castle_repo', 'Adding a file to the test' } + File.open(some_rc_file.to_s, 'w') do |file| + file.puts "Some test text" + end + text = Capture.stdout { homesick.diff('castle_repo') } + text.should =~ /diff --git.+Some test text$/m + end end describe 'show_path' do @@ -379,19 +396,43 @@ describe 'homesick' do end 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') + homesick.pull 'castle_repo' + end - xit 'needs testing' + it 'should print an error message when trying to pull a non-existant castle' do + homesick.should_receive("say_status").once.with(:error, /Could not pull castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) + expect { homesick.pull "castle_repo" }.to raise_error(SystemExit) + end describe '--all' do - xit 'needs testing' + 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.with('git submodule --quiet init') + homesick.stub(:system).exactly(2).times.with('git submodule --quiet update --init --recursive >/dev/null 2>&1') + Capture.stdout { Capture.stderr { homesick.invoke 'pull', [], all: true } } + end end end 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') + homesick.push 'castle_repo' + end - xit 'needs testing' - + it 'should print an error message when trying to push a non-existant castle' do + homesick.should_receive("say_status").once.with(:error, /Could not push castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) + expect { homesick.push "castle_repo" }.to raise_error(SystemExit) + end end describe 'track' do @@ -560,7 +601,7 @@ describe 'homesick' do it "returns an error message when the $EDITOR environment variable is not set" do ENV.stub(:[]).with('EDITOR').and_return(nil) # Set the default editor to make sure it fails. - homesick.should_receive("say_status").once.with(:error,"The $EDITOR environment variable must be set to use this command", :red) + homesick.should_receive("say_status").once.with(:error, "The $EDITOR environment variable must be set to use this command", :red) expect { homesick.open "castle_repo" }.to raise_error(SystemExit) end