From bc08d80e50cfcd4805f529901c370856950fc5e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 9 May 2012 11:21:32 +0200 Subject: specs: increase Room coverage with #try_links --- spec/evendoors_spec.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/spec/evendoors_spec.rb b/spec/evendoors_spec.rb index 37a49f2..4fe107c 100644 --- a/spec/evendoors_spec.rb +++ b/spec/evendoors_spec.rb @@ -589,6 +589,62 @@ describe EvenDoors do p.dst.should be door0 end # + it "routing success: unconditional link" do + room0 = EvenDoors::Room.new 'room0', nil + door0 = EvenDoors::Door.new 'door0', room0 + door1 = EvenDoors::Door.new 'door1', room0 + room0.add_link EvenDoors::Link.new('door0', 'door1') + p = EvenDoors::Twirl.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 + 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::Twirl.require_p EvenDoors::Particle + p['f0']='v0' + p['f1']='v1' + door0.send_p p + p.action.should be_nil + p.src.should be door0 + p.dst.should be door1 + end + # + it "routing success: more then one matching link" do + room0 = EvenDoors::Room.new 'room0', nil + door0 = EvenDoors::Door.new 'door0', room0 + class Out < EvenDoors::Door + attr_reader :ps + def receive_p p + @ps||=[] + @ps << p + end + end + 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::Twirl.require_p EvenDoors::Particle + EvenDoors::Twirl.clear! + p['f0']='v0' + p['f1']='v1' + door0.send_p p + EvenDoors::Twirl.run = true + EvenDoors::Twirl.twirl! + door1.ps.length.should eql 2 + p0 = door1.ps[0] + p0.action.should be_nil + p0.src.should be door0 + p0.dst.should be door1 + p1 = door1.ps[1] + p1.action.should be_nil + p1.src.should be door0 + p1.dst.should be door1 + p1.should be p + end # end end -- cgit v1.1-2-g2b99