From 10d9111f681d668dabe85a5c54f877ad0236c29a Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Tue, 2 Jun 2015 19:11:08 -0400 Subject: [PATCH] Clean up test to verify that an individual failed search fails the overall search. --- spec/workspace-spec.coffee | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/spec/workspace-spec.coffee b/spec/workspace-spec.coffee index b1e7b033c..524adde5f 100644 --- a/spec/workspace-spec.coffee +++ b/spec/workspace-spec.coffee @@ -985,31 +985,27 @@ describe "Workspace", -> expect(onPathsSearched.mostRecentCall.args[0]).toBe( numPathsToPretendToSearchInCustomDirectorySearcher + numPathsSearchedInDir2) - it "can be cancelled by cancelling one of the DirectorySearchers", -> - customDirectorySearcherPromiseInstance = null - class CustomDirectorySearchToCancel + it "will have the side-effect of failing the overall search if it fails", -> + # Note that hoisting reject in this way is generally frowned upon. + hoistedReject = null + class CustomDirectorySearchThatWillFail constructor: -> - # Note that hoisting reject in this way is generally frowned upon. - @promise = new Promise (resolve, reject) => - @hoistedReject = reject - customDirectorySearcherPromiseInstance = this + @promise = new Promise (resolve, reject) -> + hoistedReject = reject then: (args...) -> @promise.then.apply(@promise, args) cancel: -> - @hoistedReject() class CustomDirectorySearcherToCancel canSearchDirectory: (directory) -> directory.getPath() is dir1 search: (directory, options) -> - new CustomDirectorySearchToCancel + new CustomDirectorySearchThatWillFail atom.packages.serviceHub.provide( "atom.directory-searcher", "0.1.0", new CustomDirectorySearcherToCancel()) - resultPaths = [] - cancelableSearch = atom.workspace.scan /aaaa/, ({filePath}) -> - resultPaths.push(filePath) - customDirectorySearcherPromiseInstance.cancel() + cancelableSearch = atom.workspace.scan /aaaa/, -> + hoistedReject() resultOfPromiseSearch = null waitsForPromise ->