Jasmine无法从资产管道加载JavaScript文件

8

我正在开发一个gem,已经安装了Jasmine https://github.com/pivotal/jasmine-gem/

我的所有必需的JS文件都在我的清单文件中,路径为app/assets/javascripts/application.js

//= require underscore
//= require backbone

//= require_tree .//vendor
//= require_tree .//custom

//= require_tree .//templates
//= require_tree .//models
//= require_tree .//collections
//= require_tree .//views

我的 jasmine.yml 文件引用了它:

src_files:
  - 'app/assets/javascripts/application.js'

但是,其中任何一个指定的文件都没有加载。有人知道为什么吗?我正在使用最新版本的Jasmine 1.3.2,它应该支持资源管道,因此您不需要使用类似于jasmine-rails的东西。有什么想法吗?

2个回答

7
在你的jasmine.yml中,路径应该是'assets/application.js'。如果你仍然有问题,请确保在Gemfile中将jasmine gem分别放在开发和测试组中,就像在https://github.com/pivotal/jasmine-gem的说明中指定的那样。
group :development, :test do
  gem 'jasmine'
end

我确实按照这样做了,但是资产仍未加载。 我的application.js 中有“//= require underscore”,在jasmine.yml中有“src_files:-assets/application.js”,但当我调用underscore.js中的函数时,被告知它未定义。问题只有在我在jasmine.yml的'src_files'下有“-assets/underscore.js”时才会消失。非常令人沮丧。 - Tony Jiang
原来资产没有被编译。我通过在Gemfile中取消注释therubyracer行来解决了这个问题。但在另一个应用程序中 - 其中Ruby版本为1.9.3p194 - 我不需要这样做(在当前应用程序中,Ruby版本为2.0.0p247)。仍然有点难以理解。 - Tony Jiang

1
如果您使用的是Rails 4,那么在1.3.2版本中存在一个错误,它检查的config.assets.enabled已不再在Rails 4中定义。
以下内容对我有用。 gem'jasmine',"〜> 2.0.0.rc4" 这是有关该问题的票。https://github.com/pivotal/jasmine-gem/pull/177

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接