what did i learn today
News ruby jasmine tdd
using jasmine without rails

Assume you have, like I did, a ruby gem that contains some javascript you want to test standalone. First you need to install the jasmine-gem. You have two options:

  • either you use your gemspec to drive your bundler gemfile, so just add it to your developement dependencies
  • I am still using jeweler, so I use a normal Gemfile, which jeweler parses to populate my gemspec with. Personally I find this much easier, and my workflow is much closer to any ruby development for me, this way

If you have a rails-project, starting with jasmine is easy, and takes three easy steps:

# first add jasmine to Gemfile, and then 
bundle install 
rails g jasmine:install 
rake jasmine 

Inside your gem or simple ruby-project it is equally simple, just type

jasmine init 
rake jasmine

Now you can need to edit the jasmine.yml to make sure it is running your tests and your code, instead of the example code. In my case I had to change only one line:

src_files: - app/assets/javascripts/\*\*/\*.js 

Happy testing :) Some interesting links to help you with jasmine:

More ...