Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DataDaoDe/337fae191abc3827eb29fae37f4dac5c to your computer and use it in GitHub Desktop.
Save DataDaoDe/337fae191abc3827eb29fae37f4dac5c to your computer and use it in GitHub Desktop.
[RSpec custom matcher] match hashes with indifferent access
# match hashes with indifferent access
#
# example)
# expect({"key1" => 1, :key2 => 2}).to equal_with_indifferent_access(key1: 1, key2: 2)
RSpec::Matchers.define :eq_with_indifferent_access do |expected|
match do |actual|
actual.with_indifferent_access == expected.with_indifferent_access
end
failure_message do |actual|
<<-FAIL_MSG
expected: #{expected}
got: #{actual}
FAIL_MSG
end
failure_message_when_negated do |actual|
<<-FAIL_MSG
expected: value != #{expected}
got: #{actual}
FAIL_MSG
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment