 is_mock_object = (object) ->
   object.constructor.name == 'MockObject'
 
-fail = (message, args...) ->  
+fail = (message, args...) ->
   throw new Error(format(message, args...))
 
 #

  matches: (args...) ->
    ( @_args.length == args.length ) and
      ( @_args.every ( element, i ) -> element == args[ i ] )
      
  # private
  
  _check_args_usage = (self, args) ->
    fail(messages.ArgsUsage) if args.length == 0
    fail(messages.ArgsUsedMoreThanOnce) unless self._args.length == 0
    fail(messages.ArgsUsedAfterReturnsOrThrows) if self._returns? or self._throws?
    
  _check_returns_usage = (self, value, arg_count) ->
    fail(messages.ReturnsUsage) unless value?
    fail(messages.ReturnsUsage) if arg_count != 1
    fail(messages.ReturnsUsedMoreThanOnce) if self._returns?
    fail(messages.ReturnsAndThrowsBothUsed) if self._throws?
    
  _check_throws_usage = (self, error, arg_count) ->
    fail(messages.ThrowsUsage) unless error?
    fail(messages.ThrowsUsage) if arg_count != 1
    fail(messages.ThrowsUsedMoreThanOnce) if self._throws?
    fail(messages.ReturnsAndThrowsBothUsed) if self._returns?
      
      
class ExpectationList
  
  constructor: ->
    @_list = []
    
  create_expectation: ->
    expectation = new Expectation()
    @_list.push(expectation)
    expectation
    
  find_expectation: (args...) ->
    for expectation in @_list when expectation.matches(args...)
      return expectation

# TODO: In error message names: Called, Used, or Specified: pick one
messages = require("../messages/messages.en.json")



mock = (args...) ->
