 format = (message, args...) ->
   message.replace /{(\d)+}/g, (match, i) ->
     if typeof args[i] isnt 'undefined' then args[i] else match
+    
+#
+# [ [], [ "a" ], [ "b", "c" ] ]   => [ "a", "b", "c" ]
+# [ [], [], [] ]                  => []
+#
+# Don't care about this scenario:
+# [ [ [ "a" ] ], [ "b"] ]         => [ [ "a" ], "b" ]
+#
+# See: http://stackoverflow.com/a/10865042
+#
+flatten = (array) ->
+  [].concat.apply([], array)
 
 
 #

        if @_list[outer].equals( @_list[inner] )
          fail(messages.DuplicateExpectation, method_name, @_list[outer]._args)

  find_errors: (method_name) ->                           # method_name is for error messages; TODO: is there a better way?
    format(messages.ExpectationNeverCalled, method_name, expectation._args) for expectation in @_list when ! expectation._called


  add: (mock_method) ->
    @_list.push(mock_method)

  # returns [ "an error re method1()", "another error re method1()", "an error re method2()", ... ]
  find_errors: ->
    @_list.reduce ( (errors, mock_method) -> errors.concat(mock_method.find_errors()) ), []

  restore_original_methods: ->
    mock_method.restore_original_method() for mock_method in @_list
