aboutsummaryrefslogblamecommitdiffstats
path: root/spec/matchers/hash_the_same_as.rb
blob: c1903b62b4ba1ad8b8fd6d16a7b3f7bc7a0deafb (plain) (tree)
1
2
3
4
5
6
7
8
9
10





                            

                        

                                             
                                            


                       
                                                                                                                 


                                
                                                                                                                             






                                
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