   delete Object.prototype.expects
 
 # TODO: write comment about uninstalling in reverse
+# TODO: move into AllExpectations
 uninstall_all_mocked_methods = ->
-  expectation.uninstall_mocked_method() for expectation in all_expectations by -1
+  expectation.uninstall_mocked_method() for expectation in AllExpectations._expectations by -1
 
 build_convenience_mock_objects = ->
   ( new Object() for i in [1..5] )

    throw expectation._throws if expectation._throws?
    expectation._returns

find_expectation = (object, method_name, args...) ->
  for expectation in all_expectations when expectation.matches(object, method_name, args...)
    return expectation
  undefined

check_for_duplicate_expectations = ->
  # TODO: use each with index and slice to avoid last element
  return if all_expectations.length < 2
  for outer in [0..all_expectations.length-2]
    for inner in [outer+1..all_expectations.length-1]
      if all_expectations[outer].equals( all_expectations[inner] )
        throw_duplicate_expectation("#{all_expectations[outer]._method_name}(#{all_expectations[outer]._args})")

throw_unknown_expectation = (expectation) ->
  throw new Error( "#{expectation} does not match any expectations" )

    install_expects_method()
    convenience_mocks = build_convenience_mock_objects()
    run_test_function(test_function, convenience_mocks)
    AllExpectations.verify_all_expectations()
  finally
    uninstall_expects_method()
    uninstall_all_mocked_methods()
    AllExpectations.unregister_all_expectations()

install_expects_method = ->
  Object.prototype.expects = expects
