build_watcher 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.
- data/History.txt +4 -0
- data/lib/build_watcher.rb +1 -1
- data/lib/build_watcher/zigbee_device.rb +10 -2
- data/spec/update_listeners_cli_spec.rb +14 -11
- metadata +2 -2
data/History.txt
CHANGED
data/lib/build_watcher.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module BuildWatcher
|
2
2
|
class ZigbeeDevice
|
3
|
+
MAX_SERIAL_DEVICE_ATTEMPTS = 5
|
3
4
|
def initialize(device)
|
4
5
|
@device = device
|
5
6
|
@connection = "USE #serial_device INSTEAD OF CONNECTION DIRECTLY"
|
@@ -56,7 +57,6 @@ module BuildWatcher
|
|
56
57
|
raise AppropriateMessageTypeNotFound, "No 'project info' message type found on serial buffer."
|
57
58
|
end
|
58
59
|
|
59
|
-
#Struct.new("ProjectInfo", :public_key, :private_key)
|
60
60
|
Struct::ProjectInfo.new(*project_info.split(/#{Message::MSG_SEP}/).slice(1,3))
|
61
61
|
end
|
62
62
|
|
@@ -71,7 +71,15 @@ module BuildWatcher
|
|
71
71
|
def serial_device(&block)
|
72
72
|
@connection = SerialPort.new(@device, 9600)
|
73
73
|
@connection.read_timeout = -1
|
74
|
-
|
74
|
+
|
75
|
+
i = 1
|
76
|
+
begin
|
77
|
+
yield @connection
|
78
|
+
rescue AppropriateMessageTypeNotFound => e
|
79
|
+
i += 1
|
80
|
+
retry unless i > MAX_SERIAL_DEVICE_ATTEMPTS
|
81
|
+
raise e
|
82
|
+
end
|
75
83
|
ensure
|
76
84
|
@connection.close
|
77
85
|
end
|
@@ -2,14 +2,17 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
require 'update_listeners/cli'
|
3
3
|
|
4
4
|
describe UpdateListeners::CLI, "execute" do
|
5
|
+
def execute_script
|
6
|
+
UpdateListeners::CLI.execute(STDOUT, ['-d', '/dev/some_device'])
|
7
|
+
end
|
8
|
+
|
5
9
|
before(:each) do
|
6
|
-
@
|
7
|
-
@zgb_device = BuildWatcher::ZigbeeDevice.new('/dev/something')
|
10
|
+
@zigbee_device = BuildWatcher::ZigbeeDevice.new('/dev/something')
|
8
11
|
@project = CodeFumes::Project.new(:public_key => 'pub', :private_key => 'priv')
|
9
12
|
@project.stub!(:build_status).and_return("running")
|
10
13
|
|
11
|
-
SerialPort.stub!(:new).and_return(
|
12
|
-
BuildWatcher::ZigbeeDevice.stub!(:new).and_return(@
|
14
|
+
SerialPort.stub!(:new).and_return(FakeSerialPort.new)
|
15
|
+
BuildWatcher::ZigbeeDevice.stub!(:new).and_return(@zigbee_device)
|
13
16
|
CodeFumes::Project.stub!(:find).and_return(@project)
|
14
17
|
end
|
15
18
|
|
@@ -21,25 +24,25 @@ describe UpdateListeners::CLI, "execute" do
|
|
21
24
|
end
|
22
25
|
|
23
26
|
it "requests the quantity of projects from the serial device" do
|
24
|
-
@
|
25
|
-
|
27
|
+
@zigbee_device.should_receive(:project_quantity).and_return(@project_quantity)
|
28
|
+
execute_script
|
26
29
|
end
|
27
30
|
|
28
31
|
it "requests the project information from the serial device for each project" do
|
29
32
|
project_info = OpenStruct.new({:private_key => 'priv', :public_key => 'pub'})
|
30
|
-
@
|
31
|
-
|
33
|
+
@zigbee_device.should_receive(:project_info).exactly(3).times.and_return(project_info)
|
34
|
+
execute_script
|
32
35
|
end
|
33
36
|
|
34
37
|
it "it requests the project build status from CodeFumes for each project" do
|
35
38
|
CodeFumes::Project.should_receive(:find).exactly(@project_quantity).times.and_return(@project)
|
36
39
|
@project.should_receive(:build_status).exactly(@project_quantity).times.and_return('running')
|
37
|
-
|
40
|
+
execute_script
|
38
41
|
end
|
39
42
|
|
40
43
|
it "it broadcasts the status of each project via the serial device" do
|
41
|
-
@
|
42
|
-
|
44
|
+
@zigbee_device.should_receive(:broadcast_status).exactly(@project_quantity).times
|
45
|
+
execute_script
|
43
46
|
end
|
44
47
|
end
|
45
48
|
end
|