From 46d689fa327a5e5c1bd08c85dbb0ddafb0ac1a73 Mon Sep 17 00:00:00 2001 From: John Croisant Date: Sat, 30 Jun 2012 23:28:42 -0500 Subject: [PATCH] Moved most BehaviorFactory specs to Actor specs. 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. --- spec/core/actor_spec.rb | 38 ++++++++++++++++++++++-- spec/core/behavior_factory_spec.rb | 47 ++++-------------------------- 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/spec/core/actor_spec.rb b/spec/core/actor_spec.rb index 237716a..e8ea7db 100644 --- a/spec/core/actor_spec.rb +++ b/spec/core/actor_spec.rb @@ -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 diff --git a/spec/core/behavior_factory_spec.rb b/spec/core/behavior_factory_spec.rb index 0d37c29..f8c4163 100644 --- a/spec/core/behavior_factory_spec.rb +++ b/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