【发布时间】:2013-02-16 04:50:30
【问题描述】:
我试图通过提取共享示例来干掉一些茉莉花测试。
@sharedExamplesForThing = (thing) ->
beforeEach ->
@thingy = new thing
it "is neat", ->
expect(@thingy.neat).toBeTruthy()
describe "widget with shared behavior", ->
sharedExamplesForThing(-> new Widget)
当所有内容都定义在一个文件中时,这很有效。当我尝试将 sharedExamples 移动到单独的文件时,会出现我遇到的问题。我得到Can't find variable: sharedExamplesForThing ...
所以为了调试,我尝试了以下方法:
describe "widget with shared behavior", ->
it "is acting like a meany", ->
console.log sharedExamplesForThing
expect(false).toBeTruthy()
sharedExamplesForThing(-> new Widget)
在is acting like a meany 块中,日志将sharedExamplesForThing 显示为[Function],但我仍然在it 之外得到Can't find variable。我觉得这可能与我当前经验之外的范围界定问题有关,但我可能完全错了。我在这里错过了什么?
(使用 rails、jasminerice、guard-jasmine)
【问题讨论】:
标签: javascript coffeescript tdd jasmine