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?
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.
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.
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.
I'm wondering if I could somehow:
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
Here's the magic combo you're looking for:
Here's an example Guardfile to get you started:
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
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:
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With