从我之前的问题here开始,我正在尝试获取Atom注册的'spec'文件,我已经成功了,但现在,无论describe
和{{ 1}}我这样做,当我测试它时它没有做任何事情。
我使用命令it
,我得到的是:
apm test
根据spec文件判断(肯定正在注册,因为它不存在时会抱怨),我应该运行3次测试。
我的spec文件如下......(语法荧光笔包)
[655:0527/083825:WARNING:resource_bundle.cc(305)] locale_file_path.empty() for locale English
[655:0527/083825:ERROR:file_io.cc(30)] read: expected 40, observed 0
[659:0527/083825:WARNING:resource_bundle.cc(305)] locale_file_path.empty() for locale English
[655:0527/083828:INFO:CONSOLE(52)] "Window load time: 2420ms", source: file:///Applications/Atom.app/Contents/Resources/app.asar/static/index.js (52)
Finished in 0.023 seconds
0 tests, 0 assertions, 0 failures, 0 skipped
Tests passed
我的文件结构如下:
describe "Jazz grammar", ->
grammar = null
beforeEach ->
waitsForPromise ->
atom.packages.activatePackage("language-jazz")
runs ->
grammar = atom.grammars.grammarForScopeName("source.jazz")
it "parses the grammar", ->
expect(grammar).toBeDefined()
expect(grammar.scopeName).toBe "source.jazz"
it "tokenises keywords", ->
tokens = grammar.tokenizeLines('func')
expect(tokens[0][0].value).toBe 'func'
expect(tokens[0][0].scopes).toEqual ['source.jazz', 'storage.type.jazz']
it "tokenizes comments inside function parameters", ->
tokens = grammar.tokenizeLines('module test(arg1, ;; arg2)')
expect(tokens[0][0].value).toBe 'module'
expect(tokens[0][0].scopes).toEqual ['source.jazz', 'storage.type.jazz']
expect(tokens[0][1].scopes).toEqual ['source.jazz', 'comment.line.jazz']
jazz.cson
language-jazz.cson
jazz-spec.coffee
答案 0 :(得分:2)
问题在于您的规范中的测试的缩进和结构,请记住,在CoffeeScript中,空格很重要,而run
块用于封装代码块而不是组it
语句。
所以规范应该是:
describe "Jazz grammar", ->
grammar = null
beforeEach ->
waitsForPromise ->
atom.packages.activatePackage("language-jazz")
grammar = atom.grammars.grammarForScopeName("source.jazz")
it "parses the grammar", ->
expect(grammar).toBeDefined()
expect(grammar.scopeName).toBe "source.jazz"
it "tokenises keywords", ->
tokens = grammar.tokenizeLines('func')
expect(tokens[0][0].value).toBe 'func'
expect(tokens[0][0].scopes).toEqual ['source.jazz', 'storage.type.jazz']
it "tokenizes comments inside function parameters", ->
tokens = grammar.tokenizeLines('module test(arg1, ;; arg2)')
expect(tokens[0][0].value).toBe 'module'
expect(tokens[0][0].scopes).toEqual ['source.jazz', 'storage.type.jazz']
expect(tokens[0][1].scopes).toEqual ['source.jazz', 'comment.line.jazz']
我已经在本地进行了测试,并且它显示为三个失败的测试,因为我已经实现了你的语法。