Last active
February 10, 2023 14:29
-
-
Save sue445/8730600 to your computer and use it in GitHub Desktop.
[RSpec custom matcher] match hashes with indifferent access
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# match hashes with indifferent access | |
# | |
# example) | |
# expect({"key1" => 1, :key2 => 2}).to equal_with_indifferent_access(key1: 1, key2: 2) | |
RSpec::Matchers.define :equal_with_indifferent_access do |expected| | |
match do |actual| | |
actual.with_indifferent_access == expected.with_indifferent_access | |
end | |
failure_message_for_should do |actual| | |
<<-EOS | |
expected: #{expected} | |
got: #{actual} | |
EOS | |
end | |
failure_message_for_should_not do |actual| | |
<<-EOS | |
expected: value != #{expected} | |
got: #{actual} | |
EOS | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment