summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-05-11 09:32:47 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2012-05-12 09:38:00 +0200
commitbbccc8d8c1a06d3a47686e5f01430b321a319ab9 (patch)
tree214382a39cdbf2cc6169c550fbaf3774e3d84b43
parentc57ae27428b28db3d5972147ba914434b8b72d30 (diff)
downloadedoors-ruby-bbccc8d8c1a06d3a47686e5f01430b321a319ab9.zip
edoors-ruby-bbccc8d8c1a06d3a47686e5f01430b321a319ab9.tar.gz
specs: adapt to new spin topology
-rw-r--r--spec/spin_spec.rb92
1 files changed, 50 insertions, 42 deletions
diff --git a/spec/spin_spec.rb b/spec/spin_spec.rb
index 7e171a5..707ded3 100644
--- a/spec/spin_spec.rb
+++ b/spec/spin_spec.rb
@@ -6,71 +6,80 @@ require 'spec_helper'
#
describe EvenDoors::Spin do
#
- before(:each) do
- EvenDoors::Spin.clear!
- end
- #
class MyP < EvenDoors::Particle; end
#
it "Particles pool" do
- p0 = EvenDoors::Spin.require_p EvenDoors::Particle
- p1 = EvenDoors::Spin.require_p EvenDoors::Particle
+ spin = EvenDoors::Spin.new 'dom0'
+ p0 = spin.require_p EvenDoors::Particle
+ p1 = spin.require_p EvenDoors::Particle
(p0===p1).should be_false
- EvenDoors::Spin.release_p p0
- p2 = EvenDoors::Spin.require_p EvenDoors::Particle
+ spin.release_p p0
+ p2 = spin.require_p EvenDoors::Particle
(p0===p2).should be_true
end
#
it "different Particles classes in pool" do
- p0 = EvenDoors::Spin.require_p EvenDoors::Particle
- p1 = EvenDoors::Spin.require_p EvenDoors::Particle
+ spin = EvenDoors::Spin.new 'dom0'
+ p0 = spin.require_p EvenDoors::Particle
+ p1 = spin.require_p EvenDoors::Particle
(p0===p1).should be_false
- EvenDoors::Spin.release_p p0
- p2 = EvenDoors::Spin.require_p MyP
- p3 = EvenDoors::Spin.require_p MyP
+ spin.release_p p0
+ p2 = spin.require_p MyP
+ p3 = spin.require_p MyP
(p2===p3).should be_false
- EvenDoors::Spin.release_p p2
- p4 = EvenDoors::Spin.require_p MyP
+ spin.release_p p2
+ p4 = spin.require_p MyP
(p2===p4).should be_true
end
#
it "release of merged particles" do
- p0 = EvenDoors::Spin.require_p EvenDoors::Particle
- p1 = EvenDoors::Spin.require_p EvenDoors::Particle
+ spin = EvenDoors::Spin.new 'dom0'
+ p0 = spin.require_p EvenDoors::Particle
+ p1 = spin.require_p EvenDoors::Particle
(p0===p1).should be_false
p0.merge! p1
- EvenDoors::Spin.release_p p0
- p2 = EvenDoors::Spin.require_p EvenDoors::Particle
+ spin.release_p p0
+ p2 = spin.require_p EvenDoors::Particle
(p2===p0).should be_true
- p3 = EvenDoors::Spin.require_p EvenDoors::Particle
+ p3 = spin.require_p EvenDoors::Particle
(p3===p1).should be_true
end
#
+ it "clear!" do
+ spin = EvenDoors::Spin.new 'dom0'
+ p0 = spin.require_p EvenDoors::Particle
+ p1 = spin.require_p EvenDoors::Particle
+ spin.send_p p0
+ spin.release_p p1
+ spin.clear!
+ p2 = spin.require_p EvenDoors::Particle
+ (p2==p0).should be_false
+ (p2==p1).should be_false
+ end
+ #
it "send_p send_sys_p spin!" do
+ spin = EvenDoors::Spin.new 'dom0'
f = Fake.new
- p0 = EvenDoors::Spin.require_p EvenDoors::Particle
+ p0 = spin.require_p EvenDoors::Particle
p0.dst_routed! f
- p1 = EvenDoors::Spin.require_p EvenDoors::Particle
+ p1 = spin.require_p EvenDoors::Particle
p1.dst_routed! f
- EvenDoors::Spin.send_p p0
- EvenDoors::Spin.send_sys_p p1
- EvenDoors::Spin.run = true
- EvenDoors::Spin.spin!
+ spin.send_p p0
+ spin.send_sys_p p1
+ spin.run = true
+ spin.spin!
f.p.should be p0
f.sp.should be p1
+ spin.stop!
end
#
it "option debug" do
- EvenDoors::Spin.debug_routing.should be false
- EvenDoors::Spin.debug_errors.should be false
+ spin = EvenDoors::Spin.new 'dom0'
+ spin.debug_routing.should be false
+ spin.debug_errors.should be false
spin = EvenDoors::Spin.new 'dom0', :debug_routing=>true, :debug_errors=>true
- EvenDoors::Spin.debug_routing.should be true
- EvenDoors::Spin.debug_errors.should be true
- end
- #
- it "only 1 Spin instance" do
- spin = EvenDoors::Spin.new 'dom0', :debug_routing=>true
- lambda { EvenDoors::Spin.new('dom1') }.should raise_error(EvenDoors::Exception)
+ spin.debug_routing.should be true
+ spin.debug_errors.should be true
end
#
it "spin->json->spin" do
@@ -83,14 +92,13 @@ describe EvenDoors::Spin do
d0 = EvenDoors::Door.new 'd0', r1
d1 = EvenDoors::Door.new 'd1', r1
d2 = EvenDoors::Door.new 'd2', r2
- p0 = EvenDoors::Spin.require_p EvenDoors::Particle
- p1 = EvenDoors::Spin.require_p EvenDoors::Particle
- p2 = EvenDoors::Spin.require_p EvenDoors::Particle
- EvenDoors::Spin.send_p p0
- EvenDoors::Spin.send_p p1
- EvenDoors::Spin.send_sys_p p2
+ p0 = spin.require_p EvenDoors::Particle
+ p1 = spin.require_p EvenDoors::Particle
+ p2 = spin.require_p EvenDoors::Particle
+ spin.send_p p0
+ spin.send_p p1
+ spin.send_sys_p p2
json = JSON.generate spin
- EvenDoors::Spin.clear!
dom0 = EvenDoors::Spin.json_create( JSON.load( json ) )
json.should eql JSON.generate(dom0)
end