Skip to content

Commit

Permalink
Moved most BehaviorFactory specs to Actor specs.
Browse files Browse the repository at this point in the history
TODO: There are 3 pending Actor specs that I can't make work because I
don't understand what's going on with the conjected/mock objects.
  • Loading branch information
jacius committed Jul 1, 2012
1 parent 615e10d commit 46d689f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 45 deletions.
38 changes: 35 additions & 3 deletions spec/core/actor_spec.rb
Expand Up @@ -21,10 +21,42 @@
end

describe "#add_behavior" do
it 'adds a behavior to the actors list of behaviors' do
subject.add_behavior :foo, :bar
subject.has_behavior?(:foo).should be_true
before do
define_behavior :test_behavior do
setup do
actor.has_attributes(test_attr: opts[:test_attr])
end
end
end

it 'adds a behavior to the actor\'s list of behaviors' do
pending "jacius doesn't understand conjected objects"
subject.add_behavior :test_behavior
subject.has_behavior?(:test_behavior).should be_true
end

it 'sets up the behavior on the actor' do
pending "jacius doesn't understand conjected objects"
subject.add_behavior :test_behavior
subject.has_attribute?(:test_attr).should be_true
end

it 'configures the behavior with the given opts' do
pending "jacius doesn't understand conjected objects"
subject.add_behavior :test_behavior, test_attr: 'test'
subject.test_attr.should == 'test'
end

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

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

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

describe "#remove_behavior" do
Expand Down
47 changes: 5 additions & 42 deletions spec/core/behavior_factory_spec.rb
@@ -1,50 +1,13 @@
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) }

before do
Behavior.define :shootable

object_context.stubs(:[]).with(:behavior).returns(some_behavior)
object_context.stubs(:in_subcontext).yields(object_context)
some_behavior.stubs(:configure)
end

describe "#add_behavior" do
it 'creates the behavior based on the actor and symbol behavior_def' do
some_behavior.expects(:configure).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 "should call #add_behavior on the actor" do
opts = {foo: 'bar'}
some_actor = stub("actor")
some_actor.expects(:add_behavior).with(:some_behavior, opts)

it 'configures the behavior with the given opts' do
opts = {some: 'opts'}
some_behavior.expects(:configure).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
subject.add_behavior( some_actor, :some_behavior, opts )
end

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

0 comments on commit 46d689f

Please sign in to comment.