require '../spec_helper'

describe "Freakset Acceptance", ->
  
  beforeEach ->
    @freakset = new Freakset()
    @set = null
   

  it "should compile a simple Group Freakset", ->

    @freakset.group "group:simple", (innerFreakset) ->

      innerFreakset.step "step1", (set) ->
        set.store['steps'].push("step1")
        set.commit()

      innerFreakset.step "step2", (set) ->
        set.store['steps'].push("step2")
        _.delay ( => set.commit() ), 50


    @set = @freakset.compile { steps: [] }

    waitsFor -> !@set.isRunning()

    runs ->
      expect(@set.store['steps']).toContain("step1")
      expect(@set.store['steps']).toContain("step2")
      
      
  it "should compile a parallel Group Freakset", ->
    
    @freakset.group "group:parallel", { parallel: yes }, (innerFreakset) ->
      
      innerFreakset.step "step1", (set) ->
        _.delay ( => 
          set.store['steps'].push("step1")
          _.delay ( => set.commit() ), 500
        ),100
          
      innerFreakset.step "step2", (set) ->
        set.store['steps'].push("step2")
        _.delay ( => set.commit() ), 500
  
    
    @set = @freakset.compile { steps: [] }
    
    # Just wait until compiling startet..
    waits(150)
    
    runs ->
      expect(@set.store['steps']).toContain("step1")
      expect(@set.store['steps']).toContain("step2")