spec/interfaces/udp_interface_spec.rb in cosmos-3.2.1 vs spec/interfaces/udp_interface_spec.rb in cosmos-3.3.0

- old
+ new

@@ -13,162 +13,162 @@ module Cosmos describe UdpInterface do describe "initialize" do - it "should initialize the instance variables" do + it "initializes the instance variables" do i = UdpInterface.new('localhost','8888','8889','8890','127.0.0.1','64','5','5') end - it "should not be writeable if no write port given" do + it "is not writeable if no write port given" do i = UdpInterface.new('localhost','nil','8889') - i.name.should eql "Cosmos::UdpInterface" - i.write_allowed?.should be_falsey - i.write_raw_allowed?.should be_falsey - i.read_allowed?.should be_truthy + expect(i.name).to eql "Cosmos::UdpInterface" + expect(i.write_allowed?).to be_falsey + expect(i.write_raw_allowed?).to be_falsey + expect(i.read_allowed?).to be_truthy end - it "should not be readable if no read port given" do + it "is not readable if no read port given" do i = UdpInterface.new('localhost','8888','nil') - i.name.should eql "Cosmos::UdpInterface" - i.write_allowed?.should be_truthy - i.write_raw_allowed?.should be_truthy - i.read_allowed?.should be_falsey + expect(i.name).to eql "Cosmos::UdpInterface" + expect(i.write_allowed?).to be_truthy + expect(i.write_raw_allowed?).to be_truthy + expect(i.read_allowed?).to be_falsey end end describe "connect, connected?, disconnect" do - it "should create a UdpWriteSocket and UdpReadSocket if both given" do + it "creates a UdpWriteSocket and UdpReadSocket if both given" do write = double("write") expect(write).to receive(:closed?).and_return(false) expect(write).to receive(:close) read = double("read") expect(read).to receive(:closed?).and_return(false) expect(read).to receive(:close) expect(UdpWriteSocket).to receive(:new).and_return(write) expect(UdpReadSocket).to receive(:new).and_return(read) i = UdpInterface.new('localhost','8888','8889') - i.connected?.should be_falsey + expect(i.connected?).to be_falsey i.connect - i.connected?.should be_truthy + expect(i.connected?).to be_truthy i.disconnect - i.connected?.should be_falsey + expect(i.connected?).to be_falsey end - it "should create a UdpWriteSocket if write port given" do + it "creates a UdpWriteSocket if write port given" do write = double("write") expect(write).to receive(:closed?).and_return(false) expect(write).to receive(:close) expect(UdpWriteSocket).to receive(:new).and_return(write) expect(UdpReadSocket).to_not receive(:new) i = UdpInterface.new('localhost','8888','nil') - i.connected?.should be_falsey + expect(i.connected?).to be_falsey i.connect - i.connected?.should be_truthy + expect(i.connected?).to be_truthy i.disconnect - i.connected?.should be_falsey + expect(i.connected?).to be_falsey end - it "should create a UdpReadSocket if read port given" do + it "creates a UdpReadSocket if read port given" do read = double("read") expect(read).to receive(:closed?).and_return(false) expect(read).to receive(:close) expect(UdpWriteSocket).to_not receive(:new) expect(UdpReadSocket).to receive(:new).and_return(read) i = UdpInterface.new('localhost','nil','8889') - i.connected?.should be_falsey + expect(i.connected?).to be_falsey i.connect - i.connected?.should be_truthy + expect(i.connected?).to be_truthy i.disconnect - i.connected?.should be_falsey + expect(i.connected?).to be_falsey end end describe "disconnect" do - it "should rescue IOError from close" do + it "rescues IOError from close" do write = double("write") expect(write).to receive(:closed?).and_return(false) expect(write).to receive(:close).and_raise(IOError) read = double("read") expect(read).to receive(:closed?).and_return(false) expect(read).to receive(:close).and_raise(IOError) expect(UdpWriteSocket).to receive(:new).and_return(write) expect(UdpReadSocket).to receive(:new).and_return(read) i = UdpInterface.new('localhost','8888','8889') - i.connected?.should be_falsey + expect(i.connected?).to be_falsey i.connect - i.connected?.should be_truthy + expect(i.connected?).to be_truthy i.disconnect - i.connected?.should be_falsey + expect(i.connected?).to be_falsey end end describe "read" do - it "should stop the read thread if no read port given" do + it "stops the read thread if no read port given" do i = UdpInterface.new('localhost','8888','nil') thread = Thread.new { i.read } sleep 0.1 - thread.stop?.should be_truthy + expect(thread.stop?).to be_truthy Cosmos.kill_thread(nil, thread) end - it "should stop the read thread if there is an IOError" do + it "stops the read thread if there is an IOError" do read = double("read") allow(read).to receive(:read).and_raise(IOError) expect(UdpReadSocket).to receive(:new).and_return(read) i = UdpInterface.new('localhost','nil','8889') i.connect thread = Thread.new { i.read } sleep 0.1 - thread.stop?.should be_truthy + expect(thread.stop?).to be_truthy Cosmos.kill_thread(nil, thread) end - it "should count the packets received" do + it "counts the packets received" do read = double("read") allow(read).to receive(:read) { "\x00\x01\x02\x03" } expect(UdpReadSocket).to receive(:new).and_return(read) i = UdpInterface.new('localhost','nil','8889') i.connect - i.read_count.should eql 0 - i.bytes_read.should eql 0 + expect(i.read_count).to eql 0 + expect(i.bytes_read).to eql 0 i.read - i.read_count.should eql 1 - i.bytes_read.should eql 4 + expect(i.read_count).to eql 1 + expect(i.bytes_read).to eql 4 i.read - i.read_count.should eql 2 - i.bytes_read.should eql 8 + expect(i.read_count).to eql 2 + expect(i.bytes_read).to eql 8 end end describe "write, write_raw" do - it "should complain if write_dest not given" do + it "complains if write_dest not given" do i = UdpInterface.new('localhost','nil','8889') expect { i.write(Packet.new('','')) }.to raise_error(/read only/) expect { i.write_raw('') }.to raise_error(/read only/) end - it "should complain if the server is not connected" do + it "complains if the server is not connected" do i = UdpInterface.new('localhost','8888','nil') expect { i.write(Packet.new('','')) }.to raise_error(/Interface not connected/) expect { i.write_raw('') }.to raise_error(/Interface not connected/) end - it "should count the packets written" do + it "counts the packets written" do write = double("write") expect(UdpWriteSocket).to receive(:new).and_return(write) allow(write).to receive(:write) i = UdpInterface.new('localhost','8888','nil') i.connect - i.write_count.should eql 0 + expect(i.write_count).to eql 0 pkt = Packet.new('tgt','pkt') pkt.buffer = "\x00\x01\x02\x03" i.write(pkt) - i.write_count.should eql 1 - i.bytes_written.should eql 4 + expect(i.write_count).to eql 1 + expect(i.bytes_written).to eql 4 i.write_raw(pkt.buffer) - i.write_count.should eql 2 - i.bytes_written.should eql 8 + expect(i.write_count).to eql 2 + expect(i.bytes_written).to eql 8 end end end end