Skip to content

Instantly share code, notes, and snippets.

@snowmantw
Forked from mattwynne/be_same_file_as.rb
Created July 7, 2012 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snowmantw/3066900 to your computer and use it in GitHub Desktop.
Save snowmantw/3066900 to your computer and use it in GitHub Desktop.
RSpec matcher to compare two file, using their MD5 hashes
RSpec::Matchers.define(:be_same_file_as) do |exected_file_path|
match do |actual_file_path|
md5_hash(actual_file_path).should == md5_hash(exected_file_path)
end
def md5_hash(file_path)
Digest::MD5.hexdigest(File.read(file_path))
end
end
# e.g. path_to_foo.should be_same_file_as(path_to_bar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment