diff options
author | Jérémy Zurcher <jeremy.zurcher@heraeus.com> | 2015-01-12 10:13:58 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy.zurcher@heraeus.com> | 2015-01-12 10:13:58 +0100 |
commit | 4f065f63125907b3a4f72fbab8722c58ccab41c1 (patch) | |
tree | 3add5b782e0c86ffcf61d1b4e4dae769b7aa89c4 /spec/particle_spec.rb | |
parent | 6b69e8e7806ade8fc36505f9ca358edd1572acef (diff) | |
download | edoors-ruby-master.zip edoors-ruby-master.tar.gz |
Diffstat (limited to 'spec/particle_spec.rb')
-rw-r--r-- | spec/particle_spec.rb | 254 |
1 files changed, 127 insertions, 127 deletions
diff --git a/spec/particle_spec.rb b/spec/particle_spec.rb index 862ad14..58437f3 100644 --- a/spec/particle_spec.rb +++ b/spec/particle_spec.rb @@ -10,14 +10,14 @@ describe Edoors::Particle do p = Edoors::Particle.new # p['key']=666 - p['key'].should eql 666 - p.data('key').should eql 666 - p.get_data('key').should eql 666 + expect(p['key']).to eql 666 + expect(p.data('key')).to eql 666 + expect(p.get_data('key')).to eql 666 # p.set_data 'key', 69 - p['key'].should eql 69 - p.data('key').should eql 69 - p.get_data('key').should eql 69 + expect(p['key']).to eql 69 + expect(p.data('key')).to eql 69 + expect(p.get_data('key')).to eql 69 end # it "payload clone" do @@ -27,14 +27,14 @@ describe Edoors::Particle do o = Edoors::Particle.new o.clone_data p p['k00']=nil - p['k00'].should be_nil - o['k00']['k0'].should eql 0 - o['k00']['k1'].should eql 1 + expect(p['k00']).to be_nil + expect(o['k00']['k0']).to eql 0 + expect(o['k00']['k1']).to eql 1 p['k11']=nil - p['k11'].should be_nil - o['k11'][0].should eql 1 - o['k11'][1].should eql 2 - o['k11'][2].should eql 3 + expect(p['k11']).to be_nil + expect(o['k11'][0]).to eql 1 + expect(o['k11'][1]).to eql 2 + expect(o['k11'][2]).to eql 3 end # it "particle merge" do @@ -44,84 +44,84 @@ describe Edoors::Particle do o = Edoors::Particle.new p.merge! q p.merge! o - p.merged(0).should be q - p.merged(1).should be o - p.merged(2).should be_nil + expect(p.merged(0)).to be q + expect(p.merged(1)).to be o + expect(p.merged(2)).to be_nil c = 0 p.each_merged do |o| - o.should be p.merged(c) + expect(o).to be p.merged(c) c+=1 end - c.should be 2 - p.merged_length.should be 2 - p.merged_shift.should be q - p.merged(0).should be o - p.merged(1).should be_nil + expect(c).to be 2 + expect(p.merged_length).to be 2 + expect(p.merged_shift).to be q + expect(p.merged(0)).to be o + expect(p.merged(1)).to be_nil c = 0 p.each_merged do |o| - o.should be p.merged(c) + expect(o).to be p.merged(c) c+=1 end - c.should be 1 - p.merged_length.should be 1 - p.merged_shift.should be o - p.merged(0).should be_nil + expect(c).to be 1 + expect(p.merged_length).to be 1 + expect(p.merged_shift).to be o + expect(p.merged(0)).to be_nil c = 0 p.each_merged do |o| - o.should be p.merged(c) + expect(o).to be p.merged(c) c+=1 end - c.should be 0 - p.merged_length.should be 0 + expect(c).to be 0 + expect(p.merged_length).to be 0 p.merge! q p.merge! o - p.merged(0).should be q - p.merged(1).should be o + expect(p.merged(0)).to be q + expect(p.merged(1)).to be o p.clear_merged! - p.merged(0).should be_nil + expect(p.merged(0)).to be_nil p.merge! q p.merge! o - p.merged(0).should be q - p.merged(1).should be o + expect(p.merged(0)).to be q + expect(p.merged(1)).to be o p.clear_merged! spin - p.merged(0).should be_nil - spin.require_p(Edoors::Particle).should be o - spin.require_p(Edoors::Particle).should be q + expect(p.merged(0)).to be_nil + expect(spin.require_p(Edoors::Particle)).to be o + expect(spin.require_p(Edoors::Particle)).to be q end # it "routing: add_dsts, next_dst and dst_routed!" do p = Edoors::Particle.new d0 = Edoors::Door.new 'door0', nil d1 = Edoors::Door.new 'door1', nil - p.dst.should be_nil - p.next_dst.should be_nil + expect(p.dst).to be_nil + expect(p.next_dst).to be_nil p.add_dsts 'some?where', 'room0/room1/door?action', 'room/door', 'door' - p.next_dst.should eql 'some?where' + expect(p.next_dst).to eql 'some?where' p.dst_routed! d0 - p.dst.should be d0 - p.next_dst.should eql 'room0/room1/door?action' + expect(p.dst).to be d0 + expect(p.next_dst).to eql 'room0/room1/door?action' p.dst_routed! d1 - p.dst.should be d1 - p.next_dst.should eql 'room/door' + expect(p.dst).to be d1 + expect(p.next_dst).to eql 'room/door' p.dst_routed! nil - p.dst.should be_nil - p.next_dst.should eql 'door' + expect(p.dst).to be_nil + expect(p.next_dst).to eql 'door' end # it "wrong path should raise exeption" do p = Edoors::Particle.new - lambda { p.add_dst 'action', '/room' }.should raise_error(Edoors::Exception) - lambda { p.add_dst 'action', 'room/' }.should raise_error(Edoors::Exception) - lambda { p.add_dst '', 'room/' }.should raise_error(Edoors::Exception) - lambda { p.add_dst 'action', 'room//door' }.should raise_error(Edoors::Exception) - lambda { p.add_dst ' ' }.should raise_error(Edoors::Exception) - lambda { p.add_dst ' ', '' }.should raise_error(Edoors::Exception) - lambda { p.add_dst 'f f' }.should raise_error(Edoors::Exception) - lambda { p.add_dst '', ' d' }.should raise_error(Edoors::Exception) - lambda { p.add_dst '' }.should raise_error(Edoors::Exception) - lambda { p.add_dst '', '' }.should raise_error(Edoors::Exception) - lambda { p.add_dst nil }.should raise_error(TypeError) - lambda { p.add_dst 'action', nil }.should raise_error(NoMethodError) + expect(lambda { p.add_dst 'action', '/room' }).to raise_error(Edoors::Exception) + expect(lambda { p.add_dst 'action', 'room/' }).to raise_error(Edoors::Exception) + expect(lambda { p.add_dst '', 'room/' }).to raise_error(Edoors::Exception) + expect(lambda { p.add_dst 'action', 'room//door' }).to raise_error(Edoors::Exception) + expect(lambda { p.add_dst ' ' }).to raise_error(Edoors::Exception) + expect(lambda { p.add_dst ' ', '' }).to raise_error(Edoors::Exception) + expect(lambda { p.add_dst 'f f' }).to raise_error(Edoors::Exception) + expect(lambda { p.add_dst '', ' d' }).to raise_error(Edoors::Exception) + expect(lambda { p.add_dst '' }).to raise_error(Edoors::Exception) + expect(lambda { p.add_dst '', '' }).to raise_error(Edoors::Exception) + expect(lambda { p.add_dst nil }).to raise_error(TypeError) + expect(lambda { p.add_dst 'action', nil }).to raise_error(NoMethodError) end # it "routing: set_dst!" do @@ -129,14 +129,14 @@ describe Edoors::Particle do d0 = Edoors::Door.new 'door0', nil # p.set_dst! 'action', d0 - p.action.should eql 'action' - p.dst.should be d0 + expect(p.action).to eql 'action' + expect(p.dst).to be d0 # p.set_dst! 'action', '/world/room/door' - p.action.should eql 'action' - p.dst.should be nil - p.room.should eql '/world/room' - p.door.should eql 'door' + expect(p.action).to eql 'action' + expect(p.dst).to be nil + expect(p.room).to eql '/world/room' + expect(p.door).to eql 'door' end # it "routing: add_dst and split_dst!" do @@ -144,51 +144,51 @@ describe Edoors::Particle do d0 = Edoors::Door.new 'door0', nil # p.split_dst! - p.room.should be_nil - p.door.should be_nil - p.action.should be_nil + expect(p.room).to be_nil + expect(p.door).to be_nil + expect(p.action).to be_nil # p.add_dst 'action', 'room0/room1/door' p.split_dst! - p.room.should eql 'room0/room1' - p.door.should eql 'door' - p.action.should eql 'action' + expect(p.room).to eql 'room0/room1' + expect(p.door).to eql 'door' + expect(p.action).to eql 'action' p.clear_dsts! # p.add_dst 'action', 'room/door' p.split_dst! - p.room.should eql 'room' - p.door.should eql 'door' - p.action.should eql 'action' + expect(p.room).to eql 'room' + expect(p.door).to eql 'door' + expect(p.action).to eql 'action' p.clear_dsts! # p.add_dst 'action', '' p.split_dst! - p.room.should be_nil - p.door.should be_nil - p.action.should eql 'action' + expect(p.room).to be_nil + expect(p.door).to be_nil + expect(p.action).to eql 'action' p.clear_dsts! # p.add_dst 'action' p.split_dst! - p.room.should be_nil - p.door.should be_nil - p.action.should eql 'action' + expect(p.room).to be_nil + expect(p.door).to be_nil + expect(p.action).to eql 'action' p.clear_dsts! # p.add_dsts 'door?action', '?action' p.split_dst! - p.room.should be_nil - p.door.should eql 'door' - p.action.should eql 'action' + expect(p.room).to be_nil + expect(p.door).to eql 'door' + expect(p.action).to eql 'action' # p.dst_routed! d0 # - p.dst.should be d0 + expect(p.dst).to be d0 p.split_dst! - p.room.should be_nil - p.door.should be_nil - p.action.should eql 'action' + expect(p.room).to be_nil + expect(p.door).to be_nil + expect(p.action).to eql 'action' # end # @@ -197,11 +197,11 @@ describe Edoors::Particle do d = Edoors::Door.new 'door', nil p.init! d p.add_dsts 'door?action', '?action' - p.next_dst.should eql 'door?action' + expect(p.next_dst).to eql 'door?action' p.error! 'err_msg' - p[Edoors::FIELD_ERROR_MSG].should eql 'err_msg' - p.action.should eq Edoors::ACT_ERROR - p.dst.should be d + expect(p[Edoors::FIELD_ERROR_MSG]).to eql 'err_msg' + expect(p.action).to eq Edoors::ACT_ERROR + expect(p.dst).to be d end # it "link keys and link values" do @@ -211,13 +211,13 @@ describe Edoors::Particle do p['k2'] = 'v2' p['k3'] = 'v3' p.set_link_keys 'k0', 'k2', 'k1' - p.link_value.should == {'k0'=>'v0','k1'=>'v1','k2'=>'v2'} + expect(p.link_value).to be == {'k0'=>'v0','k1'=>'v1','k2'=>'v2'} p.del_data 'k0' - p.link_value.should == {'k1'=>'v1','k2'=>'v2'} + expect(p.link_value).to be == {'k1'=>'v1','k2'=>'v2'} p.set_link_keys 'k1', 'k0' - p.link_value.should == {'k1'=>'v1'} + expect(p.link_value).to be == {'k1'=>'v1'} p['k1']='vX' - p.link_value.should == {'k1'=>'vX'} + expect(p.link_value).to be == {'k1'=>'vX'} end # it 'link_with?' do @@ -225,9 +225,9 @@ describe Edoors::Particle do p['k0'] = 'v0' p['k1'] = 'v1' p['k2'] = 'v2' - p.link_with?(Edoors::Link.new('', '', '')).should be_true - p.link_with?(Edoors::Link.new('', '', '', {'k0'=>'v0','k1'=>'v1'})).should be_true - p.link_with?(Edoors::Link.new('', '', '', {'k0'=>'v2','k1'=>'v1'})).should be_false + expect(p.link_with?(Edoors::Link.new('', '', ''))).to be_truthy + expect(p.link_with?(Edoors::Link.new('', '', '', {'k0'=>'v0','k1'=>'v1'}))).to be_truthy + expect(p.link_with?(Edoors::Link.new('', '', '', {'k0'=>'v2','k1'=>'v1'}))).to be_falsy end # it "apply_link!" do @@ -237,16 +237,16 @@ describe Edoors::Particle do p['k2'] = 'v2' p.set_link_keys 'k0', 'k2' p.add_dsts 'door?action', '?action' - p.src.should be_nil - p.link_value.should == {'k0'=>'v0','k2'=>'v2'} - p.next_dst.should eql 'door?action' + expect(p.src).to be_nil + expect(p.link_value).to be == {'k0'=>'v0','k2'=>'v2'} + expect(p.next_dst).to eql 'door?action' lnk = Edoors::Link.new('door0', ['door1?get','door2'], 'k1', {'f0'=>'v0','f1'=>'v1'}) f = Fake.new 'fake', nil lnk.door = f p.apply_link! lnk - p.src.should be f - p.next_dst.should eql 'door1?get' - p.link_value.should == {'k1'=>'v1'} + expect(p.src).to be f + expect(p.next_dst).to eql 'door1?get' + expect(p.link_value).to be == {'k1'=>'v1'} end # it "particle->json->particle" do @@ -275,30 +275,30 @@ describe Edoors::Particle do o = JSON.load( JSON.generate(p0) ) o['spin'] = s0 px = Edoors::Particle.json_create( o ) - ((px.ts-p0.ts)<0.5).should be_true - px.src.should be s3 - px.dst.should be_nil - px.room.should eql 'room0/room1/room2' - px.door.should eql 'doorX' - px.action.should eql 'myaction' - px.next_dst.should eql 'room0/room1/room2/doorX?myaction' - px.link_value.should == {'k0'=>'v0','k2'=>'v2'} - px['k0'].should eql 'v0' - px['k1'].should eql 'v1' - px['k2'].should eql 'v2' + expect(((px.ts-p0.ts)<0.5)).to be_truthy + expect(px.src).to be s3 + expect(px.dst).to be_nil + expect(px.room).to eql 'room0/room1/room2' + expect(px.door).to eql 'doorX' + expect(px.action).to eql 'myaction' + expect(px.next_dst).to eql 'room0/room1/room2/doorX?myaction' + expect(px.link_value).to be == {'k0'=>'v0','k2'=>'v2'} + expect(px['k0']).to eql 'v0' + expect(px['k1']).to eql 'v1' + expect(px['k2']).to eql 'v2' py = px.merged(0) - ((py.ts-p1.ts)<0.5).should be_true - py.src.should be s3 - py.dst.should be s4 - py.room.should be_nil - py.door.should be_nil - py.action.should be_nil - py.next_dst.should eql 'room0/room1/door?action' - py.link_value.should == {'k3'=>'v6','k4'=>'v7','k5'=>'v8'} - py['k3'].should eql 'v6' - py['k4'].should eql 'v7' - py['k5'].should eql 'v8' - JSON.generate(p0).should eql JSON.generate(px) + expect(((py.ts-p1.ts)<0.5)).to be_truthy + expect(py.src).to be s3 + expect(py.dst).to be s4 + expect(py.room).to be_nil + expect(py.door).to be_nil + expect(py.action).to be_nil + expect(py.next_dst).to eql 'room0/room1/door?action' + expect(py.link_value).to be == {'k3'=>'v6','k4'=>'v7','k5'=>'v8'} + expect(py['k3']).to eql 'v6' + expect(py['k4']).to eql 'v7' + expect(py['k5']).to eql 'v8' + expect(JSON.generate(p0)).to eql JSON.generate(px) end # end |