diff --git a/spec/atom/app-spec.coffee b/spec/atom/app-spec.coffee index 163b10416..44a8c4ba6 100644 --- a/spec/atom/app-spec.coffee +++ b/spec/atom/app-spec.coffee @@ -11,14 +11,28 @@ describe "App", -> window.close() for window in app.windows() describe "open", -> - it "loads a buffer based on the given path and displays it in a new window", -> - filePath = require.resolve 'fixtures/sample.txt' - expect(app.windows().length).toBe 0 + describe "when opening a filePath", -> + it "loads a buffer with filePath contents and displays it in a new window", -> + filePath = require.resolve 'fixtures/sample.txt' + expect(app.windows().length).toBe 0 - app.open filePath + app.open filePath - expect(app.windows().length).toBe 1 - newWindow = app.windows()[0] + expect(app.windows().length).toBe 1 + newWindow = app.windows()[0] - expect(newWindow.rootView.editor.buffer.url).toEqual filePath - expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath) + expect(newWindow.rootView.editor.buffer.url).toEqual filePath + expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath) + + describe "when opening a dirPath", -> + it "loads an empty buffer", -> + dirPath = require.resolve 'fixtures' + expect(app.windows().length).toBe 0 + + app.open dirPath + + expect(app.windows().length).toBe 1 + newWindow = app.windows()[0] + + expect(newWindow.rootView.editor.buffer.url).toBeUndefined + expect(newWindow.rootView.editor.buffer.getText()).toBe "" diff --git a/spec/atom/root-view-spec.coffee b/spec/atom/root-view-spec.coffee index 12cfa39d1..706865e7e 100644 --- a/spec/atom/root-view-spec.coffee +++ b/spec/atom/root-view-spec.coffee @@ -11,11 +11,18 @@ describe "RootView", -> rootView = RootView.build {url} describe "initialize", -> - describe "when called with a url", -> - describe "when the url references a file", -> - it "creates a project for the file's parent directory and opens it in the editor", -> - expect(rootView.project.url).toBe fs.directory(url) - expect(rootView.editor.buffer.url).toBe url + describe "when called with a url that references a file", -> + it "creates a project for the file's parent directory and opens it in the editor", -> + expect(rootView.project.url).toBe fs.directory(url) + expect(rootView.editor.buffer.url).toBe url + + describe "when called with a url that references a directory", -> + it "creates a project for the directory and opens and empty buffer", -> + url = require.resolve 'fixtures/dir' + rootView = RootView.build {url} + + expect(rootView.project.url).toBe url + expect(rootView.editor.buffer.url).toBeUndefined() describe "when not called with a url", -> it "opens an empty buffer", -> diff --git a/src/atom/root-view.coffee b/src/atom/root-view.coffee index 04c126da1..1c20dc7cc 100644 --- a/src/atom/root-view.coffee +++ b/src/atom/root-view.coffee @@ -21,8 +21,14 @@ class RootView extends Template @bindKey 'meta+w', => window.close() @bindKey 'meta+t', => @toggleFileFinder() - @project = new Project(fs.directory(url)) if url - @editor.open url + if not url + # not sure what to do + else if fs.isDirectory url + @project = new Project url + @editor.open() + else + @project = new Project(fs.directory(url)) + @editor.open url addPane: (view) -> pane = $('
')