Skip to content

Instantly share code, notes, and snippets.

@cemeng
Created August 15, 2012 03:38
Show Gist options
  • Save cemeng/3355490 to your computer and use it in GitHub Desktop.
Save cemeng/3355490 to your computer and use it in GitHub Desktop.
Jasmine, Angular, Rails, Coffeescript - my oh my

Goals:

  • Support Coffeescript testing
  • Headless - run from command line
  • Test can be written in Coffeescript

Test libraries, two main alternatives:

  • Jasmine
  • Mocha

Jasmine is older - actively maintained by PivotalLabs, de facto JS testing for Rails projects? So I'd expect there are more gems/projects that integrate Jasmine and Rails compared to Mocha (at the moment anyway).

Mocha is newer - better support for asyn process test (not sure if that matters too much for us at the moment).

Some notes: Evergreen author suggests to use mocha:

I find that Mocha has superior support for testing asynchronous processes, which is kind of important when it comes to JS. It also plays nicer with the node and JS eco system. Jasmine is pretty much unusable in node.js. I'd rather use only one framework, regardless of where I work and Mocha works everywhere.

Source

Although apparently it is not difficult to switch from Jasmine to Mocha in the future source

Jasmine Test Framework

Options

Evergreen

Not maintained anymore

Jasminerice vs jasmine-rails

Both support assets pipeline and thus Coffeescript, both support headless test. Looks really similar - I'd give jasminerice a try simply because it has more downloads (as reported by ruby toolbox).

http://www.derekhammer.com/2012/02/18/testing-coffeescript-for-rails-with-jasmine.html

Mocha Test Framework

Future maybe?

Side Notes

Angular Problem: ReferenceError: inject is not defined Solution: Need to include angular js mock.

Links

https://github.com/angular/angular.js/wiki/JsFiddle-Examples - most useful - just look at Jasmine examples https://github.com/angular/angular-seed/blob/master/test/unit/controllersSpec.js - uhm ok .. more details please? https://github.com/IgorMinar/angular-phonecat/blob/master/test/unit/servicesSpec.js - seems outdated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment