 
   describe 'JavaScript functions', ->
 
-    describe 'up.fragment.all', ->
+    describe 'up.fragment.all()', ->
 
       it 'returns elements matching the given selector', ->
         match = fixture('.match')

          result = up.fragment.first(match, layer: 'root')
          expect(result).toBe(match)

    describe 'up.replace', ->

      describeCapability 'canPushState', ->

        beforeEach ->

          @$oldBefore = $fixture('.before').text('old-before')
          @$oldMiddle = $fixture('.middle').text('old-middle')
          @$oldAfter = $fixture('.after').text('old-after')

          @responseText =
            """
            <div class="before">new-before</div>
            <div class="middle">new-middle</div>
            <div class="after">new-after</div>
            """

          @respond = (options = {}) -> @respondWith(@responseText, options)

        it 'replaces the given selector with the same selector from a freshly fetched page', asyncSpec (next) ->
          up.replace('.middle', '/path')

          next =>
            @respond()

          next.after 10, =>
            expect($('.before')).toHaveText('old-before')
            expect($('.middle')).toHaveText('new-middle')
            expect($('.after')).toHaveText('old-after')

        it 'returns a promise that will be fulfilled once the server response was received and the fragments were swapped', asyncSpec (next) ->
          resolution = jasmine.createSpy()
          promise = up.replace('.middle', '/path')
          promise.then(resolution)
          expect(resolution).not.toHaveBeenCalled()
          expect($('.middle')).toHaveText('old-middle')

          next =>
            @respond()

          next =>
            expect(resolution).toHaveBeenCalled()
            expect($('.middle')).toHaveText('new-middle')

        it 'allows to pass an element instead of a selector', asyncSpec (next) ->
          up.replace(@$oldMiddle, '/path')

          next =>
            @respond()

          next =>
            expect($('.before')).toHaveText('old-before')
            expect($('.middle')).toHaveText('new-middle')
            expect($('.after')).toHaveText('old-after')

        describe 'with { transition } option', ->

          it 'returns a promise that will be fulfilled once the server response was received and the swap transition has completed', asyncSpec (next) ->
            resolution = jasmine.createSpy()
            promise = up.replace('.middle', '/path', transition: 'cross-fade', duration: 200)
            promise.then(resolution)
            expect(resolution).not.toHaveBeenCalled()
            expect($('.middle')).toHaveText('old-middle')

            next =>
              @respond()
              expect(resolution).not.toHaveBeenCalled()

            next.after 100, =>
              expect(resolution).not.toHaveBeenCalled()

            next.after 200, =>
              expect(resolution).toHaveBeenCalled()

        describe 'with { params } option', ->

          it "uses the given params as a non-GET request's payload", asyncSpec (next) ->
            givenParams = { 'foo-key': 'foo-value', 'bar-key': 'bar-value' }
            up.replace('.middle', '/path', method: 'put', params: givenParams)

            next =>
              expect(@lastRequest().data()['foo-key']).toEqual(['foo-value'])
              expect(@lastRequest().data()['bar-key']).toEqual(['bar-value'])

          it "encodes the given params into the URL of a GET request", asyncSpec (next) ->
            givenParams = { 'foo-key': 'foo-value', 'bar-key': 'bar-value' }
            up.replace('.middle', '/path', method: 'get', params: givenParams)
            next => expect(@lastRequest().url).toMatchURL('/path?foo-key=foo-value&bar-key=bar-value')

        it 'uses a HTTP method given as { method } option', asyncSpec (next) ->
          up.replace('.middle', '/path', method: 'put')
          next => expect(@lastRequest()).toHaveRequestMethod('PUT')

        describe 'when the server responds with an error', ->


              expect($('.up-insertion')).not.toBeAttached()

        it 'uses a { failTransition } option if the request failed'

    describe 'up.extract', ->

