blinky 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,27 +2,27 @@ module Blinky
2
2
  module DelcomEngineering
3
3
  module VisualIndicator
4
4
  module GenerationII
5
-
5
+
6
6
  def success!
7
7
  set_colour("\x01")
8
8
  end
9
-
9
+
10
10
  def failure!
11
11
  set_colour("\x02")
12
12
  end
13
-
13
+
14
14
  def building!
15
15
  set_colour("\x04")
16
16
  end
17
-
17
+
18
18
  def warning!
19
19
  set_colour("\x07")
20
20
  end
21
-
21
+
22
22
  def off!
23
23
  set_colour("\x00")
24
24
  end
25
-
25
+
26
26
  private
27
27
  def set_colour colour
28
28
  @handle.usb_control_msg(0x21, 0x09, 0x0635, 0x000, "\x65\x0C#{colour}\xFF\x00\x00\x00\x00", 0)
@@ -2,16 +2,16 @@ require File.join(File.dirname(__FILE__), '/spec_helper')
2
2
 
3
3
  module Blinky
4
4
  describe "Blinky" do
5
-
5
+
6
6
  describe "that has a supported device connected" do
7
-
7
+
8
8
  before(:each) do
9
- @supported_device = OpenStruct.new(:idVendor => 0x2000, :idProduct => 0x2222)
9
+ @supported_device = double("supported device",:idVendor => 0x2000, :idProduct => 0x2222)
10
10
  self.connected_devices = [
11
- OpenStruct.new(:idVendor => 0x1234, :idProduct => 0x5678),
11
+ double("unsupported device A",:idVendor => 0x1234, :idProduct => 0x5678),
12
12
  @supported_device,
13
- OpenStruct.new(:idVendor => 0x5678, :idProduct => 0x1234)
14
- ]
13
+ double("unsupported device B",:idVendor => 0x5678, :idProduct => 0x1234)
14
+ ]
15
15
  @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
16
16
  end
17
17
 
@@ -24,7 +24,7 @@ module Blinky
24
24
  @supported_device.should_receive(:indicate_success)
25
25
  @blinky.light.success!
26
26
  end
27
-
27
+
28
28
  it "can provide a light that can show where it is" do
29
29
  @supported_device.should_receive(:indicate_failure).ordered
30
30
  @supported_device.should_receive(:indicate_success).ordered
@@ -40,111 +40,111 @@ module Blinky
40
40
 
41
41
  @blinky.light.where_are_you?
42
42
  end
43
-
43
+
44
44
  end
45
-
45
+
46
46
  describe "that supports two devices from the same vendor" do
47
-
48
- it "can provide a light that can control the first device" do
49
- supported_device_one = OpenStruct.new(:idVendor => 0x1000, :idProduct => 0x1111)
50
- self.connected_devices = [supported_device_one]
51
- @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
52
- supported_device_one.should_receive(:indicate_success)
53
- @blinky.light.success!
54
- end
55
-
56
- it "can provide a light that can control the second device" do
57
- supported_device_two = OpenStruct.new(:idVendor => 0x1000, :idProduct => 0x2222)
58
- self.connected_devices = [supported_device_two]
59
- @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
60
- supported_device_two.should_receive(:indicate_success)
61
- @blinky.light.success!
62
- end
63
- end
64
-
47
+
48
+ it "can provide a light that can control the first device" do
49
+ supported_device_one = double("supported device one", :idVendor => 0x1000, :idProduct => 0x1111)
50
+ self.connected_devices = [supported_device_one]
51
+ @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
52
+ supported_device_one.should_receive(:indicate_success)
53
+ @blinky.light.success!
54
+ end
55
+
56
+ it "can provide a light that can control the second device" do
57
+ supported_device_two = double("supported device two", :idVendor => 0x1000, :idProduct => 0x2222)
58
+ self.connected_devices = [supported_device_two]
59
+ @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
60
+ supported_device_two.should_receive(:indicate_success)
61
+ @blinky.light.success!
62
+ end
63
+ end
64
+
65
65
  describe "that has no supported devices connected" do
66
66
 
67
67
  before(:each) do
