Wednesday, July 14, 2010

JSpec tests running in CI

A lot of people, myself included, have been TDDing our javascript for awhile but it seems like it's still fairly rare for the tests to be run in the CI build. I've taken some time today to get our existing suite of JSpec tests to run in our CI server (Hudson in our case) and thought I would share what I did. My general approach should be useful regardless of which CI server you are using.

It's actually fairly simple: I'm using the capybara selenium driver to run the JSpec tests and grab the results from the DOM when they finish. Here's the testcase:

I define an array of all my jspec tests, loop over them, munge them into a legal test method name and define a method that delegates to run_jspec. run_spec opens a file url (had to go underneath capy here so its a little icky) and then waits for the .failures div to appear. It should be noted that capybara will wait for an element to appear when you call page.has_css?

From here, running it under CI is trivial. In fact I didn't have to do anything at all, the tests was found by rake test:integrations and ran (and passed!) in the next build. Most of the heavy lifting is done by capybara and selenium-webdriver.

Obviously there is a lot that could be done to improve this code. I could grab the jspec file from a FileList, and grab some better failure messages from the DOM. I could also probably write a custom JSpec formatter to make this easier on myself even. I'm thinking if there is interest I could finish this up and turn it into a gem. Please comment if you'd use such a thing.

Also, one more thing you will need is the JSpec runner file that can run a single test. I did that like so:

The actualCheap wow gold banter backwards and forwards don't seem to be very well as I hoped. Rick eventually left me my personal open positions, I merely got tense and had difficulties creating normalBuy rs gold appearing tendencies.

Such was the prevailing predicament inside the ancient Chinese civilization. The impact was also noticed on the ancient Chinese clothing of the common man. Correct attire was regarded because the ultimate expression of Chinese culture and identity, differentiating them from 'inferior' foreign neighbors while producing social and gender distinctions within their society. The ancient Chinese clothes had distinct cultural meaning Chinese Fashion, with correctly attired bodies reflecting order and control and unadorned bodies and feet serving as visible indicators of disorder and risky nonconformity with the individual risking association to barbarian outsiders.

Guys, do you like to play MMORPG? Guild Wars 2 is one of the most wonderful MMORPGs.I'm a big fan of Guild Wars 2 and good at farming Guild Wars 2 gold. I know a good website to update game guidance about how to farm gold. The cheap Guild Wars 2 gold is also available in that store. So, if you lack gold, you can have a try of that store. Just click the colored word which will direct you.

Buy D3 Gold Furthermore, i feel there is no spot for the Robber throughout competetive staff matches for that reality that you can not continue being great Guild Wars 2 Gold at melee whatsoever with the amount of CC's every staff has and the way soft our own profeession is actually.

JavaScript Training Course is essential to the achievements of an individual. Perhaps its most positive benefit is better employees. A company develop the potential of an employee, and part of the way a company encourages improvement is through training.