Why?

I am not good at writing bug-free code in JavaScript or CoffeeScript. I am equally not good at writing bug-free tests. It would be nice to have a way to quickly build a basic 'safety net' for my code, and be able to describe the tests in a format less verbose than 'describe->it-should->etc'.

It should also be a good learning experience.

Goals

  1. Short and sweet syntax for asserting basic behaviour.
  2. It should be relatively easy to create new ad-hoc assertions.

How should it work?

# describe how they should work
describe 'asserters.verify', ->
	# describe a mock module that 'exports' various things
	myModule =
		export1: {a:'a', b:'b'}
		export2: i:'am', one:'object'
		funcWithNoArgs: (callback) -> callback(null, "with", "some", "extra")
		funcWithOneArg: (input, callback) ->
			assert _.isFunction(callback), "callback must be a function"
			callback(new Error("error") if input is "error")
		funcWithTwoArgs: (input1, input2, callback) ->
			assert _.isFunction(callback), "callback must be a function"
			if input1 is "error" or input2 is "error"
				callback(new Error("error"))
			else
				callback(null, "with", "some", "extra")

	# describe the assertions that need to be performed
	myAsserts =
		abc: [ new Asserter(), new Asserter() ] # abc doesn't exist, but the asserter doesnt require it
		# abc2: [ a.IsDefined ] # this would fail
		# def: [ new AssertIsDefined() ] # def doesn't exist
		export1: [ a.IsObject, a.HasFields(['a', 'b']) ]
		export2: [ a.IsObject, a.HasFields(['i', 'one']) ]
		funcWithNoArgs: [ a.CanCallback() ]
		funcWithTwoArgs: [ a.CanCallbackError('success', 'error'), a.CanCallback('success', 'success') ]
		funcWithOneArg: [ a.CanCallbackError('error'), a.CanCallback('success') ]

	it 'should get no errors when verified', (done) -> a.verify myAsserts, myModule, done