Permalink
Browse files

Clean up positioned behavior specs

  • Loading branch information...
1 parent 5dc966d commit daf08ba0c6657b7b94be6cae937d7622c95c696b @shawn42 committed Feb 15, 2014
Showing with 32 additions and 46 deletions.
  1. +2 −0 .rspec
  2. +1 −2 lib/gamebox/behaviors/positioned.rb
  3. +2 −3 lib/gamebox/spec/helper.rb
  4. +27 −41 spec/behaviors/positioned_spec.rb
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
@@ -2,8 +2,7 @@
setup do
x = opts[:x] || 0
y = opts[:y] || 0
- actor.has_attributes x: x, y: y
- actor.has_attributes position: vec2(actor.x, actor.y)
+ actor.has_attributes position: vec2(x, y), x: x, y: y
actor.when(:x_changed) { actor.position = vec2(actor.x, actor.y) }
actor.when(:y_changed) { actor.position = vec2(actor.x, actor.y) }
@@ -23,6 +23,7 @@ def subjectify_behavior(behavior_name)
before {
@_beh_mock_names = Behavior.object_definition.component_names
@actor = evented_stub(mock("actor_for_#{behavior_name}"))
+ @actor.stubs(has_attribute: nil)
@_mocks_created = create_mocks *(@_beh_mock_names - [:actor])
@_mocks_created[:actor] = @actor
@@ -206,9 +207,7 @@ def initialize(object)
def method_missing(name, *args)
@inner_stub.send name, *args
end
- def fire(*args)
- super
- end
+ public :fire
end
module GameboxAcceptanceSpecHelpers
@@ -1,63 +1,49 @@
require 'helper'
describe :positioned do
+ subjectify_behavior :positioned
- subject! { subcontext[:behavior_factory].add_behavior actor, :positioned, opts }
- let(:director) { evented_stub(stub_everything('director')) }
- let(:subcontext) do
- it = nil
- Conject.default_object_context.in_subcontext{|ctx|it = ctx};
- it[:director] = director
- _mocks = create_mocks *(Actor.object_definition.component_names + ActorView.object_definition.component_names - [:actor, :behavior, :this_object_context])
- _mocks.each do |k,v|
- it[k] = v
- end
- it
- end
- let!(:actor) { subcontext[:actor] }
let(:opts) { {} }
+ before do
+ actor.stubs(:has_attributes)
+ end
context "empty options" do
- it 'defines x,y on actor' do
- actor.x.should == 0
- actor.y.should == 0
- end
-
- it 'defines position' do
- actor.position.should == vec2(0,0)
+ it 'defines x,y,position on actor' do
+ actor.expects(:has_attributes).with(x: 0, y: 0, position: vec2(0,0))
+ subject
end
end
- it 'keeps position up to date w/ x and y' do
- called = 0
- actor.when(:position_changed) do
- called += 1
- end
- actor.x = 99
- called.should == 1
+ it 'updates position on x change' do
+ subject
- actor.y = 8
+ actor.expects(:position=).with(vec2(1,2))
+ actor.stubs(x: 1, y: 2)
+ actor.fire(:x_changed)
+ end
+
+ it 'updates position on y change' do
+ subject
- called.should == 2
- actor.position.should == vec2(99,8)
+ actor.expects(:position=).with(vec2(1,2))
+ actor.stubs(x: 1, y: 2)
+ actor.fire(:y_changed)
end
context "options passed in" do
let(:opts) { { x: 5, y: 8} }
- it 'defines x,y on actor' do
- actor.x.should == 5
- actor.y.should == 8
- end
-
- it 'defines position on actor' do
- actor.position.should == vec2(5,8)
+ it 'defines x,y,position on actor' do
+ actor.expects(:has_attributes).with(x: 5, y: 8, position: vec2(5,8))
+ subject
end
-
end
it "keeps x and y up to date if position changes" do
- actor.position = vec2(1,2)
- actor.x.should == 1
- actor.y.should == 2
+ subject
+
+ actor.expects(:update_attributes).with(x: 2, y: 3)
+ actor.stubs(position: vec2(2,3))
+ actor.fire(:position_changed)
end
end

0 comments on commit daf08ba

Please sign in to comment.