Culerity = Full Stack Rails Testing with Cucumber and Celerity

Since the day we started upstream testing was our obsession. When we began all we had was the Rails built-in unit, functional and integration tests. When we learned about RSpec the world became a brighter place. When the RSpec team released their StoryRunner we were thrilled. We started writing stories in English and were able to run them. Whoa. It soon turned out the first version had some serious issues with staying DRY. More versions were released, we rewrote our stories, step by step StoryRunner got better and we got better, too.

Then Cucumber came out and it was a huge leap ahead again. With the integration of Webrat we could write much shorter stories, but more importantly we could test that our links and forms were working as well. Everything was working perfectly and the world was a happy place – as long as we didn’t use any JavaScript/AJAX…

Welcome to Culerity. Culerity is a small gem that integrates Cucumber with Celerity, a wrapper around HtmlUnit which in turn is a Java library that parses HTML and runs the embedded JavaScript code. And unlike Watir or Selenium this all happens in headless mode: without hijacking your browser.

The problem with Celerity has been that it only works in a JRuby environment, which means you either had to run your application in JRuby as well (which might not even work with certain libraries and plugins) or somehow work your way around it by running your tests in JRuby and your application in whatever Ruby you wanted to use and somehow glue it together. Culerity now fills this gap. After installing it you run your Cucumber features as usual. Celerity now spawns a Java process in the background, sends all the Celerity calls to this process and evaluates the results back in the original Ruby environment — everything works (almost) as if you were running just in your single Ruby process. For an easier start Culerity comes with the same set of Cucumber step definitions that are provided by a default Cucumber/Webrat installation. This means you can reuse your step definitions written for Webrat.

To get started you can either clone the GitHub repository or simply install the gem (langalex-culerity). Then follow the instructions in the README. If you find something is not working for you or could be improved please feel free to fork the source code and show it some love. The codebase is really small right now and fully spec’d.

Does your company need help with software testing? We can help: check out our new product Scene Investigation.

Tags: , , , , , , , ,

6 Responses to “Culerity = Full Stack Rails Testing with Cucumber and Celerity”

  1. Bug fighting with Test Driven Development Followup | upstream agile - software Says:

    [...] Culerity [...]

  2. Joseph Wilk » Outside-in Development with Cucumber and Rspec Says:

    [...] Using Celerity from within Ruby – Culerity – http://upstream-berlin.com/2009/01/28/culerity-full-stack-rails-testing-with-cucumber-and-celerity/ [...]

  3. Matt Says:

    Did you guys have any trouble setting this up at all. I’ve just spent the last 3 days fixing tests after switching from cucumber/webrat to cucumber/culerity and now that I have added my first JS scenario I get these warnings in the cucumber console output for every single js file that the page loads:

    WARNING: Expected content type of ‘application/javascript’ or ‘application/ecmascript’ for remotely loaded JavaScript element at ‘http://celerity.mysite.local/javascripts/application.js?1245351752′, but got ‘application/x-javascript’.

    And it seems that the javascript is not being executed (well celerity seems unable to see hidden links that are made visible via js anyway) :(

    p.s. on a side note, are you unit testing your JS too? I’ve just started using jspec, and it seems pretty awesome: http://visionmedia.github.com/jspec/

  4. Alexander Lang Says:

    hi matt,

    well, there are a few subtle differences in how webrat and celerity work so we also spent some time fixing tests. but after that it worked ok.

    maybe the wrong content type you see in the warning prevents your javascript from being executed. have you tried putting the js into your html? does that work?

    looks like whatever web/app server you are using is sending a content type celerity is not expecting. maybe it works after you change that content type.

    unfortunately i can’t help you too mich with your problems. they are not culerity but celerity related which itself is only a wrapper for htmlunit. maybe they can help you.

    p.s. we do unit test your javascript. at the moment with blue-ridge (which allows us to do headless js unit testing) and screwunit. jspec looks nice though.

  5. admic Says:

    Muxoci =))))))))))))))))))))))))))))))))))))))))))))))

  6. admic Says:

    =))))))))))))))))))))))))))))))))))))))

Leave a Reply