Sha256: fc318c5493ad2baa1cf716494bfdeda6e86b13a341d8115317b5d1f4a42b880f

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

require 'helper'

describe BehaviorFactory do
  let(:some_behavior) { stub('some behavior', required_behaviors: []) }
  let(:object_context) { mock('object context') }
  let(:some_actor) { stub('some actor', add_behavior: nil, this_object_context: object_context) }
  let(:some_block) { Proc.new }

  before do
    Behavior.define :shootable
    object_context.stubs(:[]).with(:behavior).returns(some_behavior)
    object_context.stubs(:in_subcontext).yields(object_context)
    some_behavior.stubs(:opts=)
  end

  describe "#add_behavior" do
    it 'creates the behavior based on the actor and symbol behavior_def' do
      some_behavior.expects(:opts=).with({})

      subject.add_behavior some_actor, :shootable
    end

    it 'adds the behavior to the actor' do
      some_actor.expects(:add_behavior).with(:shootable, some_behavior)
      subject.add_behavior some_actor, :shootable
    end

    it 'configures the behavior with the given opts' do
      opts = {some: 'opts'}
      some_behavior.expects(:opts=).with(opts)

      subject.add_behavior some_actor, :shootable, opts 
    end

    it 'raises on nil actor' do
      lambda { subject.add_behavior nil, {} }.should raise_exception(/nil actor/)
    end

    it 'raises on nil behavior def' do
      lambda { subject.add_behavior some_actor, nil }.should raise_exception(/nil behavior definition/)
    end

    it 'raises for missing behavior' do
      lambda { subject.add_behavior actor, :do_not_exist }.should raise_exception
    end

    it 'creates all required behaviors'
    it 'mixes in helpers'
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gamebox-0.5.5 spec/core/behavior_factory_spec.rb
gamebox-0.5.4 spec/core/behavior_factory_spec.rb
gamebox-0.5.2 spec/core/behavior_factory_spec.rb
gamebox-0.5.1 spec/core/behavior_factory_spec.rb
gamebox-0.5.0 spec/core/behavior_factory_spec.rb
gamebox-0.4.1 spec/core/behavior_factory_spec.rb