68
68
  @devices = [
69
- OpenStruct.new(:idVendor => 0x1234, :idProduct => 0x5678),
70
- OpenStruct.new(:idVendor => 0x5678, :idProduct => 0x1234)
71
- ]
72
- self.connected_devices= @devices
69
+ double("unsupported device", :idVendor => 0x1234, :idProduct => 0x5678),
70
+ double("unsupported device", :idVendor => 0x5678, :idProduct => 0x1234)
71
+ ]
72
+ self.connected_devices= @devices
73
+ end
74
+
75
+ it "will complain" do
76
+ exception = Exception.new("foo")
77
+ NoSupportedDevicesFound.should_receive(:new).with(@devices).and_return(exception)
78
+ lambda{Blinky.new("#{File.dirname(__FILE__)}/fixtures")}.should raise_error("foo")
79
+ end
80
+
81
+ end
82
+
83
+ describe "that has no supported devices connected - but does have one from the same vendor" do
84
+
85
+ before(:each) do
86
+ @devices = [
87
+ double("unsupported device from known vendor", :idVendor => 0x1000, :idProduct => 0x5678),
88
+ double("unsupported device", :idVendor => 0x5678, :idProduct => 0x1234)
89
+ ]
90
+ self.connected_devices= @devices
73
91
  end
74
-
92
+
75
93
  it "will complain" do
76
94
  exception = Exception.new("foo")
77
95
  NoSupportedDevicesFound.should_receive(:new).with(@devices).and_return(exception)
78
96
  lambda{Blinky.new("#{File.dirname(__FILE__)}/fixtures")}.should raise_error("foo")
79
97
  end
80
-
81
- end
82
-
83
- describe "that has no supported devices connected - but does have one from the same vendor" do
84
-
85
- before(:each) do
86
- @devices = [
87
- OpenStruct.new(:idVendor => 0x1000, :idProduct => 0x5678),
88
- OpenStruct.new(:idVendor => 0x5678, :idProduct => 0x1234)
89
- ]
90
- self.connected_devices= @devices
91
- end
92
-
93
- it "will complain" do
94
- exception = Exception.new("foo")
95
- NoSupportedDevicesFound.should_receive(:new).with(@devices).and_return(exception)
96
- lambda{Blinky.new("#{File.dirname(__FILE__)}/fixtures")}.should raise_error("foo")
97
- end
98
-
99
- end
100
-
101
- describe "that has two supported devices connected" do
102
-
103
- before(:each) do
104
- @supported_device_one = OpenStruct.new(:idVendor => 0x1000, :idProduct => 0x1111)
105
- @supported_device_two = OpenStruct.new(:idVendor => 0x2000, :idProduct => 0x2222)
106
-
107
- self.connected_devices = [
108
- OpenStruct.new(:idVendor => 0x1234, :idProduct => 0x5678),
109
- @supported_device_one,
110
- @supported_device_two
111
- ]
112
- @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
113
- end
114
-
115
- it "will provide two lights" do
116
- @blinky.light.should_not be_nil
117
- @blinky.lights.length.should == 2
118
- end
119
-
120
- it "can provide lights that can control thedevices" do
121
- @supported_device_one.should_receive(:indicate_success)
122
- @supported_device_two.should_receive(:indicate_success)
123
- @blinky.lights[0].success!
124
- @blinky.lights[1].success!
125
- end
126
- end
127
-
128
- describe "that provides a light that is asked to watch a supported CI server" do
129
-
130
- before(:each) do
131
- self.connected_devices = [OpenStruct.new(:idVendor => 0x1000, :idProduct => 0x1111)]
132
- @light = Blinky.new("#{File.dirname(__FILE__)}/fixtures").light
133
- end
134
-
135
- it "can receive call backs from the server" do
136
- @light.should_receive(:notify_build_status)
137
- @light.watch_mock_ci_server
138
- end
139
-
140
- end
141
-
142
- def connected_devices= devices
143
- devices.each do |device|
144
- device.stub!(:usb_open).and_return(device)
145
- end
146
- USB.stub!(:devices).and_return(devices)
147
- end
148
-
149
- end
98
+
99
+ end
100
+
101
+ describe "that has two supported devices connected" do
102
+
103
+ before(:each) do
104
+ @supported_device_one = double("supported device A",:idVendor => 0x1000, :idProduct => 0x1111)
105
+ @supported_device_two = double("supported device B",:idVendor => 0x2000, :idProduct => 0x2222)
106
+
107
+ self.connected_devices = [
108
+ double("unsupported device", :idVendor => 0x1234, :idProduct => 0x5678),
109
+ @supported_device_one,
110
+ @supported_device_two
111
+ ]
112
+ @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
113
+ end
114
+
115
+ it "will provide two lights" do
116
+ @blinky.light.should_not be_nil
117
+ @blinky.lights.length.should == 2
118
+ end
119
+
120
+ it "can provide lights that can control thedevices" do
121
+ @supported_device_one.should_receive(:indicate_success)
122
+ @supported_device_two.should_receive(:indicate_success)
123
+ @blinky.lights[0].success!
124
+ @blinky.lights[1].success!
125
+ end
126
+ end
127
+
128
+ describe "that provides a light that is asked to watch a supported CI server" do
129
+
130
+ before(:each) do
131
+ self.connected_devices = [double("device",:idVendor => 0x1000, :idProduct => 0x1111)]
132
+ @light = Blinky.new("#{File.dirname(__FILE__)}/fixtures").light
133
+ end
134
+
135
+ it "can receive call backs from the server" do
136
+ @light.should_receive(:notify_build_status)
137
+ @light.watch_mock_ci_server
138
+ end
139
+
140
+ end
141
+
142
+ def connected_devices= devices
143
+ devices.each do |device|
144
+ device.stub!(:usb_open).and_return(device)
145
+ end
146
+ USB.stub!(:devices).and_return(devices)
147
+ end
148
+
149
+ end
150
150
  end
