 _ = require 'underscore'
+
+unorderedEqual = (one, two) ->
+  return false if one.length != two.length
+  for val in one
+    return false unless _.contains(two, val)
+  true
 
 beforeEach ->
   @addMatchers


            when "Array"
              if actual.length != expected.length
                addFailure(path, "has length #{actual.length}", "has length #{expected.length}")
              else
                for value, i in actual
                  compare(appendToPath(path, i), actual[i], expected[i])

            when "Object"
              actualKeys = _.keys(actual)
              expectedKeys = _.keys(expected)
              unless unorderedEqual(actualKeys, expectedKeys)
                addFailure(path, "has keys #{JSON.stringify(actualKeys.sort())}", "has keys #{JSON.stringify(expectedKeys.sort())}")
              else
                for key, value of actual
                  continue unless actual.hasOwnProperty(key)
