Rails 3.1 和 Rails 3.1 Jasmine:包含来自 gems 的 JavaScript

发布于 2024-12-25 07:59:27 字数 881 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾听心声的旋律 2025-01-01 07:59:27

我强烈建议使用 jasmine-headless-webkit 来做Rails 3.1 应用程序中的 jasmine 测试。这是我的 jasmine.yml 文件:

src_dir: app/assets/javascripts
asset_paths:
- app/assets/templates
- lib/assets/javascripts
- vendor/assets/javascripts

src_files:
- [ 'application.js' ]

spec_dir: spec/javascripts

spec_files:
- "**/*[Ss]pec.*"

helpers:
- "helpers/**/*"

我将其与 jasmine-headless-webkit 一起使用,在命令行上运行我的测试(使用 watchr 在文件更改时自动运行它们)

这是一种很棒的测试方法。

I highly recommend using jasmine-headless-webkit to do jasmine testing in rails 3.1 apps. Here's my jasmine.yml file:

src_dir: app/assets/javascripts
asset_paths:
- app/assets/templates
- lib/assets/javascripts
- vendor/assets/javascripts

src_files:
- [ 'application.js' ]

spec_dir: spec/javascripts

spec_files:
- "**/*[Ss]pec.*"

helpers:
- "helpers/**/*"

I'm using that with jasmine-headless-webkit to run my tests on the command-line (using watchr to run them automatically when a file is changed)

It's a wonderful way to test.

Spring初心 2025-01-01 07:59:27

最近对 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文