-
-
Save mattwynne/736421 to your computer and use it in GitHub Desktop.
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) |
I ran across this on Google and it helped me tremendously. You rule.
π
A very small revision to avoid a depreation warning :
line 3:
expect(md5_hash(actual_file_path)).to eq(md5_hash(exected_file_path))
Wow, amazing that this is still useful after 10 years! I've revised the original with your edits, thanks @thomasdarde!
Even more amazing is your reactivity after 10 years π
Just one small additional correction -- a typo in expected_file_path
.
Just one small additional correction -- a typo in
expected_file_path
.
How did it take 10 years for someone to spot this!? ππ
Fixed.
Ah, of course this code needing correction was not 10 years old π€¦
Just one small additional correction -- a typo in
expected_file_path
.
You have the same typo on line 1 π
Looks great! @mattwyne, where do you usually put custom matcher files under
spec
folder? Is itsupport
,shared_matchers
subfolder or some other folder?