 path = require 'path'
 fs = require 'fs-plus'
-{WorkspaceView} = require 'atom'
 temp = require 'temp'
 
 describe "Whitespace", ->
-  [editor, buffer] = []
+  [editor, buffer, workspaceElement] = []
 
   beforeEach ->
     directory = temp.mkdirSync()
     atom.project.setPath(directory)
-    atom.workspaceView = new WorkspaceView()
-    atom.workspace = atom.workspaceView.model
+    workspaceElement = atom.views.getView(atom.workspace)
     filePath = path.join(directory, 'atom-whitespace.txt')
     fs.writeFileSync(filePath, '')
     fs.writeFileSync(path.join(directory, 'sample.txt'), 'Some text.\n')


  describe "when the editor is split", ->
    it "does not throw exceptions when the editor is saved after the split is closed (regression)", ->
      atom.workspaceView.getActivePaneView().trigger 'pane:split-right'
      atom.workspace.getPanes()[0].destroyItems()

      editor = atom.workspace.activePaneItem

      buffer.setText("foo   \nbar\t   \n\nbaz")

    it "removes the trailing whitespace in the active editor", ->
      atom.commands.dispatch(workspaceElement, 'whitespace:remove-trailing-whitespace')
      expect(buffer.getText()).toBe "foo\nbar\n\nbaz"

    it "does not attempt to remove whitespace when the package is deactivated", ->
