 #
 class ExpectsMethod
   
-  constructor: (expects_method_name) ->
+  constructor: (expects_method_name, all_expectations) ->
     _check_constructor_usage(expects_method_name)
-    _install_expects_method(expects_method_name)
+    _install_expects_method(expects_method_name, all_expectations)
     _install_uninstall_expects_method(@, expects_method_name)
 
   # private

    try
      _check_mock_usage(args)
      [ expects_method_name, mock_count, test_function ] = _parse_args(args)
      expects_method = new ExpectsMethod(expects_method_name)
      convenience_mocks = _build_convenience_mock_objects(mock_count)
      _run_test_function(test_function, convenience_mocks)
      AllExpectations.verify_all_expectations()
    finally
      expects_method.uninstall_expects_method() if expects_method?  # TODO: the 'if' guard smells.
      AllExpectations.uninstall_all_mocked_methods()
      AllExpectations.unregister_all_expectations()

  # private
  


  # private

  _install_mock_method = (expectation, all_expectations) ->
    methods = if is_class(expectation._object) then expectation._object.prototype else expectation._object
    original_method = methods[ expectation._method_name ]
    methods[ expectation._method_name ] = _build_mocked_method(expectation._method_name, all_expectations)
    if original_method?
      expectation.uninstall_mocked_method = -> methods[ expectation._method_name ] = original_method
    else
      expectation.uninstall_mocked_method = -> delete methods[ expectation._method_name ]
  
  _build_mocked_method = (method_name, all_expectations) ->
    (args...) ->
      all_expectations.check_for_duplicate_expectations()    # TODO: explain why we call this here
      _invoke( all_expectations.find_expectation(@, method_name, args...) )
      
  _invoke = (expectation) ->
    expectation._called = yes
