Resource: push conditional down into #verify_download_integrity

This commit is contained in:
Jack Nagel 2013-10-30 00:43:10 -05:00
parent a5b2814770
commit 2dd44f7791
2 changed files with 7 additions and 6 deletions

View File

@ -48,8 +48,7 @@ class Resource
# If block is given, yield to that block
# A target or a block must be given, but not both
def stage(target=nil)
fetched = fetch
verify_download_integrity(fetched) if fetched.respond_to?(:file?) and fetched.file?
verify_download_integrity(fetch)
mktemp(download_name) do
downloader.stage
if block_given?
@ -75,7 +74,9 @@ class Resource
end
def verify_download_integrity fn
fn.verify_checksum(checksum)
if fn.respond_to?(:file?) && fn.file?
fn.verify_checksum(checksum)
end
rescue ChecksumMissingError
opoo "Cannot verify integrity of #{fn.basename}"
puts "A checksum was not provided for this resource"

View File

@ -106,15 +106,15 @@ class ResourceTests < Test::Unit::TestCase
fn = Pathname.new('test')
checksum = @resource.sha1('baadidea'*5)
fn.expects(:verify_checksum).
with(checksum).raises(ChecksumMissingError)
fn.stubs(:file? => true)
fn.expects(:verify_checksum).raises(ChecksumMissingError)
fn.expects(:sha1)
shutup { @resource.verify_download_integrity(fn) }
end
def test_verify_download_integrity_mismatch
fn = Object.new
fn = stub(:file? => true)
checksum = @resource.sha1('baadidea'*5)
fn.expects(:verify_checksum).with(checksum).