Rails 3.1 和 Rails 3.1 Jasmine:包含来自 gems 的 JavaScript
我有一个 Rails 3.1 项目,我想在其上运行一些 jasmine 规范。问题是,我的 Rails 项目需要一些来自 gems(尤其是backbone-rails)的 javascript 文件,而不是我的 /assets 目录。
查看生成的 jasmine 文件的 HTML,它成功包含了 JavaScripts /assets 目录中的所有资源(从 Coffeescript 编译),但没有由 gems 生成的 javascript 文件。因此,我收到了一堆“找不到类”错误。
那么,有什么想法可以让 jasmine 需要来自 gems 的 Rails 3.1 JavaScript 文件,而不仅仅是 /assets 吗?当前的 jasmine.yml 包含在下面。任何想法表示赞赏
src_files:
- public/javascripts/prototype.js
- public/javascripts/effects.js
- public/javascripts/controls.js
- public/javascripts/dragdrop.js
- public/javascripts/application.js
- public/javascripts/**/*.js
- spec/**/*_spec.js
- "vendor/**/*.{js, coffee}"
- "lib/**/*.{js, coffee}"
- "app/**/*.{js, coffee}"
stylesheets:
- stylesheets/**/*.css
helpers:
- helpers/**/*.js
spec_files:
- '**/*[sS]pec.{js, coffee}'
src_dir: assets
spec_dir: spec/javascripts
I have a rails 3.1 project that I'd like to run some jasmine specs on. Problem is, my rails project requires some javascript files that are sourced from gems (most particularly backbone-rails), not my /assets directory.
Looking at the generated jasmine file's HTML, it's successfully including all assets from the JavaScripts /assets directory (compiled from coffeescript), but no javascript files generated by gems. Consequently I'm getting a bunch of 'class not found' errors.
So, any ideas on getting jasmine to require Rails 3.1 JavaScript files from gems, not just /assets? Current jasmine.yml included below. Any ideas appreciated
src_files:
- public/javascripts/prototype.js
- public/javascripts/effects.js
- public/javascripts/controls.js
- public/javascripts/dragdrop.js
- public/javascripts/application.js
- public/javascripts/**/*.js
- spec/**/*_spec.js
- "vendor/**/*.{js, coffee}"
- "lib/**/*.{js, coffee}"
- "app/**/*.{js, coffee}"
stylesheets:
- stylesheets/**/*.css
helpers:
- helpers/**/*.js
spec_files:
- '**/*[sS]pec.{js, coffee}'
src_dir: assets
spec_dir: spec/javascripts
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我强烈建议使用
jasmine-headless-webkit
来做Rails 3.1 应用程序中的 jasmine 测试。这是我的 jasmine.yml 文件:我将其与 jasmine-headless-webkit 一起使用,在命令行上运行我的测试(使用
watchr
在文件更改时自动运行它们)这是一种很棒的测试方法。
I highly recommend using
jasmine-headless-webkit
to do jasmine testing in rails 3.1 apps. Here's myjasmine.yml
file:I'm using that with
jasmine-headless-webkit
to run my tests on the command-line (usingwatchr
to run them automatically when a file is changed)It's a wonderful way to test.
最近对 jasmine master 的承诺使其能够从资产管道中获取 javascript。效果很好。
https://github.com/pivotal/jasmine-gem/commits/master
Fairly recent commits to jasmine master enable it to source javascripts from the asset pipeline. It works great.
https://github.com/pivotal/jasmine-gem/commits/master