aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support/matchers/hash_the_same_as.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/matchers/hash_the_same_as.rb')
-rw-r--r--spec/support/matchers/hash_the_same_as.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/support/matchers/hash_the_same_as.rb b/spec/support/matchers/hash_the_same_as.rb
new file mode 100644
index 0000000000..03e955a0cb
--- /dev/null
+++ b/spec/support/matchers/hash_the_same_as.rb
@@ -0,0 +1,26 @@
+module HashTheSameAsMatcher
+ class HashTheSameAs
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def matches?(actual)
+ @actual = actual
+ hash = {}
+ hash[@expected] = :some_arbitrary_value
+ hash[@actual] == :some_arbitrary_value
+ end
+
+ def failure_message
+ "expected #{@actual} to hash the same as #{@expected}; they must be `eql?` and have the same `#hash` value"
+ end
+
+ def negative_failure_message
+ "expected #{@actual} to hash differently than #{@expected}; they must not be `eql?` or have a differing `#hash` values"
+ end
+ end
+
+ def hash_the_same_as(expected)
+ HashTheSameAs.new(expected)
+ end
+end