diff options
-rw-r--r-- | spec/room_spec.rb | 130 |
1 files changed, 64 insertions, 66 deletions
diff --git a/spec/room_spec.rb b/spec/room_spec.rb index 26f5023..3e385e3 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -6,13 +6,16 @@ require 'spec_helper' # describe EvenDoors::Room do # + before (:all) do + @spin = EvenDoors::Spin.new 'dom0' + end + # before(:each) do - EvenDoors::Spin.clear! + @spin.clear! end # it "add_spot and add_link correctly" do - EvenDoors::Spin.debug_routing = false - r0 = EvenDoors::Room.new 'room0', nil + r0 = EvenDoors::Room.new 'room0', @spin d0 = EvenDoors::Door.new 'door0', r0 lambda { EvenDoors::Door.new('door0', r0) }.should raise_error(EvenDoors::Exception) lambda { r0.add_spot EvenDoors::Door.new('door1', r0) }.should raise_error(EvenDoors::Exception) @@ -21,9 +24,8 @@ describe EvenDoors::Room do end # it "start! and stop! should work" do - r0 = EvenDoors::Room.new 'room0', nil - d0 = Fake.new - r0.add_spot d0 + r0 = EvenDoors::Room.new 'room0', @spin + d0 = Fake.new 'fake', r0 d0.start.should be_nil d0.stop.should be_nil r0.start! @@ -35,20 +37,19 @@ describe EvenDoors::Room do end # it "parent, spin and search_down should be ok" do - s = EvenDoors::Spin.new 'dom0' - r0 = EvenDoors::Room.new 'r0', s + r0 = EvenDoors::Room.new 'r0', @spin r1 = EvenDoors::Room.new 'r1', r0 r2 = EvenDoors::Room.new 'r2', r1 - r3 = EvenDoors::Room.new 'r3', s + r3 = EvenDoors::Room.new 'r3', @spin r4 = EvenDoors::Room.new 'r4', r3 r2.parent.should be r1 r1.parent.should be r0 - r0.parent.should be s - r0.spin.should be s - r1.spin.should be s - r2.spin.should be s - r3.spin.should be s - s.search_down('dom0/r0/r1/r2').should be r2 + r0.parent.should be @spin + r0.spin.should be @spin + r1.spin.should be @spin + r2.spin.should be @spin + r3.spin.should be @spin + @spin.search_down('dom0/r0/r1/r2').should be r2 r0.search_down('dom0/r0/r1/r2').should be r2 r1.search_down('dom0/r0/r1/r2').should be r2 r2.search_down('dom0/r0/r1/r2').should be r2 @@ -58,8 +59,8 @@ describe EvenDoors::Room do end # it "route error: no source" do - room = EvenDoors::Room.new 'room', nil - p = EvenDoors::Spin.require_p EvenDoors::Particle + room = EvenDoors::Room.new 'room', @spin + p = @spin.require_p EvenDoors::Particle p.set_dst! 'get', 'room/door' room.send_p p p.action.should eql EvenDoors::ACT_ERROR @@ -68,9 +69,9 @@ describe EvenDoors::Room do end # it "route error: no destination no links" do - room = EvenDoors::Room.new 'room', nil - p = EvenDoors::Spin.require_p EvenDoors::Particle - p.src = Fake.new + room = EvenDoors::Room.new 'room', @spin + p = @spin.require_p EvenDoors::Particle + p.src = Fake.new 'fake', @spin room.send_p p p.action.should eql EvenDoors::ACT_ERROR p[EvenDoors::ERROR_FIELD].should eql EvenDoors::ERROR_ROUTE_NDNL @@ -78,10 +79,10 @@ describe EvenDoors::Room do end # it "route error: top room, wrong room" do - room0 = EvenDoors::Room.new 'room0', nil + room0 = EvenDoors::Room.new 'room0', @spin room1 = EvenDoors::Room.new 'room1', room0 - p = EvenDoors::Spin.require_p EvenDoors::Particle - p.src = Fake.new + p = @spin.require_p EvenDoors::Particle + p.src = Fake.new 'fake', @spin p.set_dst! 'get', 'noroom/door' room1.send_p p p.action.should eql EvenDoors::ACT_ERROR @@ -90,10 +91,10 @@ describe EvenDoors::Room do end # it "route error: right room, wrong door" do - room = EvenDoors::Room.new 'room', nil - p = EvenDoors::Spin.require_p EvenDoors::Particle - p.src = Fake.new - p.set_dst! 'get', 'room/nodoor' + room = EvenDoors::Room.new 'room', @spin + p = @spin.require_p EvenDoors::Particle + p.src = Fake.new 'fake', @spin + p.set_dst! 'get', 'dom0/room/nodoor' room.send_p p p.action.should eql EvenDoors::ACT_ERROR p[EvenDoors::ERROR_FIELD].should eql EvenDoors::ERROR_ROUTE_RRWD @@ -101,11 +102,11 @@ describe EvenDoors::Room do end # it "route error: right room, wrong door (bubble up)" do - room0 = EvenDoors::Room.new 'room0', nil + room0 = EvenDoors::Room.new 'room0', @spin room1 = EvenDoors::Room.new 'room1', room0 - p = EvenDoors::Spin.require_p EvenDoors::Particle - p.src = Fake.new - p.set_dst! 'get', 'room0/nodoor' + p = @spin.require_p EvenDoors::Particle + p.src = Fake.new 'fake', @spin + p.set_dst! 'get', 'dom0/room0/nodoor' room1.send_p p p.action.should eql EvenDoors::ACT_ERROR p[EvenDoors::ERROR_FIELD].should eql EvenDoors::ERROR_ROUTE_RRWD @@ -113,10 +114,10 @@ describe EvenDoors::Room do end # it "routing success (direct)" do - room0 = EvenDoors::Room.new 'room0', nil + room0 = EvenDoors::Room.new 'room0', @spin door0 = EvenDoors::Door.new 'door0', room0 - p = EvenDoors::Spin.require_p EvenDoors::Particle - p.src = Fake.new + p = @spin.require_p EvenDoors::Particle + p.src = Fake.new 'fake', @spin p.set_dst! 'get', 'door0' room0.send_p p p.action.should eql 'get' @@ -124,26 +125,26 @@ describe EvenDoors::Room do end # it "routing success (bubble up the direct door)" do - room0 = EvenDoors::Room.new 'room0', nil + room0 = EvenDoors::Room.new 'room0', @spin room1 = EvenDoors::Room.new 'room1', room0 door0 = EvenDoors::Door.new 'door0', room0 - p = EvenDoors::Spin.require_p EvenDoors::Particle - p.src = Fake.new - p.set_dst! 'get', 'room0/door0' + p = @spin.require_p EvenDoors::Particle + p.src = Fake.new 'fake', @spin + p.set_dst! 'get', 'dom0/room0/door0' room1.send_p p p.action.should eql 'get' p.dst.should be door0 end # it "route error: right room, no drill down (2xbubble up)" do - room0 = EvenDoors::Room.new 'room0', nil + room0 = EvenDoors::Room.new 'room0', @spin room1 = EvenDoors::Room.new 'room1', room0 room2 = EvenDoors::Room.new 'room2', room0 room3 = EvenDoors::Room.new 'room3', room2 door0 = EvenDoors::Door.new 'door01', room1 - p = EvenDoors::Spin.require_p EvenDoors::Particle - p.src = Fake.new - p.set_dst! 'get', 'room0/room1/door01' + p = @spin.require_p EvenDoors::Particle + p.src = Fake.new 'fake', @spin + p.set_dst! 'get', 'dom0/room0/room1/door01' room3.send_p p p.action.should eql EvenDoors::ACT_ERROR p[EvenDoors::ERROR_FIELD].should eql EvenDoors::ERROR_ROUTE_RRNDD @@ -151,9 +152,9 @@ describe EvenDoors::Room do end # it "routing success: no door name -> src" do - room0 = EvenDoors::Room.new 'room0', nil + room0 = EvenDoors::Room.new 'room0', @spin door0 = EvenDoors::Door.new 'door0', room0 - p = EvenDoors::Spin.require_p EvenDoors::Particle + p = @spin.require_p EvenDoors::Particle p.src = door0 p.set_dst! 'get' room0.send_p p @@ -162,22 +163,22 @@ describe EvenDoors::Room do end # it "routing success: unconditional link" do - room0 = EvenDoors::Room.new 'room0', nil + room0 = EvenDoors::Room.new 'room0', @spin door0 = EvenDoors::Door.new 'door0', room0 door1 = EvenDoors::Door.new 'door1', room0 room0.add_link EvenDoors::Link.new('door0', 'door1') - p = EvenDoors::Spin.require_p EvenDoors::Particle + p = @spin.require_p EvenDoors::Particle door0.send_p p p.action.should be_nil p.dst.should be door1 end # it "routing success: conditional link" do - room0 = EvenDoors::Room.new 'room0', nil + room0 = EvenDoors::Room.new 'room0', @spin door0 = EvenDoors::Door.new 'door0', room0 door1 = EvenDoors::Door.new 'door1', room0 room0.add_link EvenDoors::Link.new('door0', 'door1', 'fields', 'f0,f1', 'v0v1') - p = EvenDoors::Spin.require_p EvenDoors::Particle + p = @spin.require_p EvenDoors::Particle p['f0']='v0' p['f1']='v1' door0.send_p p @@ -187,7 +188,7 @@ describe EvenDoors::Room do end # it "routing success: more then one matching link" do - room0 = EvenDoors::Room.new 'room0', nil + room0 = EvenDoors::Room.new 'room0', @spin door0 = EvenDoors::Door.new 'door0', room0 class Out < EvenDoors::Door attr_reader :ps @@ -199,13 +200,11 @@ describe EvenDoors::Room do door1 = Out.new 'door1', room0 room0.add_link EvenDoors::Link.new('door0', 'door1') room0.add_link EvenDoors::Link.new('door0', 'door1', 'fields', 'f0,f1', 'v0v1') - p = EvenDoors::Spin.require_p EvenDoors::Particle - EvenDoors::Spin.clear! + p = @spin.require_p EvenDoors::Particle p['f0']='v0' p['f1']='v1' door0.send_p p - EvenDoors::Spin.run = true - EvenDoors::Spin.spin! + @spin.spin! door1.ps.length.should eql 2 p0 = door1.ps[0] p0.action.should be_nil @@ -219,16 +218,16 @@ describe EvenDoors::Room do end # it "system route error: system no destination" do - room0 = EvenDoors::Room.new 'room0', nil - p = EvenDoors::Spin.require_p EvenDoors::Particle + room0 = EvenDoors::Room.new 'room0', @spin + p = @spin.require_p EvenDoors::Particle room0.send_sys_p p p.action.should eql EvenDoors::ACT_ERROR p[EvenDoors::ERROR_FIELD].should eql EvenDoors::ERROR_ROUTE_SND end # it "system routing success: action only" do - room0 = EvenDoors::Room.new 'room0', nil - p = EvenDoors::Spin.require_p EvenDoors::Particle + room0 = EvenDoors::Room.new 'room0', @spin + p = @spin.require_p EvenDoors::Particle p.set_dst! EvenDoors::SYS_ACT_ADD_LINK room0.send_sys_p p p.action.should eql EvenDoors::SYS_ACT_ADD_LINK @@ -236,21 +235,20 @@ describe EvenDoors::Room do end # it "system routing success" do - room0 = EvenDoors::Room.new 'room0', nil + room0 = EvenDoors::Room.new 'room0', @spin door0 = EvenDoors::Door.new 'door0', room0 - p = EvenDoors::Spin.require_p EvenDoors::Particle - p.set_dst! EvenDoors::SYS_ACT_ADD_LINK, 'room0/door0' + p = @spin.require_p EvenDoors::Particle + p.set_dst! EvenDoors::SYS_ACT_ADD_LINK, 'dom0/room0/door0' room0.send_sys_p p p.action.should eql EvenDoors::SYS_ACT_ADD_LINK p.dst.should be door0 end # it "SYS_ACT_ADD_LINK" do - spin = EvenDoors::Spin.new 'dom0' # needed to be able to route to door - room0 = EvenDoors::Room.new 'room0', spin + room0 = EvenDoors::Room.new 'room0', @spin door0 = EvenDoors::Door.new 'door0', room0 door1 = EvenDoors::Door.new 'door1', room0 - p0 = EvenDoors::Spin.require_p EvenDoors::Particle + p0 = @spin.require_p EvenDoors::Particle p0.set_data EvenDoors::LNK_SRC, 'door0' p0.set_data EvenDoors::LNK_DSTS, 'door1' p0.set_data EvenDoors::LNK_FIELDS, 'fields' @@ -258,8 +256,8 @@ describe EvenDoors::Room do p0.set_data EvenDoors::LNK_CONDV, 'v0v1' p0.set_dst! EvenDoors::SYS_ACT_ADD_LINK, room0.path room0.send_sys_p p0 - spin.spin! - p = EvenDoors::Spin.require_p EvenDoors::Particle + @spin.spin! + p = @spin.require_p EvenDoors::Particle p['f0']='v0' p['f1']='v1' door0.send_p p @@ -269,7 +267,7 @@ describe EvenDoors::Room do end # it "room->json->room" do - r0 = EvenDoors::Room.new 'r0' + r0 = EvenDoors::Room.new 'r0', @spin r1 = EvenDoors::Room.new 'r1', r0 r2 = EvenDoors::Room.new 'r2', r1 r3 = EvenDoors::Room.new 'r3', r1 |