data/spec/blinky_spec.rb CHANGED
@@ -4,7 +4,7 @@ Dir["#{File.dirname(__FILE__)}/fixtures/ci_server_plugins/**/*.rb"].each { |f| r
4
4
 
5
5
  module Blinky
6
6
  describe "Blinky" do
7
-
7
+
8
8
  it "will construct a light factory with the available plugins and recipes" do
9
9
  expected_plugins = [MockCiServer]
10
10
  expected_recipes = {
@@ -14,19 +14,19 @@ module Blinky
14
14
  LightFactory.should_receive(:detect_lights).with( expected_plugins, expected_recipes).and_return([])
15
15
  Blinky.new("#{File.dirname(__FILE__)}/fixtures")
16
16
  end
17
-
17
+
18
18
  it "will make lights from the light factory available" do
19
- expected_plugins = [MockCiServer]
20
- expected_recipes = {
21
- 0x1000 => { 0x2222 => AenimaEngineering::ModelEulogy, 0x1111 => AenimaEngineering::Model462 },
22
- 0x2000 => { 0x2222 => FragileEngineering::ModelWretched }
23
- }
24
- lights = ["light one", "light two"]
25
- LightFactory.should_receive(:detect_lights).and_return(lights)
26
- blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
27
-
28
- blinky.lights.should eql lights
29
- blinky.light.should == "light one"
30
- end
19
+ expected_plugins = [MockCiServer]
20
+ expected_recipes = {
21
+ 0x1000 => { 0x2222 => AenimaEngineering::ModelEulogy, 0x1111 => AenimaEngineering::Model462 },
22
+ 0x2000 => { 0x2222 => FragileEngineering::ModelWretched }
23
+ }
24
+ lights = ["light one", "light two"]
25
+ LightFactory.should_receive(:detect_lights).and_return(lights)
26
+ blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
27
+
28
+ blinky.lights.should eql lights
29
+ blinky.light.should == "light one"
30
+ end
31
31
  end
32
32
  end
@@ -1,34 +1,34 @@
1
1
  require File.join(File.dirname(__FILE__), '..', '/spec_helper')
2
2
  require 'ci_server_plugins/test_server_plugin'
3
3
  module Blinky
4
-
5
- class StubBlinky
4
+
5
+ class StubBlinky
6
+ end
7
+
8
+ describe "TestCiServer" do
9
+
10
+ before(:each) do
11
+ @blinky = StubBlinky.new
12
+ @blinky.extend(TestCiServer)
6
13
  end
7
-
8
- describe "TestCiServer" do
9
-
10
- before(:each) do
11
- @blinky = StubBlinky.new
12
- @blinky.extend(TestCiServer)
13
- end
14
-
15
- it "cycles through all possible statuses" do
16
- @blinky.should_receive(:building!).ordered
17
- @blinky.should_receive(:sleep).ordered
18
- @blinky.should_receive(:failure!).ordered
19
- @blinky.should_receive(:sleep).ordered
20
- @blinky.should_receive(:building!).ordered
21
- @blinky.should_receive(:sleep).ordered
22
- @blinky.should_receive(:warning!).ordered
23
- @blinky.should_receive(:sleep).ordered
24
- @blinky.should_receive(:building!).ordered
25
- @blinky.should_receive(:sleep).ordered
26
- @blinky.should_receive(:success!).ordered
27
- @blinky.should_receive(:sleep).ordered
28
- @blinky.should_receive(:off!).ordered
29
-
30
- @blinky.watch_test_server
31
- end
32
-
33
- end
14
+
15
+ it "cycles through all possible statuses" do
16
+ @blinky.should_receive(:building!).ordered
17
+ @blinky.should_receive(:sleep).ordered
18
+ @blinky.should_receive(:failure!).ordered
19
+ @blinky.should_receive(:sleep).ordered
20
+ @blinky.should_receive(:building!).ordered
21
+ @blinky.should_receive(:sleep).ordered
22
+ @blinky.should_receive(:warning!).ordered
23
+ @blinky.should_receive(:sleep).ordered
24
+ @blinky.should_receive(:building!).ordered
25
+ @blinky.should_receive(:sleep).ordered
26
+ @blinky.should_receive(:success!).ordered
27
+ @blinky.should_receive(:sleep).ordered
28
+ @blinky.should_receive(:off!).ordered
29
+
30
+ @blinky.watch_test_server
31
+ end
32
+
33
+ end
34
34
  end
@@ -1,7 +1,7 @@
1
1
  module Blinky
2
2
  module MockCiServer
3
- def watch_mock_ci_server
4
- notify_build_status
5
- end
3
+ def watch_mock_ci_server
4
+ notify_build_status
5
+ end
6
6
  end
7
7
  end
@@ -1,11 +1,11 @@
1
1
  module Blinky
2
2
  module AenimaEngineering
3
3
  module Model462
4
-
4
+
5
5
  def success!
6
6
  @handle.indicate_success
7
7
  end
8
-
8
+
9
9
  end
10
10
  end
11
11
  end
@@ -1,11 +1,11 @@
1
1
  module Blinky
2
2
  module AenimaEngineering
3
3
  module ModelEulogy
4
-
4
+
5
5
  def success!
6
6
  @handle.indicate_success
7
7
  end
8
-
8
+
9
9
  end
10
10
  end
11
11
  end
@@ -1,19 +1,19 @@
1
1
  module Blinky
2
2
  module FragileEngineering
3
3
  module ModelWretched
4
-
4
+
5
5
  def success!
6
6
  @handle.indicate_success
7
7
  end
8
-
8
+
9
9
  def failure!
10
- @handle.indicate_failure
10
+ @handle.indicate_failure
11
11
  end
12
12
 
13
13
  def off!
14
14
  @handle.turn_off
15
15
  end
16
-
16
+
17
17
  end
18
18
  end
19
19
  end
@@ -1,64 +1,64 @@
1
1
  require File.join(File.dirname(__FILE__), '/spec_helper')
2
2
 
3
3
  module Blinky
4
-
4
+
5
5
  module RecipeOne
6
6
  end
7
7
 
8
8
  module RecipeTwo
9
9
  end
10
-
10
+
11
11
  describe "LightFactory" do
12
-
12
+
13
13
  before do
14
-
15
- @device_one = OpenStruct.new(:idVendor => 0x1234, :idProduct => 0x5678)
16
- @device_two = OpenStruct.new(:idVendor => 0x5678, :idProduct => 0x1234)
14
+
15
+ @device_one = double("device one", :idVendor => 0x1234, :idProduct => 0x5678)
16
+ @device_two = double("device two",:idVendor => 0x5678, :idProduct => 0x1234)
17
17
  @connected_devices = [@device_one, @device_two]
18
18
  self.connected_devices = @connected_devices
19
19
 
20
20
  @plugins = [MockCiPlugin]
21
21
  end
22
-
22
+
23
23
  it "will build a light for each connected device for which we have a recipe" do
24
- recipes = Hash.new({})
25
- recipes[0x1234] = {0x5678 => RecipeOne}
26
- recipes[0x5678] = {0x1234 => RecipeTwo}
27
-
28
- Light.should_receive(:new).with(@device_one, RecipeOne , @plugins).and_return("light one")
29
- Light.should_receive(:new).with(@device_two, RecipeTwo , @plugins).and_return("light two")
30
-
31
- lights = LightFactory.detect_lights(@plugins, recipes)
32
- lights.should include "light one"
33
- lights.should include "light two"
34
- end
35
-
36
- it "will not build a light for a connected device for which we have no recipe" do
37
- recipes = Hash.new({})
38
- recipes[0x1234] = {0x5678 => RecipeOne}
39
-
40
- Light.stub!(:new).and_return("no recipe light")
41
- Light.should_receive(:new).with(@device_one, RecipeOne , @plugins).and_return("light one")
42
-
43
- lights = LightFactory.detect_lights(@plugins, recipes)
44
- lights.should eql ["light one"]
45
- end
46
-
47
- it "will complain if there are no connected lights for which we have a recipe" do
48
- recipes = Hash.new({})
49
- recipes[0x9999] = {0x9999 => RecipeOne}
50
-
51
- exception = Exception.new("foo")
52
- NoSupportedDevicesFound.should_receive(:new).with(@connected_devices).and_return(exception)
53
- lambda{LightFactory.detect_lights(@plugins, recipes)}.should raise_error("foo")
54
- end
55
-
56
- def connected_devices= devices
57
- devices.each do |device|
58
- device.stub!(:usb_open).and_return(device)
59
- end
60
- USB.stub!(:devices).and_return(devices)
61
- end
62
-
24
+ recipes = Hash.new({})
25
+ recipes[0x1234] = {0x5678 => RecipeOne}
26
+ recipes[0x5678] = {0x1234 => RecipeTwo}
27
+
28
+ Light.should_receive(:new).with(@device_one, RecipeOne , @plugins).and_return("light one")
29
+ Light.should_receive(:new).with(@device_two, RecipeTwo , @plugins).and_return("light two")
30
+
31
+ lights = LightFactory.detect_lights(@plugins, recipes)
32
+ lights.should include "light one"
33
+ lights.should include "light two"
34
+ end
35
+
36
+ it "will not build a light for a connected device for which we have no recipe" do
37
+ recipes = Hash.new({})
38
+ recipes[0x1234] = {0x5678 => RecipeOne}
39
+
40
+ Light.stub!(:new).and_return("no recipe light")
41
+ Light.should_receive(:new).with(@device_one, RecipeOne , @plugins).and_return("light one")
42
+
43
+ lights = LightFactory.detect_lights(@plugins, recipes)
44
+ lights.should eql ["light one"]
45
+ end
46
+
47
+ it "will complain if there are no connected lights for which we have a recipe" do
48
+ recipes = Hash.new({})
49
+ recipes[0x9999] = {0x9999 => RecipeOne}
50
+
51
+ exception = Exception.new("foo")
52
+ NoSupportedDevicesFound.should_receive(:new).with(@connected_devices).and_return(exception)
53
+ lambda{LightFactory.detect_lights(@plugins, recipes)}.should raise_error("foo")
54
+ end
55
+
56
+ def connected_devices= devices
57
+ devices.each do |device|
58
+ device.stub!(:usb_open).and_return(device)
59
+ end
60
+ USB.stub!(:devices).and_return(devices)
61
+ end
62
+
63
63
  end
64
64
  end