blinky 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  = blinky
2
2
 
3
- blinky helps you see the light - get a build light up and running in a few minutes.
3
+ blinky helps you see the light - plug and play set up for build lights - get a build light up and running in a few minutes.
4
4
 
5
5
  == Why blinky?
6
6
 
@@ -19,10 +19,7 @@ Plug in your USB light, and then do something like this
19
19
  require 'rubygems'
20
20
  require 'blinky'
21
21
 
22
- blinky = Blinky.new
23
-
24
- You can also manipulate the light directly
25
-
22
+ blinky = Blinky.new
26
23
  blinky.success!
27
24
  blinky.failure!
28
25
  blinky.building!
@@ -77,10 +74,29 @@ Plug in your light and then do this:
77
74
  require 'blinky'
78
75
 
79
76
  blinky = Blinky.new
80
- blinky.watch_test_server
77
+ blinky.light.watch_test_server
81
78
 
82
79
  Watch the pretty lights!
83
-
80
+
81
+ == What if I have more than one light?
82
+
83
+ Want to plug in more than one light on the same machine?
84
+
85
+ require 'rubygems'
86
+ require 'blinky'
87
+
88
+ blinky = Blinky.new
89
+ light_one = blinky.lights[0]
90
+ light_two = blinky.lights[1]
91
+
92
+ Not sure which light is which?
93
+
94
+ # make light_one flash
95
+ light_one.where_are_you?
96
+
97
+
98
+
99
+
84
100
  == How do I contribute support for more lights
85
101
 
86
102
  COMING SOON
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,63 +1,55 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{blinky}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Perryn Fowler"]
12
- s.date = %q{2011-01-14}
12
+ s.date = %q{2011-06-15}
13
13
  s.description = %q{plug and play support for USB build status indicators}
14
14
  s.email = %q{perryn.fowler@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "blinky.gemspec",
27
- "lib/blinky.rb",
28
- "lib/blinky/no_supported_devices_found.rb",
29
- "lib/ci_server_plugins/test_server_plugin.rb",
30
- "lib/device_recipes/delcom_engineering/visual_indicator_gen_one.rb",
31
- "lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb",
32
- "lib/plugins.rb",
33
- "lib/recipes.rb",
34
- "notes.txt",
35
- "spec/blinky_spec.rb",
36
- "spec/ci_server_plugins/test_server_plugin_spec.rb",
37
- "spec/fixtures/ci_server_plugins/mock_ci_server.rb",
38
- "spec/fixtures/device_recipes/aenima_engineering/model_462.rb",
39
- "spec/fixtures/device_recipes/aenima_engineering/model_eulogy.rb",
40
- "spec/fixtures/device_recipes/fragile_engineering/wretched.rb",
41
- "spec/fixtures/plugins.rb",
42
- "spec/fixtures/recipes.rb",
43
- "spec/spec_helper.rb"
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "blinky.gemspec",
26
+ "lib/blinky.rb",
27
+ "lib/blinky/light.rb",
28
+ "lib/blinky/light_factory.rb",
29
+ "lib/blinky/no_supported_devices_found.rb",
30
+ "lib/ci_server_plugins/test_server_plugin.rb",
31
+ "lib/device_recipes/delcom_engineering/visual_indicator_gen_one.rb",
32
+ "lib/device_recipes/delcom_engineering/visual_indicator_gen_two.rb",
33
+ "lib/plugins.rb",
34
+ "lib/recipes.rb",
35
+ "notes.txt",
36
+ "spec/acceptance_spec.rb",
37
+ "spec/blinky_spec.rb",
38
+ "spec/ci_server_plugins/test_server_plugin_spec.rb",
39
+ "spec/fixtures/ci_server_plugins/mock_ci_server.rb",
40
+ "spec/fixtures/device_recipes/aenima_engineering/model_462.rb",
41
+ "spec/fixtures/device_recipes/aenima_engineering/model_eulogy.rb",
42
+ "spec/fixtures/device_recipes/fragile_engineering/wretched.rb",
43
+ "spec/fixtures/plugins.rb",
44
+ "spec/fixtures/recipes.rb",
45
+ "spec/light_factory_spec.rb",
46
+ "spec/light_spec.rb",
47
+ "spec/spec_helper.rb"
44
48
  ]
