OO style examples for oojspec (CoffeeScript)
by rosenfeld
HTML
<script src="http://oojspec.herokuapp.com/assets/oojspec.js"></script>
<link rel="stylesheet" href="http://oojspec.herokuapp.com/assets/oojspec.css">
CoffeeScript
oojspec.exposeAll()
describe class
@description: 'Bare class'
@bare: true
runSpecs: (dsl)->
@dialog = dialog: true
dsl.example 'an example', @anExample
dsl.context 'in some context', @aContext
dsl.describe NonBareClass
anExample: (s)-> s.expect(@dialog).toEqual dialog: true
aContext: (s)-> s.example 'another example', (s)-> s.refute @describe
class NonBareClass
runSpecs: ->
@dialog = dialog: true
@example 'an example', @anExample
@context 'in some context', @aContext
anExample: -> @expect(@dialog).toEqual dialog: true
aContext: -> @example 'another example', -> @refute @describe
describe
description: 'Plain Object binding'
dialog: {dialog: true}
runSpecs: -> @example 'an example', @sampleExample
sampleExample: -> @assert @dialog.dialog
# or just make use of this in regular describe blocks:
describe "Regular describe", ->
@example "'this' is propagated", ->
@expect(@helper()).toBe 1
@helper = -> 1
describe "Regular describe with bare set up", ->
@bare = true
@timeout = 100
@example "'this' is propagated but DSL is not injected", (s)->
s.expect(@timeout).toBe 100
s.refute @expect
oojspec.runSpecs()