     Expectation.verify()
   finally
     delete Object.prototype.expects
-    for expectation in Expectation._all_expectations     # TODO: do this in reverse
+    for expectation in all_expectations     # TODO: do this in reverse
       object = if typeof expectation._object == 'function' then expectation._object.prototype else expectation._object
       if expectation._original_method?
         object[ expectation.method_name ] = expectation._original_method

    expectation._returns

_find_expectation = (object, method_name, args...) ->
  for expectation in Expectation._all_expectations when expectation.matches(object, method_name, args...)
    return expectation
  undefined

_check_for_duplicate_expectations = (mock) ->
  # TODO: use each with index and slice to avoid last element
  expectations = Expectation._all_expectations
  return if expectations.length < 2
  for outer in [0..expectations.length-2]
    for inner in [outer+1..expectations.length-1]
      if expectations[outer].equals( expectations[inner] )
        _throw_duplicate_expectation("#{expectations[outer].method_name}(#{expectations[outer]._args})") 

_build_errors = (expectation) ->
  # TODO: use a mapping function?
  errors = ""
  for expectation in expectation._all_expectations when expectation.called == false
    errors += "'#{expectation.method_name}(#{expectation._args})' was never called\n"
  errors


all_expectations = []


class Expectation
  
  #
  @verify: ->
