From a29ceffc9476c99ff02f0617d2e38627c526bac2 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Tue, 11 Mar 2008 22:42:47 -0700 Subject: implemented hashing macro; implemented custom matcher testing this macro --- spec/matchers/hash_the_same_as.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spec/matchers/hash_the_same_as.rb (limited to 'spec/matchers') diff --git a/spec/matchers/hash_the_same_as.rb b/spec/matchers/hash_the_same_as.rb new file mode 100644 index 0000000000..86e98f31a3 --- /dev/null +++ b/spec/matchers/hash_the_same_as.rb @@ -0,0 +1,26 @@ +module HashTheSameAsMatcher + class HashTheSameAs + def initialize(expected) + @expected = expected + end + + def matches?(target) + @target = target + hash = {} + hash[@expected] = :some_arbitrary_value + hash[@target] == :some_arbitrary_value + end + + def failure_message + "expected #{@target} to hash the same as #{@expected}; they must be `eql?` and have the same `#hash` value" + end + + def negative_failure_message + "expected #{@target} 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 \ No newline at end of file -- cgit v1.2.3