Skip to content

Commit

Permalink
refactor test to reduce duplication and remove a helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Cornick committed Aug 7, 2009
1 parent 3212c0c commit 186d55d
Showing 1 changed file with 12 additions and 34 deletions.
46 changes: 12 additions & 34 deletions test/capistrano_rsync_with_remote_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ def stub_configuration(hash)
@rwrc.expects(:configuration).at_least_once.returns(hash)
end

def stub_detection_of_changed_local_cache(command, returned)
File.expects(:directory?).with('.rsync_cache').returns(true)
IO.expects(:popen).with(command).returns(returned)
end

context 'RsyncWithRemoteCache' do
setup do
@rwrc = Capistrano::Deploy::Strategy::RsyncWithRemoteCache.new
Expand Down Expand Up @@ -113,35 +108,18 @@ def stub_detection_of_changed_local_cache(command, returned)
end

context 'remove_cache_if_repo_changed' do
should 'purge local cache if it detects subversion info has changed' do
stub_configuration(:scm => :subversion, :repository => 'repository')
stub_detection_of_changed_local_cache("cd .rsync_cache && svn info . | sed -n 's/URL: //p'", "URL: url\n")
FileUtils.expects(:rm_rf).with('.rsync_cache')
@rwrc.send(:remove_cache_if_repo_changed)
end

should 'purge local cache if it detects git info has changed' do
stub_configuration(:scm => :git, :repository => 'repository')
stub_detection_of_changed_local_cache("cd .rsync_cache && git config remote.origin.url", "beep\n")
FileUtils.expects(:rm_rf).with('.rsync_cache')
@rwrc.send(:remove_cache_if_repo_changed)
end

should 'purge local cache if it detects hg info has changed' do
stub_configuration(:scm => :mercurial, :repository => 'repository')
stub_detection_of_changed_local_cache("cd .rsync_cache && hg showconfig paths.default", "beep\n")
FileUtils.expects(:rm_rf).with('.rsync_cache')
@rwrc.send(:remove_cache_if_repo_changed)
end

should 'purge local cache if it detects bzr info has changed' do
stub_configuration(:scm => :bzr, :repository => 'repository')
stub_detection_of_changed_local_cache("cd .rsync_cache && bzr info | grep parent | sed 's/^.*parent branch: //'", "beep\n")
FileUtils.expects(:rm_rf).with('.rsync_cache')
@rwrc.send(:remove_cache_if_repo_changed)
end

should 'not attempt to purge local cache that does not exist' do
[:subversion, :git, :mercurial, :bzr].each do |scm|
should "purge local cache if it detects #{scm} info has changed" do
stub_configuration(:scm => scm, :repository => 'repository')
info_command = Capistrano::Deploy::Strategy::RsyncWithRemoteCache::INFO_COMMANDS[scm]
File.expects(:directory?).with('.rsync_cache').returns(true)
IO.expects(:popen).with("cd .rsync_cache && #{info_command}").returns('abc')
FileUtils.expects(:rm_rf).with('.rsync_cache')
@rwrc.send(:remove_cache_if_repo_changed)
end
end

should 'not attempt to purge local cache if it does not exist' do
stub_configuration(:scm => :subversion, :repository => 'repository')
File.expects(:directory?).with('.rsync_cache').returns(false)
FileUtils.expects(:rm_rf).with('.rsync_cache').never
Expand Down

0 comments on commit 186d55d

Please sign in to comment.