diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-11 22:42:47 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-03-11 22:42:47 -0700 |
commit | a29ceffc9476c99ff02f0617d2e38627c526bac2 (patch) | |
tree | fc9aa702ad9a2f506a4a51b71791798fb8a6ca4b /spec/matchers | |
parent | 98527c8f7dd64f086895c1576fb33e8b91071142 (diff) | |
download | rails-a29ceffc9476c99ff02f0617d2e38627c526bac2.tar.gz rails-a29ceffc9476c99ff02f0617d2e38627c526bac2.tar.bz2 rails-a29ceffc9476c99ff02f0617d2e38627c526bac2.zip |
implemented hashing macro; implemented custom matcher testing this macro
Diffstat (limited to 'spec/matchers')
-rw-r--r-- | spec/matchers/hash_the_same_as.rb | 26 |
1 files changed, 26 insertions, 0 deletions
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 |