Geeks With Blogs
Liam McLennan

Tonight the Brisbane Alt.NET group is doing a coding dojo. I am hoping to talk someone into pairing with me to solve the kata in CoffeeScript. CoffeeScript is an awesome language, half javascript, half ruby, that compiles to javascript. To assist with tonight’s dojo I wrote the following micro test framework for CoffeeScript:


	<h2>Test Results:</h2>
	<p class='results' />
	<script src="" type="text/javascript"></script>

<script type="text/coffeescript">

# super simple test framework
test: {
	write: (s) ->
		$('.results').append(s + '<br/>')		
	assert: (b, message...) -> 
		test.write(if b then "pass" else "fail: " + message)
	tests: []
	exec: () ->
		for t in test.tests

# add some tests
test.tests.push { 
		name: "First Test"
		func: () ->	
test.tests.push {
		name: "Another Test" 
		func: () ->
			test.assert(false, "You loose")
# run them

<script type="text/javascript" src="coffee-script.js"></script>


It’s not the prettiest, but as far as I know it is the only CoffeeScript test framework in existence. Of course, I could just use one of the javascript test frameworks but that would be no fun. To get this example to run you need the coffeescript compiler in the same directory as the page.

Posted on Thursday, May 6, 2010 1:14 AM | Back to top

Copyright © Liam McLennan | Powered by: