Skip to content

Commit

Permalink
Run before blocks of ancestor descriptions once before each example
Browse files Browse the repository at this point in the history
Since this breaks compatibility the version was changed to 0.3.0.

Previously any @before block for some description would be run only once
for a whole inner context examples group. Now they will be run once
before each inner example.

I think this behavior makes more sense after thinking a bit about it.
  • Loading branch information
rosenfeld committed Jan 15, 2015
1 parent 6dae934 commit 8f59d2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions lib/assets/javascripts/oojspec/runner.js.coffee
Expand Up @@ -90,7 +90,7 @@ RESERVED_FOR_EXAMPLE_DSL = ['assert', 'expect', 'fail', 'refute', 'waitsFor', 'r
class Description
RESERVED = RESERVED_FOR_DESCRIPTION_DSL.concat RESERVED_FOR_EXAMPLE_DSL

constructor: (@description, @block)->
constructor: (@description, @block, @beforeBlocks = [], @afterBlocks = [])->
if @description.runSpecs or @description.prototype?.runSpecs
@block = @description
@description = @block.description or @block.name
Expand Down Expand Up @@ -126,15 +126,15 @@ class Description

removeDsl: -> delete @binding[p] for p in RESERVED_FOR_DESCRIPTION_DSL; return

run: (@params, @onFinish, @beforeBlocks = [], @afterBlocks = [])->
run: (@params, @onFinish)->
@events.emit 'context:start', name: @description
if @bindingError
@events.emit 'test:error', name: @description, error: @bindingError
@onDescriptionFinished @bindingError
else
@doRun()

doRun: -> @runAround @beforeBlocks, @afterBlocks, @onDescriptionFinished, @processDescriptionBlock
doRun: -> @runAround [], [], @onDescriptionFinished, @processDescriptionBlock

onDescriptionFinished: (error)=>
if error and not error.handled
Expand All @@ -154,6 +154,7 @@ class Description
(@onExamplesFinished(); return) unless @dsl._examples_.length
nextStep = @dsl._examples_.shift()
(@reportDeferred(nextStep.description); @runNextStep(); return) if nextStep.pending
@prependHooks nextStep
nextTick =
if nextStep instanceof Description then =>
nextStep.run @params, @runNextStep, @dsl._beforeBlocks_, @dsl._afterBlocks_
Expand All @@ -170,6 +171,12 @@ class Description
@events.emit 'test:error', { name, error }
@onFinish(error)

prependHooks: (nextStep)->
@cloneAndPrepend nextStep, type for type in ['beforeBlocks', 'afterBlocks']

cloneAndPrepend: (nextStep, type)->
(nextStep[type] = nextStep[type].slice 0).unshift this[type]...

reportDeferred: (description)-> @events.emit 'test:deferred', name: description

class DescribeDsl
Expand Down
2 changes: 1 addition & 1 deletion lib/oojspec/version.rb
@@ -1,3 +1,3 @@
module Oojspec
VERSION = "0.2.0"
VERSION = "0.3.0"
end

0 comments on commit 8f59d2d

Please sign in to comment.