Karma Rails Angular Jasmine testing - set up in 5 minutes

It took me about an hours and a half because google is not up to date, so here it is:

First - as a rails developer, if you don't have node.js, this is the time to install it.
If you don't use RubyMine as you IDE, I recommend it as well, but whatever you prefer is fine by me.
Here you'll fins instructions about karma installation, follow them carefully.

You'll see that you need to tell karma where is your sources and test sources.

I'm working with jasmine, and using angular as a gem, check my configuration:

frameworks: ['jasmine'],


        // list of files / patterns to load in the browser
        files: [
            //libs

            'http://0.0.0.0:3000/assets/application.js',
            '/Users/chen/.rvm/gems/ruby-1.9.3-p448/gems/angularjs-rails-1.2.9/vendor/assets/javascripts/angular-mocks.js',
            'spec/javascripts/controllers/sample.js',

            'spec/javascripts/controllers/*/*_spec.js.coffee',
            'spec/javascripts/controllers/**/*_spec.js.coffee',
            'spec/javascripts/controllers/**/*_spec.coffee',
            'spec/javascripts/controllers/**/*_spec.js'
]


To things you should notice:
1. I use rails assets pipeline to give all my app code js, (just run your server before you test)
2. I add the angular mocks lib


All other stuff are basic, I got code in coffee and js so needed a little more lines to find all my tests.

this is the way to make this work pretty fast.

Comments

Popular Posts