 #
-# Expectation represents a mocked method that we expect to be called.  
-# It stores the method name, the arguments that we expect to be called 
-# with, a value to return or throw, and whether it has actually been 
+# Expectation represents a mocked method that we expect to be called.
+# It stores the method name, the arguments that we expect to be called
+# with, a value to return or throw, and whether it has actually been
 # called.  For example, the following:
 #
 #   my_mock = new Mock()

    _check_args_usage(@, args...)
    _save_args(@, args)
    @
    
  #
  # my_mock = new Mock()
  # expectation = my_mock.expects("my_method")

      ( @_args.every ( element, i ) -> element == args[ i ] )


# private

_check_args_usage = (expectation, args...) ->
  _throw_args_usage() if args.length == 0
  _throw_args_called_more_than_once() unless expectation._args.length == 0

_check_returns_usage = (expectation, value) ->
  _throw_returns_usage() unless value?
  _throw_returns_called_more_than_once() if expectation._returns?
  _throw_returns_and_throws_both_called() if expectation._throws?

_check_throws_usage = (expectation, error) ->
  _throw_throws_usage(error) unless error?
  _throw_throws_called_more_than_once() if expectation._throws?
  _throw_returns_and_throws_both_called() if expectation._returns?

_save_args = (expectation, args) ->
  expectation._args = args

_save_returns = (expectation, value) ->
  expectation._returns = value

_save_throws = (expectation, error) ->
  expectation._throws = error

_throw_args_usage = ->
  throw "you need to supply at least one argument to .args(), e.g. my_mock.expects('my_method').args(42)"

_throw_args_called_more_than_once = ->
  throw new Error("you called args() more than once, e.g. my_mock.expects('my_method').args(1).args(2); call it just once")

_throw_returns_usage = ->
  throw "you need to supply an argument to .returns(), e.g. my_mock.expects('my_method').returns(123)"

_throw_returns_called_more_than_once = ->
  throw new Error("you called returns() more than once, e.g. my_mock.expects('my_method').returns(1).returns(2); call it just once")

_throw_throws_usage = ->
  throw "you need to supply an argument to .throws(), e.g. my_mock.expects('my_method').throws('an error')"

_throw_throws_called_more_than_once = ->
  throw new Error("you called throws() more than once, e.g. my_mock.expects('my_method').throws('something').throws('something else'); call it just once")

_throw_returns_and_throws_both_called = ->
  throw new Error("you called returns() and throws() on the same expectation; use one or the other but not both")



#
# Mock represents the mock of some object. @expectations is a list of
