Permalink
Browse files

Merge pull request #65 from ebeigarts/fix-md5

Use Digest::MD5 instead of md5 shell command, which is not available on Linux. Fixes #53
  • Loading branch information...
2 parents 917ea55 + 8faf94d commit aa8d5c148326604a8719bcbcf8ff75a115ab7daa @crafterm committed Apr 10, 2012
Showing with 10 additions and 1 deletion.
  1. +2 −1 lib/sprinkle/verifiers/file.rb
  2. +1 −0 spec/fixtures/my_file.txt
  3. +7 −0 spec/sprinkle/verify_spec.rb
View
3 lib/sprinkle/verifiers/file.rb
@@ -26,7 +26,8 @@ def user_present(username)
end
def matches_local(localfile, remotefile, mode=nil)
raise "Couldn't find local file #{localfile}" unless ::File.exists?(localfile)
- local = `md5 #{localfile}`.split.last
+ require 'digest/md5'
+ local = Digest::MD5.hexdigest(::File.read(localfile))
@commands << %{[ "X$(md5sum #{remotefile}|cut -d\\ -f 1)" = "X#{local}" ]}
end
end
View
1 spec/fixtures/my_file.txt
@@ -0,0 +1 @@
+...
View
7 spec/sprinkle/verify_spec.rb
@@ -12,6 +12,9 @@
# Check that a file contains a substring
file_contains 'my_file.txt', 'A sunny day on the lower east-side'
+ # Checks that a file matches a local file
+ matches_local File.join(File.dirname(__FILE__), '..', 'fixtures', 'my_file.txt'), 'my_file.txt'
+
# Check a directory exists
has_directory 'mydir'
@@ -73,6 +76,10 @@
@verification.commands.should include("grep 'A sunny day on the lower east-side' my_file.txt")
end
+ it 'should do a md5sum to see if a file matches local file' do
+ @verification.commands.should include(%{[ "X$(md5sum my_file.txt|cut -d\\ -f 1)" = "Xed20d984b757ad5291963389fc209864" ]})
+ end
+
it 'should do a "test -d" on the has_directory check' do
@verification.commands.should include('test -d mydir')
end

0 comments on commit aa8d5c1

Please sign in to comment.