使用rake jasmine,我的所有测试都会在浏览器中传递。
使用rake jasmine,2个规格失败:
TypeError: undefined is not a function (evaluating 'expect(player).not.toBePlaying(song)') in http://localhost:36091/__spec__/PlayerSpec.js (line 28)
我已将spec/javascripts/support/jasmine.yml
文件配置为
src_files:
- src/Player.js
- src/Song.js
spec_files:
- '**/*[sS]pec.js'
src_dir:
spec_dir: spec
src/Song.js
有:
function Song() {
...
为什么rake jasmine:ci
失败了这两个例子?
第一个失败的代码是:
it("should be able to play a Song", function() {
player.play(song);
expect(player.currentlyPlayingSong).toEqual(song);
//demonstrates use of custom matcher
expect(player).toBePlaying(song); # <-- error here
});
似乎已加载 Song.js
,因为如果删除它,则所有5个示例都会失败。
答案 0 :(得分:0)
我需要自定义匹配器toBePlaying
我能够通过在spec/javascripts/support/jasmine.yml
文件中更改此内容来获取所有规范:
src_files:
- src/Player.js
- src/Song.js
- spec/SpecHelper.js # <--- Added to include the custom helper 'toBePlaying'
我曾尝试将其添加到spec_files
部分,但需要列在src_files