 
   describe 'JavaScript functions', ->
   
-    describe 'up.$compiler', ->
+    describe 'up.compiler', ->
       
       it 'applies an event initializer whenever a matching fragment is inserted', ->
-  
-        observeClass = jasmine.createSpy()
-        up.$compiler '.child', ($element) ->
-          observeClass($element.attr('class'))
-  
-        up.hello(affix('.container .child'))
+        observeElement = jasmine.createSpy()
+        up.compiler '.child', (element) -> observeElement(element)
+
+        $container = affix('.container')
+        $child = $container.affix('.child')
+        $otherChild = $container.affix('.other-child')
+
+        up.hello($container[0])
    
-        expect(observeClass).not.toHaveBeenCalledWith('container')
-        expect(observeClass).toHaveBeenCalledWith('child')
+        expect(observeElement).not.toHaveBeenCalledWith($container[0])
+        expect(observeElement).not.toHaveBeenCalledWith($otherChild[0])
+        expect(observeElement).toHaveBeenCalledWith($child[0])
 
       describe 'destructors', ->
 
         it 'allows compilers to return a function to call when the compiled element is destroyed', asyncSpec (next) ->
           destructor = jasmine.createSpy('destructor')
-          up.$compiler '.child', ($element) ->
+          up.compiler '.child', (element) ->
             destructor
 
-          up.hello(affix('.container .child'))
+          up.hello(affix('.container .child')[0])
 
           next =>
             expect(destructor).not.toHaveBeenCalled()


        it 'parses an [up-data] attribute as JSON and passes the parsed object as a second argument to the compiler', ->
          observeArgs = jasmine.createSpy()
          up.$compiler '.child', ($element, data) ->
            observeArgs($element.attr('class'), data)

          data = { key1: 'value1', key2: 'value2' }

          $tag = affix(".child").attr('up-data', JSON.stringify(data))
          up.hello($tag)

          expect(observeArgs).toHaveBeenCalledWith('child', data)

        it 'passes an empty object as a second argument to the compiler if there is no [up-data] attribute', ->
          observeArgs = jasmine.createSpy()
          up.$compiler '.child', ($element, data) ->
            observeArgs($element.attr('class'), data)

          up.hello(affix(".child"))



        it 'runs all destructors if multiple compilers are applied to the same element', asyncSpec (next) ->
          destructor1 = jasmine.createSpy('destructor1')
          up.compiler '.one', (element) -> destructor1
          destructor2 = jasmine.createSpy('destructor2')
          up.compiler '.two', (element) -> destructor2

          $element = affix('.one.two')
          up.hello($element)
