     # Initialize shared variables
     dispatcher = params = routeOptions = null
 
-    # Unique ID counter for creating params objects
-    paramsId = 0
-
     # Fake route objects, walk like a route and swim like a route
 
     route1 = controller: 'test1', action: 'show'

    redirectToURLRoute = controller: 'test1', action: 'redirectToURL'
    redirectToControllerRoute = controller: 'test1', action: 'redirectToController'

    Test1Controller = null
    Test2Controller = null

    loadTest1ControllerAndExecute = null
    loadTest2ControllerAndExecute = null

    beforeEach ->
      dispatcher = new Dispatcher()

      # Define test controllers. The classes are redefined before each spec to
      # ensure a spec fiddling around with their prototype can't break other specs.

      Test1Controller = class Test1Controller extends Controller

        historyURL: (params) ->
          #console.debug 'Test1Controller#historyURL'
          'test1/' + if params.id? then params.id else ''

        initialize: (params, oldControllerName) ->
          #console.debug 'Test1Controller#initialize', params.id, oldControllerName
          super

        show: (params, oldControllerName) ->
          #console.debug 'Test1Controller#show', params, oldControllerName

        redirectToURL: (params, oldControllerName) ->
          @redirectTo '/test2/123'

        redirectToController: (params, oldControllerName) ->
          @redirectTo 'test2', 'show', params

        dispose: (params, newControllerName) ->
          #console.debug 'Test1Controller#dispose'
          super

      Test2Controller = class Test2Controller extends Controller

        historyURL: (params) ->
          #console.debug 'Test2Controller#historyURL'
          'test2/' + if params.id? then params.id else ''

        initialize: (params, oldControllerName) ->
          #console.debug 'Test2Controller#initialize', params, oldControllerName
          super

        show: (params, oldControllerName) ->
          #console.debug 'Test2Controller#show', params, oldControllerName

        dispose: (params, newControllerName) ->
          #console.debug 'Test2Controller#dispose'
          super

      # Define a test controller AMD modules
      test1Module = 'controllers/test1_controller'
      test2Module = 'controllers/test2_controller'
      define test1Module, -> Test1Controller
      define test2Module, -> Test2Controller

      # Helpers for asynchronous tests
      loadTest1ControllerAndExecute = (callback) -> require [test1Module], callback
      loadTest2ControllerAndExecute = (callback) -> require [test2Module], callback

    afterEach ->
      dispatcher.dispose()
      dispatcher = null


    # Reset helpers

    refreshParams = ->
      # Create a fresh params object which does not equal the previous one

      routeOptions = changeURL: false

    beforeEach refreshParams


    it 'should dispatch routes to controller actions', (done) ->
      proto = Test1Controller.prototype
