Skip to content

Instantly share code, notes, and snippets.

@interlock
Created April 3, 2013 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save interlock/5304425 to your computer and use it in GitHub Desktop.
Save interlock/5304425 to your computer and use it in GitHub Desktop.

Units Jasmine

My hack to output a CSV of Specs and estimates associated to them. I used this for a project that we wrote stub specs for instead of a requirements document for. Ultimately, needed to get a general idea of the amount of work, so created this Jasmine plugin.

Usage

This is for jasmine specs that run within node.js. It will not work in a browser.

Within any "it" spec, call units(x) to associate an estimated number of work units for that spec. The units are whatever you use to do project planning, in my case, 0,1,2,4,8.

The helper automatically binds to jasmine and creates a units.csv in your root folder.

((jasmine) ->
fs = require('fs')
util = require('util')
csv = require('csv')
root = @
@.units = ->
context = jasmine.getEnv().currentSpec
context.results_.units = arguments[0]
# Reporter
jasmine.UnitReporter = class UnitReporter
constructor: ->
@csv = []
return
reportSuiteResults: (suite) ->
suiteName = suite.getFullName()
results = suite.results()
@csv.push([suiteName,spec.description,spec.units || ""]) for spec in results.items_ when spec.description isnt undefined
@write()
write: () ->
csv().from(@csv).to.options({rowDelimiter:'windows',delimiter:',',quoted:true}).to('units.csv')
# console.log jasmine
jasmine.getEnv().addReporter( new jasmine.UnitReporter )
) jasmine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment