Permalink
Browse files

use IO.popen to get SVN info - more LOC but easier to test/mock

  • Loading branch information...
1 parent 62a943d commit 0d06fa26eccfe3a909f583c4dcb541c542c594c0 @markcornick markcornick committed May 15, 2009
@@ -73,10 +73,14 @@ def rsync_host(server)
#
# TODO: punt in some sensible way if local_cache exists but is a regular file.
def command
- if (configuration[:scm] == :subversion &&
- `svn info #{local_cache} | sed -n 's/URL: //p'`.strip != configuration[:repository])
- logger.trace "repository has changed; removing old local cache"
- FileUtils.rm_rf local_cache
+ if configuration[:scm] == :subversion
+ svn_info = IO.popen("svn info #{local_cache} | sed -n 's/URL: //p'")
+ svn_url = svn_info.gets.chomp
+ svn_info.close
+ if svn_url != configuration[:repository]
+ logger.trace "repository has changed; removing old local cache"
+ FileUtils.rm_rf local_cache
+ end
end
if File.exists?(local_cache) && File.directory?(local_cache)
logger.trace "updating local cache to revision #{revision}"
@@ -118,13 +118,13 @@ def stub_creation_of_new_local_cache
context 'command' do
should 'recreate local cache if it detects subversion info has changed' do
- stub_configuration(:scm => :subversion)
- # FIXME: replace this with a mocha expectation/stub
- class << @rwrc
- def `(cmd)
- '\n'
- end
- end
+ stub_configuration(:scm => :subversion, :repository => 'repository')
+
+ svn_info_stub = stub()
+ svn_info_stub.expects(:gets).returns("URL: url\n")
+ svn_info_stub.expects(:close)
+ IO.expects(:popen).with("svn info .rsync_cache | sed -n 's/URL: //p'").returns(svn_info_stub)
+
FileUtils.expects(:rm_rf).with('.rsync_cache')
stub_creation_of_new_local_cache

0 comments on commit 0d06fa2

Please sign in to comment.