 
   describe "when the grammar is updated because a grammar it includes is activated", ->
     it "retokenizes the buffer", ->
-      atom.packages.activatePackage('language-ruby-on-rails', sync: true)
-      atom.packages.activatePackage('language-ruby', sync: true)
-
-      buffer = atom.project.bufferForPathSync()
-      buffer.setText "<div class='name'><%= User.find(2).full_name %></div>"
-      tokenizedBuffer = new TokenizedBuffer({buffer})
-      tokenizedBuffer.setGrammar(atom.syntax.selectGrammar('test.erb'))
-      fullyTokenize(tokenizedBuffer)
-
-      {tokens} = tokenizedBuffer.lineForScreenRow(0)
-      expect(tokens[0]).toEqual value: "<div class='name'>", scopes: ["text.html.ruby"]
-
-      atom.packages.activatePackage('language-html', sync: true)
-      fullyTokenize(tokenizedBuffer)
-      {tokens} = tokenizedBuffer.lineForScreenRow(0)
-      expect(tokens[0]).toEqual value: '<', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.begin.html"]
+
+      waitsForPromise ->
+        atom.packages.activatePackage('language-ruby-on-rails')
+
+      waitsForPromise ->
+        atom.packages.activatePackage('language-ruby')
+
+      runs ->
+        buffer = atom.project.bufferForPathSync()
+        buffer.setText "<div class='name'><%= User.find(2).full_name %></div>"
+        tokenizedBuffer = new TokenizedBuffer({buffer})
+        tokenizedBuffer.setGrammar(atom.syntax.selectGrammar('test.erb'))
+        fullyTokenize(tokenizedBuffer)
+
+        {tokens} = tokenizedBuffer.lineForScreenRow(0)
+        expect(tokens[0]).toEqual value: "<div class='name'>", scopes: ["text.html.ruby"]
+
+      waitsForPromise ->
+        atom.packages.activatePackage('language-html')
+
+      runs ->
+        fullyTokenize(tokenizedBuffer)
+        {tokens} = tokenizedBuffer.lineForScreenRow(0)
+        expect(tokens[0]).toEqual value: '<', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.begin.html"]
 
   describe ".tokenForPosition(position)", ->
     afterEach ->


  describe "when the buffer contains surrogate pairs", ->
    beforeEach ->
      atom.packages.activatePackage('language-javascript', sync: true)
      buffer = atom.project.bufferForPathSync 'sample-with-pairs.js'
      buffer.setText """
        'abc\uD835\uDF97def'
        //\uD835\uDF97xyz
      """
      tokenizedBuffer = new TokenizedBuffer({buffer})
      fullyTokenize(tokenizedBuffer)

    afterEach ->
      tokenizedBuffer.destroy()


  describe "when the buffer contains hard-tabs", ->
    beforeEach ->
      waitsForPromise ->
        atom.packages.activatePackage('language-coffee-script')

      runs ->
        buffer = atom.project.bufferForPathSync('sample-with-tabs.coffee')
        tokenizedBuffer = new TokenizedBuffer({buffer})
        startTokenizing(tokenizedBuffer)

    afterEach ->
      tokenizedBuffer.destroy()
