spec/collidable_spec.rb in gamebox-0.2.1 vs spec/collidable_spec.rb in gamebox-0.3.2
- old
+ new
@@ -1,50 +1,70 @@
require File.join(File.dirname(__FILE__),'helper')
-require 'collidable'
+class SizedActor < Actor
+ def width;12;end
+ def height;10;end
+end
+
describe 'A new collidable behavior' do
before do
- @stage = mock(:register_collidable => nil)
+ @stage = stub(:register_collidable => nil)
@actor_opts = {:actor_type => :actor, :stage=>@stage, :input=>"input", :resources=> :rm}
@actor = Actor.new @actor_opts
end
+ describe "aabb shape" do
+ before do
+ @behavior_opts = {:shape => :aabb,
+ :cw_world_points => [
+ [-15,10],[15,10],
+ [15,-10], [-15,10]
+ ]}
+ @actor = SizedActor.new @actor_opts
+ @collidable = Collidable.new @actor, @behavior_opts
+ end
+
+ it "constructs based on points" do
+ @collidable.collidable_shape.should == :aabb
+ end
+ end
+
describe "circle shape" do
before do
@behavior_opts = {:shape => :circle}
@collidable = Collidable.new @actor, @behavior_opts
end
it 'should recalculate_collidable_cache on update' do
- @collidable.shape.should_receive(:recalculate_collidable_cache)
+ @collidable.shape.expects(:recalculate_collidable_cache)
@collidable.update 4
end
it 'should relegate methods on actor' do
- @collidable.should_receive(:width).and_return(44)
+ @collidable.expects(:width).returns(44)
@actor.width.should == 44
- @collidable.should_receive(:height).and_return(45)
+ @collidable.expects(:height).returns(45)
@actor.height.should == 45
- @collidable.should_receive(:collidable_shape).and_return(:circlez)
+ @collidable.expects(:collidable_shape).returns(:circlez)
@actor.collidable_shape.should == :circlez
end
it 'should calculate center point for circle' do
@actor.x = 3
@actor.y = 6
@collidable = Collidable.new @actor, :shape => :circle, :radius => 20
- @collidable.center_x.should be_close(23, 0.001)
- @collidable.center_y.should be_close(26, 0.001)
+ @collidable.center_x.should be_within(0.001).of(3)
+ @collidable.center_y.should be_within(0.001).of(6)
end
end
describe "polygon shape" do
it 'should calculate center point for polygon' do
@collidable = Collidable.new @actor, :shape => :polygon, :points => [[0,0],[10,7],[20,10]]
- @collidable.center_x.should be_close(10, 0.001)
- @collidable.center_y.should be_close(5, 0.001)
+ @collidable.center_x.should be_within(0.001).of(10)
+ @collidable.center_y.should be_within(0.001).of(5)
end
it 'should translate points to world coords for poly' do
@actor.x = 10
@actor.y = 5