Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
40 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |