From 801a91ec9b91ce2c3c061ae905cef8feae9c171f Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 29 Jun 2012 15:08:16 -0700 Subject: [PATCH] Specs cleanup buffers --- spec/app/edit-session-spec.coffee | 8 +- spec/app/editor-spec.coffee | 31 ++- spec/app/line-map-spec.coffee | 3 + spec/app/project-spec.coffee | 3 + spec/app/root-view-spec.coffee | 15 +- spec/app/screen-line-spec.coffee | 3 + spec/app/selection-spec.coffee | 5 +- spec/app/status-bar-spec.coffee | 4 + spec/app/tokenized-buffer-spec.coffee | 7 + spec/app/undo-manager-spec.coffee | 3 + spec/extensions/autocomplete-spec.coffee | 6 + .../command-interpreter-spec.coffee | 3 + spec/extensions/command-panel-spec.coffee | 5 + spec/extensions/file-finder-spec.coffee | 177 ------------------ spec/extensions/fuzzy-finder-spec.coffee | 23 ++- spec/extensions/snippets-spec.coffee | 3 + spec/extensions/tree-view-spec.coffee | 5 +- spec/spec-helper.coffee | 27 +-- src/app/editor.coffee | 2 +- src/app/project.coffee | 5 + src/app/root-view.coffee | 1 + 21 files changed, 107 insertions(+), 232 deletions(-) delete mode 100644 spec/extensions/file-finder-spec.coffee diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 463a92817..c1f0b7165 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1,3 +1,4 @@ +Project = require 'project' Buffer = require 'buffer' EditSession = require 'edit-session' @@ -11,6 +12,7 @@ describe "EditSession", -> tabText: ' ' autoIndent: false softWrap: false + project: new Project() lineLengths = buffer.getLines().map (line) -> line.length @@ -1329,12 +1331,6 @@ describe "EditSession", -> editSession.foldAll() expect(editSession.getCursorBufferPosition()).toEqual([5,5]) - describe ".destroy()", -> - it "triggers `destroy` event", -> - spyOn(editSession, 'trigger') - editSession.destroy() - expect(editSession.trigger).toHaveBeenCalledWith('destroy') - describe ".clipBufferPosition(bufferPosition)", -> it "clips the given position to a valid position", -> expect(editSession.clipBufferPosition([-1, -1])).toEqual [0,0] diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 6c9b301d3..3b24fa2b2 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -74,7 +74,6 @@ describe "Editor", -> newEditor.attachToDom() expect(newEditor.scrollTop()).toBe editor.scrollTop() expect(newEditor.scrollView.scrollLeft()).toBe 44 - newEditor.remove() describe "when the editor is attached to the dom", -> it "calculates line height and char width and updates the pixel position of the cursor", -> @@ -126,7 +125,7 @@ describe "Editor", -> describe ".remove()", -> it "removes subscriptions from all edit session buffers", -> previousEditSession = editor.activeEditSession - otherEditSession = rootView.project.open('sample.txt') + otherEditSession = rootView.project.open(rootView.project.resolve('sample.txt')) expect(previousEditSession.buffer.subscriptionCount()).toBeGreaterThan 1 editor.edit(otherEditSession) @@ -141,7 +140,7 @@ describe "Editor", -> editor.edit(rootView.project.open()) editSession = editor.activeEditSession spyOn(editSession, 'destroy').andCallThrough() - spyOn(editor, "remove") + spyOn(editor, "remove").andCallThrough() editor.trigger "close" expect(editSession.destroy).toHaveBeenCalled() expect(editor.remove).not.toHaveBeenCalled() @@ -151,20 +150,19 @@ describe "Editor", -> editSession = editor.activeEditSession expect(editor.mini).toBeFalsy() expect(editor.editSessions.length).toBe 1 - spyOn(editor, 'remove') + spyOn(editor, 'remove').andCallThrough() editor.trigger 'close' spyOn(editSession, 'destroy').andCallThrough() expect(editor.remove).toHaveBeenCalled() - editor.remove() - editor = new Editor(mini: true) - spyOn(editor, 'remove') - editor.trigger 'close' - expect(editor.remove).not.toHaveBeenCalled() + miniEditor = new Editor(mini: true) + spyOn(miniEditor, 'remove').andCallThrough() + miniEditor.trigger 'close' + expect(miniEditor.remove).not.toHaveBeenCalled() describe "when buffer is modified", -> it "triggers alert and does not close session", -> - spyOn(editor, 'remove') + spyOn(editor, 'remove').andCallThrough() spyOn($native, 'alert') editor.insertText("I AM CHANGED!") editor.trigger "close" @@ -279,12 +277,13 @@ describe "Editor", -> beforeEach -> rootView.remove() + tempFilePath = '/tmp/atom-temp.txt' fs.write(tempFilePath, "") rootView = new RootView(tempFilePath) + editor = rootView.activeEditor() project = rootView.project - editor.edit(rootView.project.open(tempFilePath)) expect(editor.buffer.getPath()).toBe tempFilePath afterEach -> @@ -316,7 +315,6 @@ describe "Editor", -> it "saves the buffer to the chosen path", -> selectedFilePath = '/tmp/temp.txt' - console.log 'about to save' editor.save() expect(fs.exists(selectedFilePath)).toBeTruthy() @@ -392,10 +390,10 @@ describe "Editor", -> describe "when not inside a pane", -> it "does not split the editor, but doesn't throw an exception", -> - editor.splitUp() - editor.splitDown() - editor.splitLeft() - editor.splitRight() + editor.splitUp().remove() + editor.splitDown().remove() + editor.splitLeft().remove() + editor.splitRight().remove() describe "editor-open event", -> it 'only triggers an editor-open event when it is first added to the DOM', -> @@ -1079,7 +1077,6 @@ describe "Editor", -> otherEditor.simulateDomAttachment() expect(otherEditor.setSoftWrapColumn).toHaveBeenCalled() - otherEditor.remove() describe "when some lines at the end of the buffer are not visible on screen", -> beforeEach -> diff --git a/spec/app/line-map-spec.coffee b/spec/app/line-map-spec.coffee index 01729d6d1..2891b92af 100644 --- a/spec/app/line-map-spec.coffee +++ b/spec/app/line-map-spec.coffee @@ -14,6 +14,9 @@ describe "LineMap", -> map = new LineMap [line0, line1, line2, line3, line4] = tokenizedBuffer.linesForScreenRows(0, 4) + afterEach -> + tokenizedBuffer.buffer.destroy() + describe ".insertAtBufferRow(row, lineFragments)", -> it "inserts the given line fragments before the specified buffer row", -> map.insertAtBufferRow(0, [line2, line3]) diff --git a/spec/app/project-spec.coffee b/spec/app/project-spec.coffee index af09987d0..15ef5e7b5 100644 --- a/spec/app/project-spec.coffee +++ b/spec/app/project-spec.coffee @@ -6,6 +6,9 @@ describe "Project", -> beforeEach -> project = new Project(require.resolve('fixtures/dir')) + afterEach -> + project.destroy() + describe "when editSession is destroyed", -> it "removes edit session and calls destroy on buffer (if buffer is not referenced by other edit sessions)", -> editSession = project.open("a") diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index cf24fe3ed..8344593bd 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -391,6 +391,7 @@ describe "RootView", -> newRootView = RootView.deserialize(rootView.serialize()) newRootView.activateExtension(extension) expect(extension.activate).toHaveBeenCalledWith(newRootView, "it worked") + newRootView.remove() it "throws an exception if the extension has no 'name' property", -> expect(-> rootView.activateExtension({ activate: -> })).toThrow() @@ -528,13 +529,13 @@ describe "RootView", -> it "opens an empty buffer in a new editor", -> rootView.open() expect(rootView.activeEditor()).toBeDefined() - expect(rootView.activeEditor().buffer.path).toBeUndefined() + expect(rootView.activeEditor().buffer.getPath()).toBeUndefined() describe "when called with a path", -> it "opens a buffer with the given path in a new editor", -> rootView.open('b') expect(rootView.activeEditor()).toBeDefined() - expect(rootView.activeEditor().buffer.path).toBe require.resolve('fixtures/dir/b') + expect(rootView.activeEditor().buffer.getPath()).toBe require.resolve('fixtures/dir/b') describe "when there is an active editor", -> beforeEach -> @@ -543,7 +544,7 @@ describe "RootView", -> describe "when called with no path", -> it "opens an empty buffer in the active editor", -> rootView.open() - expect(rootView.activeEditor().buffer.path).toBeUndefined() + expect(rootView.activeEditor().buffer.getPath()).toBeUndefined() describe "when called with a path", -> [editor1, editor2] = [] @@ -562,7 +563,7 @@ describe "RootView", -> describe "when the active editor has an edit session for the given path", -> it "re-activates the existing edit session", -> - expect(activeEditor.buffer.path).toBe require.resolve('fixtures/dir/a') + expect(activeEditor.buffer.getPath()).toBe require.resolve('fixtures/dir/a') previousEditSession = activeEditor.activeEditSession rootView.open('b') @@ -580,7 +581,7 @@ describe "RootView", -> describe "when the active editor has an edit session for the given path", -> it "re-activates the existing edit session regardless of whether any other editor also has an edit session for the path", -> activeEditor = rootView.activeEditor() - expect(activeEditor.buffer.path).toBe require.resolve('fixtures/dir/a') + expect(activeEditor.buffer.getPath()).toBe require.resolve('fixtures/dir/a') previousEditSession = activeEditor.activeEditSession rootView.open('b') @@ -595,11 +596,11 @@ describe "RootView", -> expect(rootView.activeEditor()).toBe editor1 rootView.open('b', allowActiveEditorChange: true) expect(rootView.activeEditor()).toBe editor2 - expect(editor2.buffer.path).toBe require.resolve('fixtures/dir/b') + expect(editor2.buffer.getPath()).toBe require.resolve('fixtures/dir/b') describe "when no other editor has an edit session for the path either", -> it "creates a new edit session for the path on the current active editor", -> path = require.resolve('fixtures/sample.js') rootView.open(path, allowActiveEditorChange: true) expect(rootView.activeEditor()).toBe editor1 - expect(editor1.buffer.path).toBe path + expect(editor1.buffer.getPath()).toBe path diff --git a/spec/app/screen-line-spec.coffee b/spec/app/screen-line-spec.coffee index 6a6a76ffa..86c5e795a 100644 --- a/spec/app/screen-line-spec.coffee +++ b/spec/app/screen-line-spec.coffee @@ -11,6 +11,9 @@ describe "ScreenLine", -> tokenizedBuffer = new TokenizedBuffer(buffer, tabText) screenLine = tokenizedBuffer.lineForScreenRow(3) + afterEach -> + buffer.destroy() + describe ".splitAt(column)", -> it "breaks the line fragment into two fragments", -> [left, right] = screenLine.splitAt(31) diff --git a/spec/app/selection-spec.coffee b/spec/app/selection-spec.coffee index d21e466c1..0a91272ea 100644 --- a/spec/app/selection-spec.coffee +++ b/spec/app/selection-spec.coffee @@ -3,13 +3,16 @@ EditSession = require 'edit-session' Range = require 'range' describe "Selection", -> - [buffer, selection] = [] + [buffer, editSession, selection] = [] beforeEach -> buffer = new Buffer(require.resolve('fixtures/sample.js')) editSession = new EditSession(buffer: buffer, tabText: ' ') selection = editSession.getSelection() + afterEach -> + buffer.destroy() + describe ".deleteSelectedText()", -> describe "when nothing is selected", -> it "deletes nothing", -> diff --git a/spec/app/status-bar-spec.coffee b/spec/app/status-bar-spec.coffee index 21a42a1d9..e79134f5c 100644 --- a/spec/app/status-bar-spec.coffee +++ b/spec/app/status-bar-spec.coffee @@ -12,6 +12,9 @@ describe "StatusBar", -> editor = rootView.activeEditor() statusBar = rootView.find('.status-bar').view() + afterEach -> + rootView.remove() + describe "@initialize", -> it "appends a status bar to all existing and new editors", -> expect(rootView.panes.find('.pane').length).toBe 1 @@ -27,6 +30,7 @@ describe "StatusBar", -> describe "when associated with an unsaved buffer", -> it "displays 'untitled' instead of the buffer's path, but still displays the buffer position", -> + rootView.remove() rootView = new RootView rootView.open() rootView.simulateDomAttachment() diff --git a/spec/app/tokenized-buffer-spec.coffee b/spec/app/tokenized-buffer-spec.coffee index d96b81192..7fb803825 100644 --- a/spec/app/tokenized-buffer-spec.coffee +++ b/spec/app/tokenized-buffer-spec.coffee @@ -9,6 +9,9 @@ describe "TokenizedBuffer", -> buffer = new Buffer(require.resolve('fixtures/sample.js')) tokenizedBuffer = new TokenizedBuffer(buffer, ' ') + afterEach -> + buffer.destroy() + describe ".findClosingBracket(startBufferPosition)", -> it "returns the position of the matching bracket, skipping any nested brackets", -> expect(tokenizedBuffer.findClosingBracket([1, 29])).toEqual [9, 2] @@ -34,6 +37,7 @@ describe "TokenizedBuffer", -> describe "coffeescript", -> it "comments/uncomments lines in the given range", -> + buffer.destroy() buffer = new Buffer(require.resolve('fixtures/coffee.coffee')) tokenizedBuffer = new TokenizedBuffer(buffer, ' ') @@ -52,6 +56,7 @@ describe "TokenizedBuffer", -> describe "fold suggestion", -> describe "javascript", -> beforeEach -> + buffer.destroy() buffer = new Buffer(require.resolve 'fixtures/sample.js') tokenizedBuffer = new TokenizedBuffer(buffer) @@ -71,6 +76,7 @@ describe "TokenizedBuffer", -> describe "coffeescript", -> beforeEach -> + buffer.destroy() buffer = new Buffer(require.resolve 'fixtures/coffee.coffee') tokenizedBuffer = new TokenizedBuffer(buffer) @@ -223,6 +229,7 @@ describe "TokenizedBuffer", -> beforeEach -> tabText = ' ' + buffer.destroy() buffer = new Buffer(require.resolve('fixtures/sample-with-tabs.coffee')) tokenizedBuffer = new TokenizedBuffer(buffer, tabText) diff --git a/spec/app/undo-manager-spec.coffee b/spec/app/undo-manager-spec.coffee index c014c0032..d44902614 100644 --- a/spec/app/undo-manager-spec.coffee +++ b/spec/app/undo-manager-spec.coffee @@ -9,6 +9,9 @@ describe "UndoManager", -> buffer = new Buffer(require.resolve('fixtures/sample.js')) undoManager = new UndoManager(buffer) + afterEach -> + buffer.destroy() + describe ".undo()", -> it "undoes the last change", -> buffer.change(new Range([0, 5], [0, 9]), '') diff --git a/spec/extensions/autocomplete-spec.coffee b/spec/extensions/autocomplete-spec.coffee index 6b70d24a9..bc0d019f2 100644 --- a/spec/extensions/autocomplete-spec.coffee +++ b/spec/extensions/autocomplete-spec.coffee @@ -14,6 +14,9 @@ describe "Autocomplete", -> autocomplete = new Autocomplete(editor) miniEditor = autocomplete.miniEditor + afterEach -> + editor.remove() + describe "@activate(rootView)", -> it "activates autocomplete on all existing and future editors (but not on autocomplete's own mini editor)", -> rootView = new RootView(require.resolve('fixtures/sample.js')) @@ -35,6 +38,9 @@ describe "Autocomplete", -> expect(Autocomplete.prototype.initialize).not.toHaveBeenCalled() + leftEditor.remove() + rightEditor.remove() + describe 'autocomplete:attach event', -> it "shows autocomplete view and focuses its mini-editor", -> expect(editor.find('.autocomplete')).not.toExist() diff --git a/spec/extensions/command-interpreter-spec.coffee b/spec/extensions/command-interpreter-spec.coffee index cc9d4e731..57239d638 100644 --- a/spec/extensions/command-interpreter-spec.coffee +++ b/spec/extensions/command-interpreter-spec.coffee @@ -12,6 +12,9 @@ describe "CommandInterpreter", -> editor = new Editor(editSession: editSession) interpreter = new CommandInterpreter() + afterEach -> + editor.remove() + describe "addresses", -> beforeEach -> editor.addSelectionForBufferRange([[7,0], [7,11]]) diff --git a/spec/extensions/command-panel-spec.coffee b/spec/extensions/command-panel-spec.coffee index 3ff833ec1..a1f721f8c 100644 --- a/spec/extensions/command-panel-spec.coffee +++ b/spec/extensions/command-panel-spec.coffee @@ -11,6 +11,9 @@ describe "CommandPanel", -> editor = rootView.activeEditor() commandPanel = rootView.activateExtension(CommandPanel) + afterEach -> + rootView.remove() + describe "serialization", -> it "preserves the command panel's mini editor text and visibility across reloads", -> rootView.trigger 'command-panel:toggle' @@ -21,6 +24,8 @@ describe "CommandPanel", -> expect(newRootView.find('.command-panel')).toExist() expect(commandPanel.miniEditor.getText()).toBe 'abc' + newRootView.remove() + describe "when toggle-command-panel is triggered on the root view", -> it "toggles the command panel", -> rootView.attachToDom() diff --git a/spec/extensions/file-finder-spec.coffee b/spec/extensions/file-finder-spec.coffee deleted file mode 100644 index 85fadf259..000000000 --- a/spec/extensions/file-finder-spec.coffee +++ /dev/null @@ -1,177 +0,0 @@ -RootView = require 'root-view' -FileFinder = require 'file-finder' -$ = require 'jquery' -{$$} = require 'space-pen' - -describe 'FileFinder', -> - [rootView, finder] = [] - - beforeEach -> - rootView = new RootView(require.resolve('fixtures/sample.js')) - rootView.enableKeymap() - rootView.activateExtension(FileFinder) - finder = FileFinder.instance - - describe "when the file-finder:toggle event is triggered on the root view", -> - describe "when there is a project", -> - it "shows or hides the FileFinder, returning focus to the active editor when hiding it", -> - rootView.attachToDom() - expect(rootView.find('.file-finder')).not.toExist() - rootView.find('.editor').trigger 'split-right' - [editor1, editor2] = rootView.find('.editor').map -> $(this).view() - - rootView.trigger 'file-finder:toggle' - expect(rootView.find('.file-finder')).toExist() - expect(rootView.find('.file-finder input:focus')).toExist() - finder.miniEditor.insertText('this should not show up next time we toggle') - - rootView.trigger 'file-finder:toggle' - expect(editor1.isFocused).toBeFalsy() - expect(editor2.isFocused).toBeTruthy() - expect(rootView.find('.file-finder')).not.toExist() - - rootView.trigger 'file-finder:toggle' - expect(finder.miniEditor.getText()).toBe '' - - it "shows all relative file paths for the current project and selects the first", -> - finder.maxResults = 1000 - rootView.trigger 'file-finder:toggle' - rootView.project.getFilePaths().done (paths) -> - expect(finder.pathList.children('li').length).toBe paths.length, finder.maxResults - for path in paths - expect(finder.pathList.find("li:contains(#{path})")).toExist() - expect(finder.pathList.children().first()).toHaveClass 'selected' - - describe "when root view's project has no path", -> - beforeEach -> - rootView.project.setPath(null) - - it "does not open the FileFinder", -> - expect(rootView.find('.file-finder')).not.toExist() - rootView.trigger 'file-finder:toggle' - expect(rootView.find('.file-finder')).not.toExist() - - describe "file-finder:cancel event", -> - it "hides the finder", -> - rootView.trigger 'file-finder:toggle' - expect(finder.hasParent()).toBeTruthy() - - finder.trigger 'file-finder:cancel' - expect(finder.hasParent()).toBeFalsy() - - it "focuses previously focused element", -> - rootView.attachToDom() - activeEditor = rootView.activeEditor() - activeEditor.focus() - - rootView.trigger 'file-finder:toggle' - expect(activeEditor.isFocused).toBeFalsy() - expect(finder.miniEditor.isFocused).toBeTruthy() - - finder.trigger 'file-finder:cancel' - expect(activeEditor.isFocused).toBeTruthy() - expect(finder.miniEditor.isFocused).toBeFalsy() - - describe "when the file finder loses focus", -> - it "detaches itself", -> - rootView.attachToDom() - rootView.trigger 'file-finder:toggle' - - expect(finder.hasParent()).toBeTruthy() - rootView.focus() - expect(finder.hasParent()).toBeFalsy() - - describe "when characters are typed into the input element", -> - it "displays matching paths in the ol element and selects the first", -> - rootView.trigger 'file-finder:toggle' - - listLengthBefore = finder.pathList.children().length - - finder.miniEditor.insertText('samp') - - expect(finder.pathList.children().length).toBeLessThan(listLengthBefore) - expect(finder.pathList.find('li:first')).toHaveClass 'selected' - expect(finder.pathList.find('li.selected').length).toBe 1 - - # we should clear the list before re-populating it - finder.miniEditor.insertText('txt') - - expect(finder.pathList.children().length).toBe 1 - expect(finder.pathList.find('li:first')).toHaveClass 'selected' - expect(finder.pathList.find('li:first')).toHaveText 'sample.txt' - - describe "move-down / move-up events", -> - beforeEach -> - rootView.trigger 'file-finder:toggle' - - it "selects the next / previous path in the list", -> - expect(finder.find('li:eq(0)')).toHaveClass "selected" - expect(finder.find('li:eq(2)')).not.toHaveClass "selected" - - finder.miniEditor.trigger keydownEvent('down') - finder.miniEditor.trigger keydownEvent('down') - - expect(finder.find('li:eq(0)')).not.toHaveClass "selected" - expect(finder.find('li:eq(2)')).toHaveClass "selected" - - finder.miniEditor.trigger keydownEvent('up') - - expect(finder.find('li:eq(0)')).not.toHaveClass "selected" - expect(finder.find('li:eq(1)')).toHaveClass "selected" - expect(finder.find('li:eq(2)')).not.toHaveClass "selected" - - it "does not fall off the end or begining of the list", -> - expect(finder.find('li:first')).toHaveClass "selected" - finder.miniEditor.trigger keydownEvent('up') - expect(finder.find('li:first')).toHaveClass "selected" - - for i in [1..finder.pathList.children().length+2] - finder.miniEditor.trigger keydownEvent('down') - - expect(finder.find('li:last')).toHaveClass "selected" - - describe "select-file events", -> - [editor1, editor2] = [] - - beforeEach -> - rootView.attachToDom() - editor1 = rootView.activeEditor() - editor2 = editor1.splitRight() - expect(rootView.activeEditor()).toBe editor2 - rootView.trigger 'file-finder:toggle' - - describe "when there is a path selected", -> - it "opens the file associated with that path in the editor", -> - finder.trigger 'move-down' - selectedLi = finder.find('li:eq(1)') - - expectedPath = rootView.project.resolve(selectedLi.text()) - expect(editor1.buffer.getPath()).not.toBe expectedPath - expect(editor2.buffer.getPath()).not.toBe expectedPath - - finder.trigger 'file-finder:select-file' - - expect(finder.hasParent()).toBeFalsy() - expect(editor1.buffer.getPath()).not.toBe expectedPath - expect(editor2.buffer.getPath()).toBe expectedPath - expect(editor2.isFocused).toBeTruthy() - - describe "when there is no path selected", -> - it "does nothing", -> - finder.miniEditor.insertText('this should match nothing, because no one wants to drink battery acid') - finder.trigger 'file-finder:select-file' - expect(finder.hasParent()).toBeTruthy() - - describe ".findMatches(queryString)", -> - beforeEach -> - rootView.trigger 'file-finder:toggle' - - it "returns up to finder.maxResults paths if queryString is empty", -> - expect(finder.findMatches('').length).toBeLessThan finder.maxResults + 1 - finder.maxResults = 5 - expect(finder.findMatches('').length).toBeLessThan finder.maxResults + 1 - - it "returns paths sorted by score of match against the given query", -> - finder.paths = ["app.coffee", "atom/app.coffee"] - expect(finder.findMatches('app.co')).toEqual ["app.coffee", "atom/app.coffee"] - expect(finder.findMatches('atom/app.co')).toEqual ["atom/app.coffee"] diff --git a/spec/extensions/fuzzy-finder-spec.coffee b/spec/extensions/fuzzy-finder-spec.coffee index 3343e7afe..603818898 100644 --- a/spec/extensions/fuzzy-finder-spec.coffee +++ b/spec/extensions/fuzzy-finder-spec.coffee @@ -12,6 +12,9 @@ describe 'FuzzyFinder', -> rootView.activateExtension(FuzzyFinder) finder = FuzzyFinder.instance + afterEach -> + rootView.remove() + describe "file-finder behavior", -> describe "toggling", -> describe "when the root view's project has a path", -> @@ -68,14 +71,14 @@ describe 'FuzzyFinder', -> selectedLi = finder.find('li:eq(1)') expectedPath = rootView.project.resolve(selectedLi.text()) - expect(editor1.buffer.path).not.toBe expectedPath - expect(editor2.buffer.path).not.toBe expectedPath + expect(editor1.buffer.getPath()).not.toBe expectedPath + expect(editor2.buffer.getPath()).not.toBe expectedPath finder.trigger 'fuzzy-finder:select-path' expect(finder.hasParent()).toBeFalsy() - expect(editor1.buffer.path).not.toBe expectedPath - expect(editor2.buffer.path).toBe expectedPath + expect(editor1.buffer.getPath()).not.toBe expectedPath + expect(editor2.buffer.getPath()).toBe expectedPath expect(editor2.isFocused).toBeTruthy() describe "when no paths are highlighted", -> @@ -156,8 +159,8 @@ describe 'FuzzyFinder', -> finder.trigger 'fuzzy-finder:select-path' expect(finder.hasParent()).toBeFalsy() - expect(editor1.buffer.path).not.toBe expectedPath - expect(editor2.buffer.path).toBe expectedPath + expect(editor1.buffer.getPath()).not.toBe expectedPath + expect(editor2.buffer.getPath()).toBe expectedPath expect(editor2.isFocused).toBeTruthy() describe "when the highlighted path is not open in the active editor, but instead is open on another editor", -> @@ -176,8 +179,8 @@ describe 'FuzzyFinder', -> finder.trigger 'fuzzy-finder:select-path' expect(finder.hasParent()).toBeFalsy() - expect(editor1.buffer.path).not.toBe expectedPath - expect(editor2.buffer.path).toBe expectedPath + expect(editor1.buffer.getPath()).not.toBe expectedPath + expect(editor2.buffer.getPath()).toBe expectedPath expect(editor2.isFocused).toBeTruthy() describe "common behavior between file and buffer finder", -> @@ -268,12 +271,12 @@ describe 'FuzzyFinder', -> selectedLi = finder.find('li:eq(1)') expectedPath = rootView.project.resolve(selectedLi.text()) - expect(rootView.activeEditor().buffer.path).not.toBe expectedPath + expect(rootView.activeEditor().buffer.getPath()).not.toBe expectedPath expect(rootView.activeEditor().isFocused).toBeFalsy() selectedLi.mousedown() - expect(rootView.activeEditor().buffer.path).toBe expectedPath + expect(rootView.activeEditor().buffer.getPath()).toBe expectedPath expect(rootView.activeEditor().isFocused).toBeTruthy() describe ".findMatches(queryString)", -> diff --git a/spec/extensions/snippets-spec.coffee b/spec/extensions/snippets-spec.coffee index 1a65f3856..84e35cbb4 100644 --- a/spec/extensions/snippets-spec.coffee +++ b/spec/extensions/snippets-spec.coffee @@ -15,6 +15,9 @@ describe "Snippets extension", -> rootView.simulateDomAttachment() rootView.enableKeymap() + afterEach -> + rootView.remove() + describe "when 'tab' is triggered on the editor", -> beforeEach -> Snippets.evalSnippets 'js', """ diff --git a/spec/extensions/tree-view-spec.coffee b/spec/extensions/tree-view-spec.coffee index 9e9172f70..bc961b5df 100644 --- a/spec/extensions/tree-view-spec.coffee +++ b/spec/extensions/tree-view-spec.coffee @@ -23,6 +23,7 @@ describe "TreeView", -> afterEach -> treeView.deactivate() + rootView.remove() describe ".initialize(project)", -> it "renders the root of the project and its contents alphabetically with subdirectories first in a collapsed state", -> @@ -85,9 +86,10 @@ describe "TreeView", -> expect(newTreeView).toExist() expect(newTreeView.selectedEntry()).toMatchSelector(".file:contains(sample.js)") expect(newTreeView.find(".directory:contains(zed)")).toHaveClass("expanded") + newRootView.remove() it "restores the focus state of the tree view", -> - treeView.attachToDom() + rootView.attachToDom() treeView.focus() expect(treeView).toMatchSelector ':focus' @@ -98,6 +100,7 @@ describe "TreeView", -> newTreeView = newRootView.find(".tree-view").view() expect(newTreeView).toMatchSelector ':focus' + newRootView.remove() describe "when tree-view:toggle is triggered on the root view", -> it "shows/hides the tree view", -> diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 8db30686b..fdef0f987 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -5,25 +5,27 @@ Keymap = require 'keymap' Point = require 'point' Project = require 'project' Directory = require 'directory' +File = require 'file' RootView = require 'root-view' +fs = require 'fs' require 'window' $native.showDevTools() requireStylesheet "jasmine.css" defaultTitle = document.title -directoriesWithSubscriptions = null +pathsWithSubscriptions = null beforeEach -> window.fixturesProject = new Project(require.resolve('fixtures')) window.resetTimeouts() - directoriesWithSubscriptions = [] + pathsWithSubscriptions = [] afterEach -> delete window.rootView if window.rootView $('#jasmine-content').empty() document.title = defaultTitle - ensureNoDirectorySubscriptions() + ensureNoPathSubscriptions() window.keymap.bindKeys '*', 'meta-w': 'close' $(document).on 'close', -> window.close() @@ -31,19 +33,20 @@ $(document).on 'close', -> window.close() # Don't load user configuration in specs, because it's variable RootView.prototype.loadUserConfiguration = -> -Directory.prototype.originalOn = Directory.prototype.on -Directory.prototype.on = (args...) -> - directoriesWithSubscriptions.push(this) if @subscriptionCount() == 0 - @originalOn(args...) +for klass in [Directory, File] + klass.prototype.originalOn = klass.prototype.on + klass.prototype.on = (args...) -> + pathsWithSubscriptions.push(this) if @subscriptionCount() == 0 + @originalOn(args...) -ensureNoDirectorySubscriptions = -> +ensureNoPathSubscriptions = -> totalSubscriptionCount = 0 - for directory in directoriesWithSubscriptions - totalSubscriptionCount += directory.subscriptionCount() - console.log "Non-zero subscription count on", directory if directory.subscriptionCount() > 0 + for path in pathsWithSubscriptions + totalSubscriptionCount += path.subscriptionCount() + console.log "Non-zero subscription count on", path if path.subscriptionCount() > 0 if totalSubscriptionCount > 0 - throw new Error("Total directory subscription count was #{totalSubscriptionCount}, when it should have been 0.\nSee console for details.") + throw new Error("Total path subscription count was #{totalSubscriptionCount}, when it should have been 0.\nSee console for details.") # Use underscore's definition of equality for toEqual assertions jasmine.Env.prototype.equals_ = _.isEqual diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 7353d99da..1bd818d56 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -398,7 +398,7 @@ class Editor extends View false getOpenBufferPaths: -> - editSession.buffer.path for editSession in @editSessions when editSession.buffer.path? + editSession.buffer.getPath() for editSession in @editSessions when editSession.buffer.getPath()? scrollTop: (scrollTop, options) -> return @cachedScrollTop or 0 unless scrollTop? diff --git a/src/app/project.coffee b/src/app/project.coffee index 6b7e92d41..11a05c820 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -90,10 +90,15 @@ class Project softTabs: @getSoftTabs() softWrap: @getSoftWrap() + @editSessions.push editSession @trigger 'new-edit-session', editSession editSession + destroy: -> + for editSession in _.clone(@editSessions) + @removeEditSession(editSession) + removeEditSession: (editSession) -> _.remove(@editSessions, editSession) @destroyBufferIfOrphaned(editSession.buffer) diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 4ff3b6566..184fcdefe 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -183,6 +183,7 @@ class RootView extends View remove: -> editor.remove() for editor in @editors() + @project.destroy() super setFontSize: (newFontSize) ->