I have a rails app that is combining javascript assets using Jammit, and I'd like to use Jasmine for BDD-style testing of my javascript. I'm wondering if anyone has any advice on accessing the Jammit-generated 'pacakges' from within Jasmine?
我有一个使用Jammit组合javascript资源的rails应用程序,我想使用Jasmine进行我的javascript的BDD风格测试。我想知道是否有人有任何建议从Jasmine内部访问Jammit生成的'pacakges'?
The issue is that Jasmine is configured by defining a list of JS files on disk to test, and it then includes those files within its own test runner page which is loaded and run in a browser.
问题是Jasmine是通过在磁盘上定义要测试的JS文件列表来配置的,然后它将这些文件包含在自己的测试运行器页面中,该页面在浏览器中加载和运行。
I could reference each of the individual JS files inside of the jasmine.yml config file before they're packaged with Jammit... however, Jammit is already dealing with dependencies between files for me, and, more importantly, I also need access to the compiled javascript templates that Jammit produces.
我可以在jasmine.yml配置文件中使用Jammit打包之前引用每个JS文件...但是,Jammit已经在为我处理文件之间的依赖关系了,更重要的是,我还需要访问Jammit生成的已编译的javascript模板。
I could also manually run Jammit to generate the compiled assets first and then run Jasmine, but I'd wind up having to re-generate the assets by hand before each test run in order to test changes, which would seriously cramp a fast test-driven type workflow.
我也可以先手动运行Jammit来生成编译后的资产,然后再运行Jasmine,但我不得不在每次测试运行之前手动重新生成资产以测试更改,这会严重阻碍快速测试 - 驱动型工作流程。
I'm wondering if I could somehow:
我想知道我能否以某种方式:
- Mount the Jammit controller from within Jasmine's rack server so it could serve out the packages from Jasmine? This would basically work the same way as Jammit already does from within Rails' development env.
- Hook into Jasmine somehow to package the assets on every page load before the tests are executed? This would be slower, but would save me a step and ensure things were up to date.
从Jasmine的机架服务器中安装Jammit控制器,以便它可以提供Jasmine的软件包?这基本上和Jammit在Rails的开发环境中已经完成的工作方式相同。
在执行测试之前,以某种方式挂钩到Jasmine以在每个页面加载上打包资产?这会比较慢,但会省去一步并确保事情是最新的。
Any suggestions? I'm just getting started with this, so I could be going about it all wrong. Any advice would be greatly appreciated. :-)
有什么建议?我刚刚开始这样做,所以我可能会把它弄错。任何建议将不胜感激。 :-)
Thanks! -John
2 个解决方案
#1
10
Here's the magic combo you're looking for:
这是您正在寻找的神奇组合:
- Use the guard gem along with the guard-jammit gem to watch for changes to your project's assets
- Install the LiveReload plugin in the browser of your choice and install the guard-livereload gem so you can have your browser auto reload whenever your specs or assets change.
- Fire up guard, then rake jasmine, then load your jasmine specs in your browser, then press the live-reload button to connect to the live-reload server that guard started
- Change your files. Watch the magic happen as guard runs jammit and instructs your browser to refresh the jasmine specs.
使用guard gem和guard-jammit gem来监视项目资产的变化
在您选择的浏览器中安装LiveReload插件并安装guard-livereload gem,这样您可以在规范或资产发生变化时自动重新加载浏览器。
启动后卫,然后耙茉莉,然后在浏览器中加载茉莉花规格,然后按实时重新加载按钮连接到守卫启动的实时重新加载服务器
更改您的文件。观看魔术发生,因为后卫运行jammit并指示您的浏览器刷新茉莉花规格。
Here's an example Guardfile to get you started:
这是一个让你入门的示例Guardfile:
guard 'jammit' do
watch(%r{public/javascripts/(.*)\.js})
watch(%r{app/views/jst/(.*)\.jst})
watch(%r{public/stylesheets/(.*)\.css})
end
guard 'livereload', :apply_js_live => false do
watch(%r{app/.+\.(erb|haml)})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
watch(%r{spec/javascripts/.+\.js})
end
#2
3
I've come up with an OK solution: force Jammit to reload and package when jasmine starts. To do this, you need to edit the jasmine_config.rb file:
我想出了一个很好的解决方案:强制Jammit重新加载并在茉莉花开始时打包。为此,您需要编辑jasmine_config.rb文件:
require 'jammit'
module Jasmine
class Config
Jammit.reload!
Jammit.package!
end
end
I wrote a bit more detailed post about it here: http://www.rebeccamiller-webster.com/2011/05/jammit-jasmine-bdd/
我在这里写了一篇更详细的帖子:http://www.rebeccamiller-webster.com/2011/05/jammit-jasmine-bdd/
#1
10
Here's the magic combo you're looking for:
这是您正在寻找的神奇组合:
- Use the guard gem along with the guard-jammit gem to watch for changes to your project's assets
- Install the LiveReload plugin in the browser of your choice and install the guard-livereload gem so you can have your browser auto reload whenever your specs or assets change.
- Fire up guard, then rake jasmine, then load your jasmine specs in your browser, then press the live-reload button to connect to the live-reload server that guard started
- Change your files. Watch the magic happen as guard runs jammit and instructs your browser to refresh the jasmine specs.
使用guard gem和guard-jammit gem来监视项目资产的变化
在您选择的浏览器中安装LiveReload插件并安装guard-livereload gem,这样您可以在规范或资产发生变化时自动重新加载浏览器。
启动后卫,然后耙茉莉,然后在浏览器中加载茉莉花规格,然后按实时重新加载按钮连接到守卫启动的实时重新加载服务器
更改您的文件。观看魔术发生,因为后卫运行jammit并指示您的浏览器刷新茉莉花规格。
Here's an example Guardfile to get you started:
这是一个让你入门的示例Guardfile:
guard 'jammit' do
watch(%r{public/javascripts/(.*)\.js})
watch(%r{app/views/jst/(.*)\.jst})
watch(%r{public/stylesheets/(.*)\.css})
end
guard 'livereload', :apply_js_live => false do
watch(%r{app/.+\.(erb|haml)})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
watch(%r{spec/javascripts/.+\.js})
end
#2
3
I've come up with an OK solution: force Jammit to reload and package when jasmine starts. To do this, you need to edit the jasmine_config.rb file:
我想出了一个很好的解决方案:强制Jammit重新加载并在茉莉花开始时打包。为此,您需要编辑jasmine_config.rb文件:
require 'jammit'
module Jasmine
class Config
Jammit.reload!
Jammit.package!
end
end
I wrote a bit more detailed post about it here: http://www.rebeccamiller-webster.com/2011/05/jammit-jasmine-bdd/
我在这里写了一篇更详细的帖子:http://www.rebeccamiller-webster.com/2011/05/jammit-jasmine-bdd/