Skip to content

Instantly share code, notes, and snippets.

@mattwynne
Last active May 21, 2022 13:27
Show Gist options
  • Save mattwynne/736421 to your computer and use it in GitHub Desktop.
Save mattwynne/736421 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|
expect(md5_hash(actual_file_path)).to eq(md5_hash(expected_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)
@thomasdarde
Copy link

Even more amazing is your reactivity after 10 years 👍

@EmmaB
Copy link

EmmaB commented Jan 9, 2021

Just one small additional correction -- a typo in expected_file_path.

@mattwynne
Copy link
Author

Just one small additional correction -- a typo in expected_file_path.

How did it take 10 years for someone to spot this!? 😀🙈

Fixed.

@mattwynne
Copy link
Author

Ah, of course this code needing correction was not 10 years old 🤦

@Timothy04
Copy link

Just one small additional correction -- a typo in expected_file_path.

You have the same typo on line 1 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment