diff --git a/lib/apex/igate_tcp.rb b/lib/apex/igate_tcp.rb index 3ccaeabc5647d27fc1c1608e93d569157eb9aba3..321787273a52128ddb1f3270ffae765f7c6cdeef 100644 --- a/lib/apex/igate_tcp.rb +++ b/lib/apex/igate_tcp.rb @@ -132,8 +132,8 @@ module Apex unless read_line.nil? @data_buffer << read_line end - ## TODO: Remove line below, only temporarly used to test - #read_more = false if @data_buffer.include? "\r\n" + ## Lets not read in more than one frame at a time so we dont get stuck in a loop + read_more = false if @data_buffer.include? "\r\n" rescue IO::WaitReadable read_more = false end diff --git a/spec/apex/igate_tcp_spec.rb b/spec/apex/igate_tcp_spec.rb index 2477cf6da0b573dceeb915a7e17601adf507ff8d..342b673bd4e7a400a7ab3ea0083b75f91ce71f4a 100644 --- a/spec/apex/igate_tcp_spec.rb +++ b/spec/apex/igate_tcp_spec.rb @@ -13,7 +13,7 @@ ENCODED_FRAME_IGATE = "W2GMD-1>OMG,WIDE1-1,WIDE2-2:test_encode_frame" describe Apex::IGateTcp do let(:aprsis_socket) { double("aprsis_socket") } let(:igate_tcp) {Apex::IGateTcp.new("WI2ARD")} - + describe ".connect" do context "When attempting to connect to an igate" do it "The correct login message is sent" do @@ -22,17 +22,17 @@ describe Apex::IGateTcp do end end end - # describe ".read" do - # context "Given a valid frame on the igate" do - # it "decodes a frame from the stream" do - # allow(aprsis_socket).to receive(:puts) - # igate_tcp.connect(aprsis_socket_override: aprsis_socket) - # - # expect(aprsis_socket).to receive(:read_nonblock).and_return(ENCODED_FRAME_IGATE + "\r\n").and_raise(IO::WaitReadable) - # expect(igate_tcp.read()).to eql(DECODED_FRAME_IGATE) - # end - # end - # end + describe ".read" do + context "Given a valid frame on the igate" do + it "decodes a frame from the stream" do + allow(aprsis_socket).to receive(:puts) + igate_tcp.connect(aprsis_socket_override: aprsis_socket) + + expect(aprsis_socket).to receive(:read_nonblock).and_return(ENCODED_FRAME_IGATE + "\r\n") + expect(igate_tcp.read()).to eql(DECODED_FRAME_IGATE) + end + end + end describe ".write" do context "Given a a valid Frame" do it "correctly encodes and sends the frame" do