vision_mate 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8862e4a3e6fc5d74ed601f4cd4a084b4d49bd684
4
- data.tar.gz: be967aa4c5c8319bdfd85a1e91c9533579ee8fa8
3
+ metadata.gz: 5f81c4d5d557338d38d6884e03ac5a3d1b55d3e3
4
+ data.tar.gz: f23712ebbdf2179d3ec404a33710a0a534acf476
5
5
  SHA512:
6
- metadata.gz: 1044d370cdaf50827df903e04a806e4e0b4e6a6542534adf73780e06a56704cea10770cf54302a5b53a666364a6a5e8e0f1fd52663c5fe9466c04d4a1bf33492
7
- data.tar.gz: e790bffc421236831a23a8508997e3461df7580056fa5200fbc0d191f944f8959adaaa6fe02cc6d4d50e96e96236033db3e98d02a51c5a85991ecb68688854cb
6
+ metadata.gz: 32ae55647d4b839b112b7101c055642235e2ce7e2c3158b47402f205b248a66677cf1d0f1e7cd431b401696474491a2a321155b7928703764258d82be9cafa6e
7
+ data.tar.gz: 6cb1fb5ab28c3537035d3916469bd7fdf37d53b277b3f17c619a965e3b0d149057f1daf0a63515fb131335c3c23efa652407f713d30f48256a3c106e5085a181
@@ -9,11 +9,10 @@ module VisionMate
9
9
 
10
10
  # For ruby 1.9 compatibility
11
11
  class Net::OpenTimeout; end
12
+ class Net::ReadTimeout; end
12
13
 
13
14
  def self.connect(host, port, telnet_class = Net::Telnet)
14
- @telnet_connection ||= telnet_class.new(
15
- "Host" => host, "Port" => port, "Timeout" => Configuration.timeout
16
- )
15
+ @telnet_connection ||= verified_connection host, port, telnet_class
17
16
  new(@telnet_connection)
18
17
  rescue Net::OpenTimeout, Timeout::Error
19
18
  raise CouldNotConnect, "Failed to connect to #{host}:#{port}"
@@ -21,6 +20,20 @@ module VisionMate
21
20
  raise BadHostNameOrPort, "Malformed host name or port"
22
21
  end
23
22
 
23
+ def self.verified_connection(host, port, telnet_class)
24
+ telnet_connection = telnet_class.new(
25
+ "Host" => host, "Port" => port, "Timeout" => Configuration.timeout
26
+ )
27
+ telnet_connection.cmd("String" => "L", "Match" => /OK/)
28
+
29
+ telnet_connection
30
+ rescue Net::OpenTimeout, Timeout::Error => e
31
+ retries ||= 0
32
+ raise e if retries == 5
33
+ retries += 1
34
+ retry
35
+ end
36
+
24
37
  def initialize(telnet_connection)
25
38
  self.telnet_connection = telnet_connection
26
39
  set_scanner_to_manual
@@ -1,3 +1,3 @@
1
1
  module VisionMate
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -9,6 +9,23 @@ describe VisionMate::Telnet do
9
9
  let(:telnet_connection) { double "telnet_connection" }
10
10
  before { VisionMate::Telnet.instance_variable_set(:@telnet_connection, nil) }
11
11
 
12
+ describe ".verified_connection" do
13
+ context "ruby 1.9.X conneciton will often fail to get scanner status" do
14
+ it "recreates the connection if the connection fails" do
15
+ telnet_connection.stub(:cmd).with(hash_including("String" => "L"))
16
+ .and_raise(Timeout::Error.new("Telnet connection failed on status"))
17
+
18
+ MockTelnet.should_receive(:new)
19
+ .with(hash_including("Host" => uri.host, "Port" => uri.port))
20
+ .at_least(:twice).and_return(telnet_connection)
21
+
22
+ expect {
23
+ VisionMate::Telnet.verified_connection(uri.host, uri.port, MockTelnet)
24
+ }.to raise_error(Timeout::Error)
25
+ end
26
+ end
27
+ end
28
+
12
29
  describe ".connect" do
13
30
  it "connects to telnet using a host and port" do
14
31
  MockTelnet.should_receive(:new)
@@ -34,6 +51,9 @@ describe VisionMate::Telnet do
34
51
 
35
52
  it "sets the scanner to manual" do
36
53
  MockTelnet.stub(new: telnet_connection)
54
+ telnet_connection.should_receive(:cmd).with(
55
+ "String" => "L", "Match" => /OK/
56
+ )
37
57
  telnet_connection.should_receive(:cmd).with(
38
58
  "String" => "M0", "Match" => /OK/
39
59
  )
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vision_mate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Jackson