45
49
  s.homepage = %q{http://github.com/perryn/blinky}
46
- s.rdoc_options = ["--charset=UTF-8"]
47
50
  s.require_paths = ["lib"]
48
51
  s.rubygems_version = %q{1.3.7}
49
52
  s.summary = %q{helps you see the light}
50
- s.test_files = [
51
- "spec/blinky_spec.rb",
52
- "spec/ci_server_plugins/test_server_plugin_spec.rb",
53
- "spec/fixtures/ci_server_plugins/mock_ci_server.rb",
54
- "spec/fixtures/device_recipes/aenima_engineering/model_462.rb",
55
- "spec/fixtures/device_recipes/aenima_engineering/model_eulogy.rb",
56
- "spec/fixtures/device_recipes/fragile_engineering/wretched.rb",
57
- "spec/fixtures/plugins.rb",
58
- "spec/fixtures/recipes.rb",
59
- "spec/spec_helper.rb"
60
- ]
61
53
 
62
54
  if s.respond_to? :specification_version then
63
55
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -2,6 +2,8 @@ $:.unshift(File.dirname(__FILE__))
2
2
 
3
3
  require 'usb'
4
4
  require 'blinky/no_supported_devices_found'
5
+ require 'blinky/light'
6
+ require 'blinky/light_factory'
5
7
 
6
8
  module Blinky
7
9
 
@@ -12,40 +14,32 @@ module Blinky
12
14
  class Blinky
13
15
 
14
16
  def initialize(path = File.dirname(__FILE__))
15
-
17
+
16
18
  Dir["#{path}/device_recipes/**/*.rb"].each { |f| require(f) }
19
+ @recipes = Hash.new({})
20
+ instance_eval(File.read("#{path}/recipes.rb"))
21
+
17
22
  Dir["#{path}/ci_server_plugins/**/*.rb"].each { |f| require(f) }
18
- @recipes = Hash.new(:default => {})
19
23
  @plugins = []
20
- instance_eval(File.read("#{path}/recipes.rb"))
21
24
  instance_eval(File.read("#{path}/plugins.rb"))
22
-
23
- @plugins.each do |plugin|
24
- self.extend(plugin)
25
- end
26
- found_devices = []
27
-
28
- @handle = nil
29
-
30
- USB.devices.each do |device|
31
- found_devices << device
32
- matching_recipe = @recipes[device.idVendor][device.idProduct]
33
- if matching_recipe
34
- self.extend(matching_recipe)
35
- @handle = device.usb_open
36
- end
37
- end
38
-
39
- raise NoSupportedDevicesFound.new found_devices unless @handle
25
+
26
+ @lights = LightFactory.detect_lights(@plugins, @recipes)
27
+ end
28
+
29
+ def lights
30
+ @lights
31
+ end
32
+
33
+ def light
34
+ @lights.first
40
35
  end
41
36
 
42
37
  def recipe recipe_module, details
43
- if @recipes[details[:usb_vendor_id]].empty?
44
- @recipes[details[:usb_vendor_id]] = {details[:usb_product_id] => recipe_module}
45
- else
46
- @recipes[details[:usb_vendor_id]][details[:usb_product_id]] = recipe_module
47
- end
48
-
38
+ if @recipes[details[:usb_vendor_id]].empty?
39
+ @recipes[details[:usb_vendor_id]] = {details[:usb_product_id] => recipe_module}
40
+ else
41
+ @recipes[details[:usb_vendor_id]][details[:usb_product_id]] = recipe_module
42
+ end
49
43
  end
50
44
 
51
45
  def plugin plugin_module
@@ -0,0 +1,23 @@
1
+ module Blinky
2
+ class Light
3
+
4
+ def initialize device_handle, recipe, plugins
5
+ @handle = device_handle
6
+ self.extend(recipe)
7
+ plugins.each do |plugin|
8
+ self.extend(plugin)
9
+ end
10
+ end
11
+
12
+ def where_are_you?
13
+ 5.times do
14
+ failure!
15
+ sleep(0.5)
16
+ success!
17
+ sleep(0.5)
18
+ end
19
+ off!
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ module Blinky
2
+ class LightFactory
3
+
4
+ def self.detect_lights plugins, recipes
5
+ lights = []
6
+ found_devices = []
7
+ USB.devices.each do |device|
8
+ found_devices << device
9
+ matching_recipe = recipes[device.idVendor][device.idProduct]
10
+ if matching_recipe
11
+ lights << Light.new(device.usb_open, matching_recipe, plugins)
12
+ end
13
+ end
14
+ raise NoSupportedDevicesFound.new found_devices if lights.empty?
15
+ lights
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,150 @@
1
+ require File.join(File.dirname(__FILE__), '/spec_helper')
2
+
3
+ module Blinky
4
+ describe "Blinky" do
5
+
6
+ describe "that has a supported device connected" do
7
+
8
+ before(:each) do
9
+ @supported_device = OpenStruct.new(:idVendor => 0x2000, :idProduct => 0x2222)
10
+ self.connected_devices = [
11
+ OpenStruct.new(:idVendor => 0x1234, :idProduct => 0x5678),
12
+ @supported_device,
13
+ OpenStruct.new(:idVendor => 0x5678, :idProduct => 0x1234)
14
+ ]
15
+ @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
16
+ end
17
+
18
+ it "will provide a single light" do
19
+ @blinky.light.should_not be_nil
20
+ @blinky.lights.length.should == 1
21
+ end
22
+
23
+ it "can provide a light that can control the device" do
24
+ @supported_device.should_receive(:indicate_success)
25
+ @blinky.light.success!
26
+ end
27
+
28
+ it "can provide a light that can show where it is" do
29
+ @supported_device.should_receive(:indicate_failure).ordered
30
+ @supported_device.should_receive(:indicate_success).ordered
31
+ @supported_device.should_receive(:indicate_failure).ordered
32
+ @supported_device.should_receive(:indicate_success).ordered
33
+ @supported_device.should_receive(:indicate_failure).ordered
34
+ @supported_device.should_receive(:indicate_success).ordered
35
+ @supported_device.should_receive(:indicate_failure).ordered
36
+ @supported_device.should_receive(:indicate_success).ordered
37
+ @supported_device.should_receive(:indicate_failure).ordered
38
+ @supported_device.should_receive(:indicate_success).ordered
39
+ @supported_device.should_receive(:turn_off).ordered
40
+
41
+ @blinky.light.where_are_you?
42
+ end
43
+
44
+ end
45
+
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
+
65
+ describe "that has no supported devices connected" do
66
+
67
+ before(:each) do
68
+ @devices = [
69
+ OpenStruct.new(:idVendor => 0x1234, :idProduct => 0x5678),
70
+ OpenStruct.new(: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
+ 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
150
+ end
@@ -1,123 +1,32 @@
1
1
  require File.join(File.dirname(__FILE__), '/spec_helper')
2
+ Dir["#{File.dirname(__FILE__)}/fixtures/device_recipes/**/*.rb"].each { |f| require(f) }
3
+ Dir["#{File.dirname(__FILE__)}/fixtures/ci_server_plugins/**/*.rb"].each { |f| require(f) }
2
4
 
3
5
  module Blinky
4
6
  describe "Blinky" do
5
7
 
6
- describe "that has a supported device connected" do
7
-
8
- before(:each) do
9
- @supported_device = OpenStruct.new(:idVendor => 0x2000, :idProduct => 0x2222)
10
- self.connected_devices = [
11
- OpenStruct.new(:idVendor => 0x1234, :idProduct => 0x5678),
12
- @supported_device,
13
- OpenStruct.new(:idVendor => 0x5678, :idProduct => 0x1234)
14
- ]
15
- @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
16
- end
17
-
18
- it "can call recipe methods on the device" do
19
- @supported_device.should_receive(:indicate_success)
20
- @blinky.success!
21
- end
22
-
8
+ it "will construct a light factory with the available plugins and recipes" do
9
+ expected_plugins = [MockCiServer]
10
+ expected_recipes = {
11
+ 0x1000 => { 0x2222 => AenimaEngineering::ModelEulogy, 0x1111 => AenimaEngineering::Model462 },
12
+ 0x2000 => { 0x2222 => FragileEngineering::ModelWretched }
13
+ }
14
+ LightFactory.should_receive(:detect_lights).with( expected_plugins, expected_recipes).and_return([])
15
+ Blinky.new("#{File.dirname(__FILE__)}/fixtures")
23
16
  end
24
17
 
25
- describe "that supports two devices from the same vendor" do
26
-
27
- it "can call recipe methods on the first device" do
28
- supported_device_one = OpenStruct.new(:idVendor => 0x1000, :idProduct => 0x1111)
29
- self.connected_devices = [supported_device_one]
30
- @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
31
- supported_device_one.should_receive(:indicate_success)
32
- @blinky.success!
33
- end
34
-
35
- it "can call recipe methods on the second device" do
36
- supported_device_two = OpenStruct.new(:idVendor => 0x1000, :idProduct => 0x2222)
37
- self.connected_devices = [supported_device_two]
38
- @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
39
- supported_device_two.should_receive(:indicate_success)
40
- @blinky.success!
41
- end
42
- end
43
-
44
- describe "that has no supported devices connected" do
45
-
46
- before(:each) do
47
- @devices = [
48
- OpenStruct.new(:idVendor => 0x1234, :idProduct => 0x5678),
49
- OpenStruct.new(:idVendor => 0x5678, :idProduct => 0x1234)
50
- ]
51
- self.connected_devices= @devices
52
- end
53
-
54
- it "will complain" do
55
- exception = Exception.new("foo")
56
- NoSupportedDevicesFound.should_receive(:new).with(@devices).and_return(exception)
57
- lambda{Blinky.new("#{File.dirname(__FILE__)}/fixtures")}.should raise_error("foo")
58
- end
59
-
60
- end
61
-
62
- describe "that has no supported devices connected - but does have one from the same vendor" do
63
-
64
- before(:each) do
65
- @devices = [
66
- OpenStruct.new(:idVendor => 0x1000, :idProduct => 0x5678),
67
- OpenStruct.new(:idVendor => 0x5678, :idProduct => 0x1234)
68
- ]
69
- self.connected_devices= @devices
70
- end
71
-
72
- it "will complain" do
73
- exception = Exception.new("foo")
74
- NoSupportedDevicesFound.should_receive(:new).with(@devices).and_return(exception)
75
- lambda{Blinky.new("#{File.dirname(__FILE__)}/fixtures")}.should raise_error("foo")
76
- end
77
-
78
- end
79
-
80
- describe "that has two supported devices connected" do
81
-
82
- before(:each) do
83
- @supported_device_one = OpenStruct.new(:idVendor => 0x1000, :idProduct => 0x1111)
84
- @supported_device_two = OpenStruct.new(:idVendor => 0x2000, :idProduct => 0x2222)
85
-
86
- self.connected_devices = [
87
- OpenStruct.new(:idVendor => 0x1234, :idProduct => 0x5678),
88
- @supported_device_one,
89
- @supported_device_two
90
- ]
91
- @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
92
- end
93
-
94
- it "will choose the second device" do
95
- @supported_device_one.should_not_receive(:indicate_success)
96
- @supported_device_two.should_receive(:indicate_success)
97
- @blinky.success!
98
- end
99
- end
100
-
101
- describe "that is asked to watch a supported CI server" do
102
-
103
- before(:each) do
104
- self.connected_devices = [OpenStruct.new(:idVendor => 0x1000, :idProduct => 0x1111)]
105
- @blinky = Blinky.new("#{File.dirname(__FILE__)}/fixtures")
106
- end
107
-
108
- it "can receive call backs from the server" do
109
- @blinky.should_receive(:notify_build_status)
110
- @blinky.watch_mock_ci_server
111
- end
112
-
113
- end
114
-
115
- def connected_devices= devices
116
- devices.each do |device|
117
- device.stub!(:usb_open).and_return(device)
118
- end
119
- USB.stub!(:devices).and_return(devices)
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"
120
30
  end
121
-
122
- end
31
+ end
123
32
  end
@@ -5,6 +5,14 @@ module Blinky
5
5
  def success!
6
6
  @handle.indicate_success
7
7
  end
8
+
9
+ def failure!
10
+ @handle.indicate_failure
11
+ end
12
+
13
+ def off!
14
+ @handle.turn_off
15
+ end
8
16
 
9
17
  end
10
18
  end
@@ -0,0 +1,64 @@
1
+ require File.join(File.dirname(__FILE__), '/spec_helper')
2
+
3
+ module Blinky
4
+
5
+ module RecipeOne
6
+ end
7
+
8
+ module RecipeTwo
9
+ end
10
+
11
+ describe "LightFactory" do
12
+
13
+ before do
14
+
15
+ @device_one = OpenStruct.new(:idVendor => 0x1234, :idProduct => 0x5678)
16
+ @device_two = OpenStruct.new(:idVendor => 0x5678, :idProduct => 0x1234)
17
+ @connected_devices = [@device_one, @device_two]
18
+ self.connected_devices = @connected_devices
19
+
20
+ @plugins = [MockCiPlugin]
21
+ end
22
+
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
+
63
+ end
64
+ end
@@ -0,0 +1,52 @@
1
+ require File.join(File.dirname(__FILE__), '/spec_helper')
2
+
3
+ module Blinky
4
+
5
+ module TestEngineering
6
+ module TestModel
7
+ def success!
8
+ @handle.indicate_success
9
+ end
10
+ end
11
+ end
12
+
13
+ module MockCiPlugin
14
+ def watch_mock_ci_server
15
+ notify_build_status
16
+ end
17
+ end
18
+
19
+ module AnotherMockCiPlugin
20
+ def watch_another_mock_ci_server
21
+ notify_a_different_build_status
22
+ end
23
+ end
24
+
25
+
26
+ describe "Light" do
27
+
28
+ describe "that has been constructed with a device, a device recipe, and some CI plugins" do
29
+
30
+ before(:each) do
31
+ @supported_device = OpenStruct.new(:idVendor => 0x2000, :idProduct => 0x2222)
32
+ @light = Light.new(@supported_device, TestEngineering::TestModel, [MockCiPlugin, AnotherMockCiPlugin ] )
33
+ end
34
+
35
+ it "can call recipe methods on the device" do
36
+ @supported_device.should_receive(:indicate_success)
37
+ @light.success!
38
+ end
39
+
40
+ it "can receive call back methods defined in a plugins" do
41
+ @light.should_receive(:notify_build_status)
42
+ @light.watch_mock_ci_server
43
+ end
44
+
45
+ it "can receive call backs from a server via another plugin" do
46
+ @light.should_receive(:notify_a_different_build_status)
47
+ @light.watch_another_mock_ci_server
48
+ end
49
+
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blinky
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Perryn Fowler
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-14 00:00:00 +11:00
18
+ date: 2011-06-15 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -59,13 +59,14 @@ extra_rdoc_files:
59
59
  - README.rdoc
60
60
  files:
61
61
  - .document
62
- - .gitignore
63
62
  - LICENSE
64
63
  - README.rdoc
65
64
  - Rakefile
66
65
  - VERSION
67
66
  - blinky.gemspec
68
67
  - lib/blinky.rb
68
+ - lib/blinky/light.rb
69
+ - lib/blinky/light_factory.rb
69
70
  - lib/blinky/no_supported_devices_found.rb
70
71
  - lib/ci_server_plugins/test_server_plugin.rb
71
72
  - lib/device_recipes/delcom_engineering/visual_indicator_gen_one.rb
@@ -73,6 +74,7 @@ files:
73
74
  - lib/plugins.rb
74
75
  - lib/recipes.rb
75
76
  - notes.txt
77
+ - spec/acceptance_spec.rb
76
78
  - spec/blinky_spec.rb
77
79
  - spec/ci_server_plugins/test_server_plugin_spec.rb
78
80
  - spec/fixtures/ci_server_plugins/mock_ci_server.rb
@@ -81,14 +83,16 @@ files:
81
83
  - spec/fixtures/device_recipes/fragile_engineering/wretched.rb
82
84
  - spec/fixtures/plugins.rb
83
85
  - spec/fixtures/recipes.rb
86
+ - spec/light_factory_spec.rb
87
+ - spec/light_spec.rb
84
88
  - spec/spec_helper.rb
85
89
  has_rdoc: true
86
90
  homepage: http://github.com/perryn/blinky
87
91
  licenses: []
88
92
 
89
93
  post_install_message:
90
- rdoc_options:
91
- - --charset=UTF-8
94
+ rdoc_options: []
95
+
92
96
  require_paths:
93
97
  - lib
94
98
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -116,13 +120,5 @@ rubygems_version: 1.3.7
116
120
  signing_key:
117
121
  specification_version: 3
118
122
  summary: helps you see the light
119
- test_files:
120
- - spec/blinky_spec.rb
121
- - spec/ci_server_plugins/test_server_plugin_spec.rb
122
- - spec/fixtures/ci_server_plugins/mock_ci_server.rb
123
- - spec/fixtures/device_recipes/aenima_engineering/model_462.rb
124
- - spec/fixtures/device_recipes/aenima_engineering/model_eulogy.rb
125
- - spec/fixtures/device_recipes/fragile_engineering/wretched.rb
126
- - spec/fixtures/plugins.rb
127
- - spec/fixtures/recipes.rb
128
- - spec/spec_helper.rb
123
+ test_files: []
124
+
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC