Skip to content

Instantly share code, notes, and snippets.

@andrewrlee
Created September 22, 2013 20:18
Show Gist options
  • Save andrewrlee/6663394 to your computer and use it in GitHub Desktop.
Save andrewrlee/6663394 to your computer and use it in GitHub Desktop.
Simple Coffeescript substeps style test runner.
class Runner
constructor: (@steps) ->
_execute = (input, name, step) ->
args = step.pattern.exec input
step.method args.slice(1)...
execute : (input) -> _execute(input, name, step) for name, step of @steps \
when input.match step.pattern
executeScript : (script) -> @execute statement.trim() for statement in script.split "\n"
######################################################################################################
steps =
aaa :
pattern : /^aaa$/
method : () -> console.log "111"
bbb:
pattern : /^bbb(.+)kk(.+)$/
method : (val, val2) -> console.log val + " XXX " + val2
run = new Runner(steps)
run.execute "aaa"
run.executeScript """
aaa
ccc
bbbaakksdasfkadfjdjvcldajciad
aaadvgsfggdaaaafdfdsfaaasdgsg
bbbsdsdsadaskkfdfdfef
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment