Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Harmony: JavaScript And A DOM Environment In Ruby

By Peter Cooper / February 17, 2010

harmony.pngHarmony, from Martin Aumont, is a new Ruby DSL for executing JavaScript and DOM-using code from within Ruby apps. Why's that cool? Well, it enables you to build your own Ruby-level unit tests for JavaScript code within your Web applications - everything can be under one set of test suites!

Harmony sounds like a significant piece of engineering, but really it's a wrapper that stands on the shoulder of giants in the form of Johnson, which provides the Mozilla Spidermonkey Javascript runtime to Ruby, and env.js, a DOM environment recreated in JavaScript.

Harmony's "Hello World" example:

harmony2.png

HolyGrail: The Rails Plugin

If you're using Rails, HolyGrail is a plugin that brings the power of Harmony to your apps (so far in functional tests only). Some example tests with HolyGrail:

holygrailtest.png

Note: This Harmony is not to be confused with the awesome Harmony CMS that esteemed Rubyist John Nunemaker is working on..

Comments

  1. Julio Cesar Ody says:

    I'm using it for a project of mine, as a way to be able to stay within RSpec land and test JS without relying on Selenium.

    http://github.com/juliocesar/shining/blob/master/spec/shining_spec.rb

    If like me you're planning on writing tests/specs with harmony in the form of a local page acting as a fixture that includes some Javascript in the head, you might want to use Harmony::Page.fetch and pass a file URI (file:///) as a parameter.

  2. Lori M Olson says:

    Thanks for sharing that, Julio! Having an RSpec example suddenly makes Harmony a LOT more interesting to me.

  3. george naing says:

    Thank you very much for your example of using Ruby as a DSL
    Cheers

    george

    http://www.rubyinside.com/

  4. george naing says:

    did my comments go in?

  5. george naing says:

    did my comment go in?

  6. Brian Demant says:

    Does Harmony handle AJAX, Events and other asynchronous?

  7. justin says:

    Thanks for the example, oh and George your comment went in!!!

Other Posts to Enjoy

Twitter Mentions