Eliminate warning messages from snippets-spec

Mock loading of TextMate snippets or Atom snippets and only enable
loading for the type of snippet being currently tested. This limits
logging of warning to the single warning we expect for each type, which
allows us to not call through on the mocking of `console.warn` and
explicitly check for the single expected call.
This commit is contained in:
Nathan Sobo
2013-01-27 13:25:59 -07:00
parent 0be4ad547a
commit c27de89327
3 changed files with 20 additions and 10 deletions

View File

@@ -212,9 +212,14 @@ describe "Snippets extension", ->
expect(editor.getSelectedBufferRange()).toEqual [[1, 6], [1, 36]]
describe "snippet loading", ->
it "loads non-hidden snippet files from all atom packages with snippets directories, logging a warning if a file can't be parsed", ->
spyOn(console, 'warn').andCallThrough()
beforeEach ->
jasmine.unspy(LoadSnippetsTask.prototype, 'start')
spyOn(LoadSnippetsTask.prototype, 'loadAtomSnippets').andCallFake -> @snippetsLoaded({})
spyOn(LoadSnippetsTask.prototype, 'loadTextMateSnippets').andCallFake -> @snippetsLoaded({})
it "loads non-hidden snippet files from all atom packages with snippets directories, logging a warning if a file can't be parsed", ->
jasmine.unspy(LoadSnippetsTask.prototype, 'loadAtomSnippets')
spyOn(console, 'warn')
snippets.loaded = false
snippets.loadAll()
@@ -225,11 +230,11 @@ describe "Snippets extension", ->
# warn about junk-file, but don't even try to parse a hidden file
expect(console.warn).toHaveBeenCalled()
expect(console.warn.calls.length).toBeGreaterThan 0
expect(console.warn.calls.length).toBe 1
it "loads snippets from all TextMate packages with snippets", ->
spyOn(console, 'warn').andCallThrough()
jasmine.unspy(LoadSnippetsTask.prototype, 'start')
jasmine.unspy(LoadSnippetsTask.prototype, 'loadTextMateSnippets')
spyOn(console, 'warn')
snippets.loaded = false
snippets.loadAll()
@@ -248,7 +253,7 @@ describe "Snippets extension", ->
# warn about junk-file, but don't even try to parse a hidden file
expect(console.warn).toHaveBeenCalled()
expect(console.warn.calls.length).toBeGreaterThan 0
expect(console.warn.calls.length).toBe 1
describe "Snippet body parser", ->
it "breaks a snippet body into lines, with each line containing tab stops at the appropriate position", ->

View File

@@ -10,7 +10,7 @@ module.exports =
attributes.bodyTree = SnippetBodyParser.parse(attributes.body)
callTaskMethod('snippetsLoaded', snippets)
loadTextmateSnippets: (path) ->
loadTextMateSnippets: (path) ->
snippetsDirPath = fs.join(path, 'Snippets')
snippets = []

View File

@@ -18,10 +18,15 @@ class LoadSnippetsTask extends Task
@packageBeingLoaded = @packages.shift()
if @packageBeingLoaded instanceof TextMatePackage
method = 'loadTextmateSnippets'
@loadTextMateSnippets(@packageBeingLoaded.path)
else
method = 'loadAtomSnippets'
@callWorkerMethod(method, @packageBeingLoaded.path)
@loadAtomSnippets(@packageBeingLoaded.path)
loadAtomSnippets: (path) ->
@callWorkerMethod('loadAtomSnippets', path)
loadTextMateSnippets: (path) ->
@callWorkerMethod('loadTextMateSnippets', path)
snippetsLoaded: (snippets) ->
@snippets.add(snippet) for snippet in snippets