cheeky-dreams 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/cheeky-dreams.gemspec +4 -2
- data/lib/cheeky-dreams.rb +180 -112
- data/spec/cheeky-dreams_spec.rb +371 -239
- data/spec/off.rb +10 -0
- data/spec/small-test.rb +16 -0
- data/spec/support/collecting_auditor.rb +7 -7
- data/spec/support/stub_driver.rb +1 -1
- data/spec/support/stub_effect.rb +2 -2
- metadata +13 -11
data/spec/cheeky-dreams_spec.rb
CHANGED
@@ -4,6 +4,25 @@ describe CheekyDreams do
|
|
4
4
|
|
5
5
|
include CheekyDreams
|
6
6
|
|
7
|
+
describe 'sleep_until' do
|
8
|
+
describe 'when until is in the past' do
|
9
|
+
it "should not sleep" do
|
10
|
+
finish = Time.at(0)
|
11
|
+
Time.should_receive(:now).and_return(Time.at(1))
|
12
|
+
sleep_until finish
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'when until is in the future' do
|
17
|
+
it "should sleep for expected time" do
|
18
|
+
finish = Time.at(13.1)
|
19
|
+
Time.should_receive(:now).and_return(Time.at(3.2))
|
20
|
+
should_receive(:sleep).with(9.9)
|
21
|
+
sleep_until finish
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
7
26
|
describe "find_dream_cheeky_usb_device" do
|
8
27
|
it "should locate the rgb files and return the driver" do
|
9
28
|
Dir.should_receive(:glob).with('/sys/devices/**/red').and_return(["/sys/devices/some-crazy-pci-bus-stuff/red"])
|
@@ -40,306 +59,412 @@ describe CheekyDreams do
|
|
40
59
|
end
|
41
60
|
end
|
42
61
|
|
43
|
-
describe "
|
44
|
-
it "should return rgb array for simple
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
62
|
+
describe "rgb" do
|
63
|
+
it "should return rgb array for simple colour symbols" do
|
64
|
+
rgb(:off).should == [0, 0, 0]
|
65
|
+
rgb(:red).should == [255, 0, 0]
|
66
|
+
rgb(:green).should == [0, 255, 0]
|
67
|
+
rgb(:blue).should == [0, 0, 255]
|
49
68
|
end
|
50
69
|
|
51
70
|
it "should return an rgb array when given one" do
|
52
|
-
|
71
|
+
rgb([11, 34, 111]).should == [11, 34, 111]
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should take var args and return an rgb array" do
|
75
|
+
rgb(11, 34, 111).should == [11, 34, 111]
|
53
76
|
end
|
54
77
|
|
55
78
|
it "should blow up when given meaningless symbol" do
|
56
|
-
|
79
|
+
proc { rgb(:purple_patch) }.should raise_error "Unknown colour 'purple_patch'"
|
57
80
|
end
|
58
81
|
|
59
82
|
it "should blow up when given array that isnt rgb" do
|
60
|
-
|
61
|
-
|
62
|
-
|
83
|
+
proc { rgb(1, 2) }.should raise_error "Invalid rgb [1, 2]"
|
84
|
+
proc { rgb([1, 2, 3, 4]) }.should raise_error "Invalid rgb [1, 2, 3, 4]"
|
85
|
+
proc { rgb(["a", "b", "c"]) }.should raise_error 'Invalid rgb ["a", "b", "c"]'
|
63
86
|
end
|
64
87
|
|
65
88
|
it "should blow up when given invalid rgb values" do
|
66
|
-
|
67
|
-
|
68
|
-
|
89
|
+
proc { rgb([0, 256, 0]) }.should raise_error "Invalid rgb value 0, 256, 0"
|
90
|
+
proc { rgb([-1, 0, 0]) }.should raise_error "Invalid rgb value -1, 0, 0"
|
91
|
+
proc { rgb([0, 0, 256]) }.should raise_error "Invalid rgb value 0, 0, 256"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should floor values" do
|
95
|
+
rgb(2.4, 0.1, 255.3).should == [2, 0, 255]
|
69
96
|
end
|
97
|
+
|
98
|
+
describe "creating with values out of range" do
|
99
|
+
it "should blow up" do
|
100
|
+
proc { rgb(-1, 0, 0) }.should raise_error "Invalid rgb value -1, 0, 0"
|
101
|
+
proc { rgb(256, 0, 0) }.should raise_error "Invalid rgb value 256, 0, 0"
|
102
|
+
proc { rgb(0, -1, 0) }.should raise_error "Invalid rgb value 0, -1, 0"
|
103
|
+
proc { rgb(0, 256, 0) }.should raise_error "Invalid rgb value 0, 256, 0"
|
104
|
+
proc { rgb(0, 0, -1) }.should raise_error "Invalid rgb value 0, 0, -1"
|
105
|
+
proc { rgb(0, 0, 256) }.should raise_error "Invalid rgb value 0, 0, 256"
|
106
|
+
end
|
107
|
+
end
|
70
108
|
end
|
71
|
-
end
|
72
|
-
|
73
|
-
module CheekyDreams::Device
|
74
109
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
before :each do
|
79
|
-
@device_path = "/device"
|
80
|
-
end
|
110
|
+
describe 'effects' do
|
111
|
+
|
112
|
+
include CheekyDreams
|
81
113
|
|
82
|
-
describe
|
114
|
+
describe 'off' do
|
83
115
|
before :each do
|
84
|
-
@
|
116
|
+
@off = off
|
85
117
|
end
|
86
118
|
|
87
|
-
|
119
|
+
it "should return [0,0,0] every time called" do
|
120
|
+
@off.next.should == COLOURS[:off]
|
121
|
+
@off.next.should == COLOURS[:off]
|
122
|
+
@off.next.should == COLOURS[:off]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe CheekyDreams::Effects::Solid, 'solid' do
|
127
|
+
describe "when is symbols" do
|
88
128
|
before :each do
|
89
|
-
@
|
129
|
+
@solid = solid :purple
|
90
130
|
end
|
91
131
|
|
92
|
-
it "should
|
93
|
-
|
132
|
+
it "should return rgb every time called" do
|
133
|
+
@solid.next.should == COLOURS[:purple]
|
134
|
+
@solid.next.should == COLOURS[:purple]
|
135
|
+
@solid.next.should == COLOURS[:purple]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "when is random rgb value" do
|
140
|
+
before :each do
|
141
|
+
@solid = solid [123, 123, 123]
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should return rgb every time called" do
|
145
|
+
@solid.next.should == [123, 123, 123]
|
146
|
+
@solid.next.should == [123, 123, 123]
|
147
|
+
@solid.next.should == [123, 123, 123]
|
94
148
|
end
|
95
149
|
end
|
96
150
|
end
|
97
|
-
|
98
|
-
describe
|
151
|
+
|
152
|
+
describe CheekyDreams::Effects::Cycle do
|
99
153
|
before :each do
|
100
|
-
@
|
154
|
+
@cycle = cycle [:red, :blue, [211, 192, 101]], 22
|
101
155
|
end
|
102
156
|
|
103
|
-
|
157
|
+
it "should have a frequency" do
|
158
|
+
@cycle.freq.should == 22
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should cycle through the colours as rgb" do
|
162
|
+
@cycle.next.should == [255, 0, 0]
|
163
|
+
@cycle.next.should == [ 0, 0, 255]
|
164
|
+
@cycle.next.should == [211, 192, 101]
|
165
|
+
|
166
|
+
@cycle.next.should == [255, 0, 0]
|
167
|
+
@cycle.next.should == [ 0, 0, 255]
|
168
|
+
@cycle.next.should == [211, 192, 101]
|
169
|
+
|
170
|
+
@cycle.next.should == [255, 0, 0]
|
171
|
+
@cycle.next.should == [ 0, 0, 255]
|
172
|
+
@cycle.next.should == [211, 192, 101]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe CheekyDreams::Effects::Fade do
|
177
|
+
describe "fading between two symbols" do
|
104
178
|
before :each do
|
105
|
-
@
|
106
|
-
@device.should_receive(:system).with("echo 13 > /device/green").and_return(true)
|
107
|
-
@device.should_receive(:system).with("echo 100 > /device/blue").and_return(true)
|
179
|
+
@fade = fade :blue, :green, 1, 5
|
108
180
|
end
|
109
181
|
|
110
|
-
it "should
|
111
|
-
@
|
182
|
+
it "should have a freq of 2" do
|
183
|
+
@fade.freq.should == 5
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should be able to provide the steps when asked" do
|
187
|
+
@fade.next.should == [ 0, 0, 255]
|
188
|
+
@fade.next.should == [ 0, 255, 0]
|
189
|
+
@fade.next.should == [ 0, 255, 0]
|
190
|
+
@fade.next.should == [ 0, 255, 0]
|
112
191
|
end
|
113
192
|
end
|
114
|
-
|
115
|
-
describe "
|
193
|
+
|
194
|
+
describe "fading between two arbitary rgb values" do
|
116
195
|
before :each do
|
117
|
-
@
|
118
|
-
@device.should_receive(:system).with("echo 0 > /device/green").and_return(true)
|
119
|
-
@device.should_receive(:system).with("echo 39 > /device/blue").and_return(true)
|
196
|
+
@fade = fade [100, 100, 100], [110, 90, 0], 10, 2
|
120
197
|
end
|
121
198
|
|
122
|
-
it "should
|
123
|
-
@
|
199
|
+
it "should have a freq of 2" do
|
200
|
+
@fade.freq.should == 2
|
124
201
|
end
|
202
|
+
|
203
|
+
it "should be able to provide the steps when asked" do
|
204
|
+
@fade.next.should == [100, 100, 100]
|
205
|
+
@fade.next.should == [101, 99, 90]
|
206
|
+
@fade.next.should == [102, 98, 80]
|
207
|
+
@fade.next.should == [103, 97, 70]
|
208
|
+
@fade.next.should == [104, 96, 60]
|
209
|
+
@fade.next.should == [105, 95, 50]
|
210
|
+
@fade.next.should == [106, 94, 40]
|
211
|
+
@fade.next.should == [107, 93, 30]
|
212
|
+
@fade.next.should == [108, 92, 20]
|
213
|
+
@fade.next.should == [109, 91, 10]
|
214
|
+
@fade.next.should == [110, 90, 0]
|
215
|
+
# and then continue to provide the same colour
|
216
|
+
@fade.next.should == [110, 90, 0]
|
217
|
+
@fade.next.should == [110, 90, 0]
|
218
|
+
end
|
125
219
|
end
|
126
220
|
end
|
127
|
-
|
128
|
-
describe
|
129
|
-
|
130
|
-
|
221
|
+
|
222
|
+
describe CheekyDreams::Effects::FadeTo do
|
223
|
+
describe "fading to a symbol" do
|
224
|
+
before :each do
|
225
|
+
@fade_to = fade_to :green, 11, 2
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should have a freq of 2" do
|
229
|
+
@fade_to.freq.should == 2
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should be able to gradually go to colour when asked" do
|
233
|
+
@fade_to.next([0, 145, 0]).should == [0, 145, 0]
|
234
|
+
@fade_to.next([0, 155, 0]).should == [0, 155, 0]
|
235
|
+
@fade_to.next([0, 165, 0]).should == [0, 165, 0]
|
236
|
+
@fade_to.next([0, 165, 0]).should == [0, 175, 0]
|
237
|
+
@fade_to.next([0, 175, 0]).should == [0, 185, 0]
|
238
|
+
@fade_to.next([0, 185, 0]).should == [0, 195, 0]
|
239
|
+
@fade_to.next([0, 195, 0]).should == [0, 205, 0]
|
240
|
+
@fade_to.next([0, 205, 0]).should == [0, 215, 0]
|
241
|
+
@fade_to.next([0, 215, 0]).should == [0, 225, 0]
|
242
|
+
@fade_to.next([0, 225, 0]).should == [0, 235, 0]
|
243
|
+
@fade_to.next([0, 235, 0]).should == [0, 245, 0]
|
244
|
+
@fade_to.next([0, 245, 0]).should == [0, 255, 0]
|
245
|
+
end
|
131
246
|
end
|
132
247
|
|
133
|
-
describe "
|
248
|
+
describe "fading to a random rgb" do
|
134
249
|
before :each do
|
135
|
-
@
|
136
|
-
@device.should_receive(:system).with("echo 34 > /device/green").and_return(true)
|
137
|
-
@device.should_receive(:system).with("echo 255 > /device/blue").and_return(true)
|
250
|
+
@fade_to = fade_to [130, 80, 170], 3, 20
|
138
251
|
end
|
139
252
|
|
140
|
-
it "should
|
141
|
-
@
|
253
|
+
it "should have a freq of 20" do
|
254
|
+
@fade_to.freq.should == 20
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should be able to gradually go to colour when asked" do
|
258
|
+
@fade_to.next([190, 77, 140]).should == [190, 77, 140]
|
259
|
+
@fade_to.next([190, 77, 140]).should == [170, 78, 150]
|
260
|
+
@fade_to.next([170, 78, 150]).should == [150, 79, 160]
|
261
|
+
@fade_to.next([150, 79, 160]).should == [130, 80, 170]
|
142
262
|
end
|
143
263
|
end
|
144
264
|
end
|
145
|
-
end
|
146
|
-
end
|
147
265
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
266
|
+
describe CheekyDreams::Effects::Func do
|
267
|
+
describe "when the block return rgb values" do
|
268
|
+
before :each do
|
269
|
+
@func = func(22) { |current_colour| [current_colour[0] + 1, current_colour[1] + 1, current_colour[2] + 1] }
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should have a freq of 22" do
|
273
|
+
@func.freq.should == 22
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should return the given rgb plus 1 to each of r, g, and b" do
|
277
|
+
@func.next([2, 5, 6]).should == [3, 6, 7]
|
278
|
+
end
|
156
279
|
end
|
157
280
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
281
|
+
describe "when the block return symbol" do
|
282
|
+
before :each do
|
283
|
+
@func = func(22) { |current_colour| :purple }
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should return the rgb for the symbol" do
|
287
|
+
@func.next([2, 5, 6]).should == COLOURS[:purple]
|
288
|
+
end
|
162
289
|
end
|
163
290
|
end
|
164
|
-
|
165
|
-
describe
|
291
|
+
|
292
|
+
describe CheekyDreams::Effects::Throb do
|
166
293
|
before :each do
|
167
|
-
@
|
294
|
+
@throb = throb 10, [100, 100, 100], [250, 50, 0]
|
168
295
|
end
|
169
296
|
|
170
|
-
it "should
|
171
|
-
@
|
172
|
-
|
173
|
-
|
297
|
+
it "should have r_amp" do
|
298
|
+
@throb.r_amp.should == 75
|
299
|
+
end
|
300
|
+
|
301
|
+
it "should have r_centre" do
|
302
|
+
@throb.r_centre.should == 175
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should have g_amp" do
|
306
|
+
@throb.g_amp.should == 25
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should have g_centre" do
|
310
|
+
@throb.g_centre.should == 75
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should have b_amp" do
|
314
|
+
@throb.b_amp.should == 50
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should have b_centre" do
|
318
|
+
@throb.b_centre.should == 50
|
174
319
|
end
|
175
320
|
end
|
176
321
|
end
|
177
|
-
|
178
|
-
|
322
|
+
end
|
323
|
+
|
324
|
+
module CheekyDreams
|
325
|
+
describe FilteringAuditor do
|
179
326
|
before :each do
|
180
|
-
@
|
327
|
+
@delegate = mock('delegate auditor')
|
328
|
+
@auditor = FilteringAuditor.new @delegate, [:error]
|
181
329
|
end
|
182
330
|
|
183
|
-
it
|
184
|
-
@
|
331
|
+
it 'should allow through audits of type :error' do
|
332
|
+
@delegate.should_receive(:audit).with(:error, 'here')
|
333
|
+
@auditor.audit :error, 'here'
|
185
334
|
end
|
186
335
|
|
187
|
-
it
|
188
|
-
@
|
189
|
-
@
|
190
|
-
@cycle.next.should == [211, 192, 101]
|
191
|
-
|
192
|
-
@cycle.next.should == [255, 0, 0]
|
193
|
-
@cycle.next.should == [ 0, 0,255]
|
194
|
-
@cycle.next.should == [211, 192, 101]
|
195
|
-
|
196
|
-
@cycle.next.should == [255, 0, 0]
|
197
|
-
@cycle.next.should == [ 0, 0,255]
|
198
|
-
@cycle.next.should == [211, 192, 101]
|
336
|
+
it 'should not allow through other random audits' do
|
337
|
+
@auditor.audit :error1, 'here'
|
338
|
+
@auditor.audit :error2, 'here'
|
199
339
|
end
|
200
340
|
end
|
201
341
|
|
202
|
-
describe
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
end
|
207
|
-
|
208
|
-
it "should have a freq of 2" do
|
209
|
-
@fade.freq.should == 5
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should be able to provide the steps when asked" do
|
213
|
-
@fade.next.should == [ 0, 0, 255]
|
214
|
-
@fade.next.should == [ 0, 255, 0]
|
215
|
-
@fade.next.should == [ 0, 255, 0]
|
216
|
-
@fade.next.should == [ 0, 255, 0]
|
217
|
-
end
|
342
|
+
describe CompositeAuditor do
|
343
|
+
before :each do
|
344
|
+
@auditor1, @auditor2 = mock('auditor1'), mock('auditor2')
|
345
|
+
@auditor = CompositeAuditor.new @auditor1, @auditor2
|
218
346
|
end
|
219
347
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
it "should have a freq of 2" do
|
226
|
-
@fade.freq.should == 2
|
227
|
-
end
|
228
|
-
|
229
|
-
it "should be able to provide the steps when asked" do
|
230
|
-
@fade.next.should == [100, 100, 100]
|
231
|
-
@fade.next.should == [101, 99, 90]
|
232
|
-
@fade.next.should == [102, 98, 80]
|
233
|
-
@fade.next.should == [103, 97, 70]
|
234
|
-
@fade.next.should == [104, 96, 60]
|
235
|
-
@fade.next.should == [105, 95, 50]
|
236
|
-
@fade.next.should == [106, 94, 40]
|
237
|
-
@fade.next.should == [107, 93, 30]
|
238
|
-
@fade.next.should == [108, 92, 20]
|
239
|
-
@fade.next.should == [109, 91, 10]
|
240
|
-
@fade.next.should == [110, 90, 0]
|
241
|
-
# and then continue to provide the same colour
|
242
|
-
@fade.next.should == [110, 90, 0]
|
243
|
-
@fade.next.should == [110, 90, 0]
|
244
|
-
end
|
348
|
+
it 'should notify both auditors' do
|
349
|
+
@auditor1.should_receive(:audit).with(:bob, 'marley')
|
350
|
+
@auditor2.should_receive(:audit).with(:bob, 'marley')
|
351
|
+
@auditor.audit :bob, 'marley'
|
245
352
|
end
|
246
353
|
end
|
247
354
|
|
248
|
-
describe
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
@fade_to.next([0, 215, 0]).should == [0, 225, 0]
|
267
|
-
@fade_to.next([0, 225, 0]).should == [0, 235, 0]
|
268
|
-
@fade_to.next([0, 235, 0]).should == [0, 245, 0]
|
269
|
-
@fade_to.next([0, 245, 0]).should == [0, 255, 0]
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
describe "fading to a random rgb" do
|
274
|
-
before :each do
|
275
|
-
@fade_to = FadeTo.new [130, 80, 170], 3, 20
|
276
|
-
end
|
277
|
-
|
278
|
-
it "should have a freq of 20" do
|
279
|
-
@fade_to.freq.should == 20
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should be able to gradually go to colour when asked" do
|
283
|
-
@fade_to.next([190, 77, 140]).should == [170, 78, 150]
|
284
|
-
@fade_to.next([170, 78, 150]).should == [150, 79, 160]
|
285
|
-
@fade_to.next([150, 79, 160]).should == [130, 80, 170]
|
286
|
-
end
|
355
|
+
describe StdIOAuditor do
|
356
|
+
before :each do
|
357
|
+
@out, @err = StringIO.new, StringIO.new
|
358
|
+
@auditor = StdIOAuditor.new(@out, @err)
|
359
|
+
end
|
360
|
+
|
361
|
+
it 'should report :error to stderr, with newlines between each one' do
|
362
|
+
@auditor.audit :error, "damn"
|
363
|
+
@auditor.audit :error, "this"
|
364
|
+
@out.string.should == ""
|
365
|
+
@err.string.should == "error - damn\nerror - this\n"
|
366
|
+
end
|
367
|
+
|
368
|
+
it 'should report other symbols to stdout, with newlines between each one' do
|
369
|
+
@auditor.audit :mmmm, "beer"
|
370
|
+
@auditor.audit :tastes, "good"
|
371
|
+
@out.string.should == "mmmm - beer\ntastes - good\n"
|
372
|
+
@err.string.should == ""
|
287
373
|
end
|
288
374
|
end
|
375
|
+
end
|
376
|
+
|
377
|
+
module CheekyDreams::Dev
|
378
|
+
|
379
|
+
include CheekyDreams
|
289
380
|
|
290
|
-
describe
|
291
|
-
|
381
|
+
describe IO do
|
382
|
+
before :each do
|
383
|
+
@io = StringIO.new
|
384
|
+
@device = IO.new @io
|
385
|
+
end
|
386
|
+
|
387
|
+
it 'should write colour' do
|
388
|
+
@device.go [1, 5, 6]
|
389
|
+
@io.string.should == "[1,5,6]\n"
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'should write colour only once when doesnt change' do
|
393
|
+
@device.go [1, 5, 6]
|
394
|
+
@device.go [4, 4, 4]
|
395
|
+
@device.go [4, 4, 4]
|
396
|
+
@device.go [2, 3, 4]
|
397
|
+
@io.string.should == "[1,5,6]\n[4,4,4]\n[2,3,4]\n"
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
describe DreamCheeky do
|
402
|
+
before :each do
|
403
|
+
@device_path = "/device"
|
404
|
+
end
|
405
|
+
|
406
|
+
describe "when cannot write to the files" do
|
292
407
|
before :each do
|
293
|
-
@
|
294
|
-
end
|
295
|
-
|
296
|
-
it "should have a freq of 22" do
|
297
|
-
@func.freq.should == 22
|
408
|
+
@device = DreamCheeky.new @device_path, 255
|
298
409
|
end
|
299
|
-
|
300
|
-
|
301
|
-
|
410
|
+
|
411
|
+
describe "making it go 123,34,255" do
|
412
|
+
before :each do
|
413
|
+
@device.should_receive(:system).with("echo 123 > /device/red").and_return false
|
414
|
+
end
|
415
|
+
|
416
|
+
it "should turn the light the correct colours" do
|
417
|
+
lambda { @device.go [123, 34, 255] }.should raise_error "Failed to update /device/red, do you have permissions to write to that file??"
|
418
|
+
end
|
302
419
|
end
|
303
420
|
end
|
304
421
|
|
305
|
-
describe "when the
|
422
|
+
describe "when the max threshold is 100" do
|
306
423
|
before :each do
|
307
|
-
@
|
424
|
+
@device = DreamCheeky.new @device_path, 100
|
425
|
+
end
|
426
|
+
|
427
|
+
describe "making it go 123,34,255" do
|
428
|
+
before :each do
|
429
|
+
@device.should_receive(:system).with("echo 48 > /device/red").and_return(true)
|
430
|
+
@device.should_receive(:system).with("echo 13 > /device/green").and_return(true)
|
431
|
+
@device.should_receive(:system).with("echo 100 > /device/blue").and_return(true)
|
432
|
+
end
|
433
|
+
|
434
|
+
it "should turn the light the correct colours" do
|
435
|
+
@device.go [123, 34, 255]
|
436
|
+
end
|
308
437
|
end
|
309
438
|
|
310
|
-
|
311
|
-
|
439
|
+
describe "making it go 0,1,100" do
|
440
|
+
before :each do
|
441
|
+
@device.should_receive(:system).with("echo 0 > /device/red").and_return(true)
|
442
|
+
@device.should_receive(:system).with("echo 0 > /device/green").and_return(true)
|
443
|
+
@device.should_receive(:system).with("echo 39 > /device/blue").and_return(true)
|
444
|
+
end
|
445
|
+
|
446
|
+
it "should turn the light the correct colours" do
|
447
|
+
@device.go [0, 1, 100]
|
448
|
+
end
|
312
449
|
end
|
313
450
|
end
|
314
|
-
end
|
315
|
-
|
316
|
-
describe Throb do
|
317
|
-
before :each do
|
318
|
-
@throb = Throb.new 10, [100, 100, 100], [250, 50, 0]
|
319
|
-
end
|
320
|
-
|
321
|
-
it "should have r_amp" do
|
322
|
-
@throb.r_amp.should == 75
|
323
|
-
end
|
324
|
-
|
325
|
-
it "should have r_centre" do
|
326
|
-
@throb.r_centre.should == 175
|
327
|
-
end
|
328
|
-
|
329
|
-
it "should have g_amp" do
|
330
|
-
@throb.g_amp.should == 25
|
331
|
-
end
|
332
|
-
|
333
|
-
it "should have g_centre" do
|
334
|
-
@throb.g_centre.should == 75
|
335
|
-
end
|
336
|
-
|
337
|
-
it "should have b_amp" do
|
338
|
-
@throb.b_amp.should == 50
|
339
|
-
end
|
340
451
|
|
341
|
-
|
342
|
-
|
452
|
+
describe "when the max threshold is 255" do
|
453
|
+
before :each do
|
454
|
+
@device = DreamCheeky.new @device_path, 255
|
455
|
+
end
|
456
|
+
|
457
|
+
describe "making it go 123,34,255" do
|
458
|
+
before :each do
|
459
|
+
@device.should_receive(:system).with("echo 123 > /device/red").and_return(true)
|
460
|
+
@device.should_receive(:system).with("echo 34 > /device/green").and_return(true)
|
461
|
+
@device.should_receive(:system).with("echo 255 > /device/blue").and_return(true)
|
462
|
+
end
|
463
|
+
|
464
|
+
it "should turn the light the correct colours" do
|
465
|
+
@device.go [123, 34, 255]
|
466
|
+
end
|
467
|
+
end
|
343
468
|
end
|
344
469
|
end
|
345
470
|
end
|
@@ -352,19 +477,26 @@ describe Light do
|
|
352
477
|
before :each do
|
353
478
|
@driver = StubDriver.new
|
354
479
|
@light = Light.new @driver
|
480
|
+
@collecting_auditor = CollectingAuditor.new
|
481
|
+
@audit_errors = filtering([:error], stdio_audit)
|
482
|
+
@light.auditor = audit_to @audit_errors, @collecting_auditor
|
483
|
+
end
|
484
|
+
|
485
|
+
after :each do
|
486
|
+
@light.off
|
355
487
|
end
|
356
488
|
|
357
489
|
describe "unhandled errors" do
|
358
490
|
before :each do
|
359
|
-
@
|
491
|
+
@error_message = "On purpose error"
|
492
|
+
@error = RuntimeError.new @error_message
|
360
493
|
@effect = StubEffect.new(20) { raise @error }
|
361
|
-
@auditor =
|
362
|
-
@light.auditor = @auditor
|
494
|
+
@light.auditor = @collecting_auditor
|
363
495
|
end
|
364
496
|
|
365
497
|
it 'should notify the auditor' do
|
366
498
|
@light.go @effect
|
367
|
-
within(
|
499
|
+
within(2, "auditor should have received ':error - #{@error_message}'") { [@collecting_auditor.has_received?(:error, @error_message), @collecting_auditor.events] }
|
368
500
|
end
|
369
501
|
end
|
370
502
|
|
@@ -412,6 +544,14 @@ describe Light do
|
|
412
544
|
end
|
413
545
|
|
414
546
|
describe "changing colour" do
|
547
|
+
|
548
|
+
include CheekyDreams
|
549
|
+
|
550
|
+
it "should tell the auditor" do
|
551
|
+
@light.go [22, 11, 33]
|
552
|
+
within(1, "auditor should have received ':colour_change - [22, 11, 33]'") { [@collecting_auditor.has_received?(:colour_change, "[22, 11, 33]"), @collecting_auditor.events] }
|
553
|
+
end
|
554
|
+
|
415
555
|
it "should go red" do
|
416
556
|
@light.go :red
|
417
557
|
@driver.should_become [255,0,0]
|
@@ -428,7 +568,7 @@ describe Light do
|
|
428
568
|
end
|
429
569
|
|
430
570
|
it "should blow up if you give it a symbol it doesnt understand" do
|
431
|
-
|
571
|
+
proc { @light.go :pink_with_polka_dots }.should raise_error "Unknown colour 'pink_with_polka_dots'"
|
432
572
|
end
|
433
573
|
|
434
574
|
it "should be able to go any rgb" do
|
@@ -442,7 +582,7 @@ describe Light do
|
|
442
582
|
end
|
443
583
|
|
444
584
|
it "should be able to cycle between colours when specified as rgb" do
|
445
|
-
@light.cycle([[255, 255, 255], [200, 200, 200], [100, 100, 100]], 10)
|
585
|
+
@light.go cycle([[255, 255, 255], [200, 200, 200], [100, 100, 100]], 10)
|
446
586
|
@driver.should_become [255, 255, 255]
|
447
587
|
@driver.should_become [200, 200, 200]
|
448
588
|
@driver.should_become [100, 100, 100]
|
@@ -451,7 +591,7 @@ describe Light do
|
|
451
591
|
end
|
452
592
|
|
453
593
|
it "should be able to cycle between colours when specified as symbols" do
|
454
|
-
@light.cycle([:red, :green, :blue], 10)
|
594
|
+
@light.go cycle([:red, :green, :blue], 10)
|
455
595
|
@driver.should_become :red
|
456
596
|
@driver.should_become :green
|
457
597
|
@driver.should_become :blue
|
@@ -460,7 +600,7 @@ describe Light do
|
|
460
600
|
end
|
461
601
|
|
462
602
|
it "should be able to fade from one colour to another" do
|
463
|
-
@light.fade([100, 100, 0], [105, 95, 0], 5, 2)
|
603
|
+
@light.go fade([100, 100, 0], [105, 95, 0], 5, 2)
|
464
604
|
@driver.should_become [101, 99, 0]
|
465
605
|
@driver.should_become [102, 98, 0]
|
466
606
|
@driver.should_become [103, 97, 0]
|
@@ -472,7 +612,7 @@ describe Light do
|
|
472
612
|
@light.go [100, 100, 0]
|
473
613
|
@driver.should_become [100, 100, 0]
|
474
614
|
|
475
|
-
@light.fade_to([105, 95, 0], 5, 2)
|
615
|
+
@light.go fade_to([105, 95, 0], 5, 2)
|
476
616
|
@driver.should_become [101, 99, 0]
|
477
617
|
@driver.should_become [102, 98, 0]
|
478
618
|
@driver.should_become [103, 97, 0]
|
@@ -482,7 +622,7 @@ describe Light do
|
|
482
622
|
|
483
623
|
it "should be able to go different colours based on a function" do
|
484
624
|
cycle = [:blue, :red, :green, :purple, :grey, :aqua].cycle
|
485
|
-
@light.func(10) { cycle.next }
|
625
|
+
@light.go func(10) { cycle.next }
|
486
626
|
@driver.should_become :blue
|
487
627
|
@driver.should_become :red
|
488
628
|
@driver.should_become :green
|
@@ -490,20 +630,12 @@ describe Light do
|
|
490
630
|
@driver.should_become :grey
|
491
631
|
@driver.should_become :aqua
|
492
632
|
end
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
describe "creating with values out of range" do
|
500
|
-
it "should blow up" do
|
501
|
-
lambda { rgb(-1, 0, 0) }.should raise_error "Invalid rgb value -1, 0, 0"
|
502
|
-
lambda { rgb(256, 0, 0) }.should raise_error "Invalid rgb value 256, 0, 0"
|
503
|
-
lambda { rgb(0, -1, 0) }.should raise_error "Invalid rgb value 0, -1, 0"
|
504
|
-
lambda { rgb(0, 256, 0) }.should raise_error "Invalid rgb value 0, 256, 0"
|
505
|
-
lambda { rgb(0, 0, -1) }.should raise_error "Invalid rgb value 0, 0, -1"
|
506
|
-
lambda { rgb(0, 0, 256) }.should raise_error "Invalid rgb value 0, 0, 256"
|
633
|
+
|
634
|
+
it "should not wait for an effect to finish if a new one is provided" do
|
635
|
+
@light.go fade([100, 0, 0], [110, 0, 0], 10, 2)
|
636
|
+
@driver.should_become [101, 0, 0]
|
637
|
+
@light.go :red
|
638
|
+
@driver.should_become [255, 0, 0]
|
507
639
|
end
|
508
640
|
end
|
509
641
|
end
|