require '../../../../spec_helper'

describe "Freakset.Actor.Group", ->

  beforeEach ->
    spyOn(Freakset, 'build').andReturn("innerFreakset")

    @freakset = {
      innerFreaksets: [],
      klass: Freakset,
      modifyStack: jasmine.createSpy(),
      stack: []
    }
    @Group = Freakset.Actor.Group

  describe '#build', ->

    it 'should create a inner Freakset with an empty stack, passing store and the current Freakset (as outer)', ->
      @Group.build @freakset, "scope:group", ->
      expect(Freakset.build).toHaveBeenCalledWith(store: @freakset.store, outerFreakset: @freakset, runInParallel: no)

    it 'should attach the actor definition to the stack', ->
      fn = ->
      @Group.build @freakset, "scope:group", fn
      expect(@freakset.modifyStack.mostRecentCall.args[0]).toEqual @freakset

    it 'should pass the parallel option to the actor definition', ->
      fn = ->
      @Group.build @freakset, "scope:group", { parallel: yes }, fn
      expect(@freakset.modifyStack.mostRecentCall.args[2].parallel).toBe true

    it 'should invoke the callback and pass the innerFreakset as argument', ->
      fn = jasmine.createSpy()
      @Group.build @freakset, "scope:group", fn
      expect(fn).toHaveBeenCalledWith('innerFreakset')
