sugarcube 1.5.8 → 1.5.9
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 +4 -4
- data/.travis.yml +4 -1
- data/Gemfile.lock +1 -1
- data/README.md +83 -18
- data/lib/sugarcube/version.rb +1 -1
- data/lib/sugarcube-color/symbol.rb +13 -13
- data/lib/sugarcube-factories/uiactionsheet.rb +44 -16
- data/lib/sugarcube-factories/uialertview.rb +53 -18
- data/runtests +3 -1
- data/spec/symbol_uicolor_spec.rb +748 -69
- data/spec/uiactionsheet_spec.rb +103 -2
- data/spec/uialertview_spec.rb +160 -14
- metadata +1 -1
data/spec/uiactionsheet_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
describe
|
1
|
+
describe UIActionSheet do
|
2
2
|
tests UIViewController # this is just needed so that a window is available
|
3
3
|
|
4
4
|
before do
|
@@ -30,6 +30,11 @@ describe 'UIActionSheet' do
|
|
30
30
|
alert.title.should == 'test title'
|
31
31
|
end
|
32
32
|
|
33
|
+
it 'should assign the title by options' do
|
34
|
+
alert = UIActionSheet.alert(title: 'test title', show: false)
|
35
|
+
alert.title.should == 'test title'
|
36
|
+
end
|
37
|
+
|
33
38
|
it 'should have << method' do
|
34
39
|
alert = UIActionSheet.alert('test', show: false)
|
35
40
|
-> {
|
@@ -130,6 +135,7 @@ describe 'UIActionSheet' do
|
|
130
135
|
|
131
136
|
before do
|
132
137
|
@touched = nil
|
138
|
+
@touched_index = nil
|
133
139
|
@alert = UIActionSheet.alert('test', buttons: ['cancel', 'destructive', 'ok']) { |button, index| @touched, @touched_index = button, index }
|
134
140
|
proper_wait 0.6
|
135
141
|
end
|
@@ -158,6 +164,7 @@ describe 'UIActionSheet' do
|
|
158
164
|
|
159
165
|
before do
|
160
166
|
@touched = nil
|
167
|
+
@touched_index = nil
|
161
168
|
@alert = UIActionSheet.alert('test', buttons: ['cancel', 'destructive']) { |button, index| @touched, @touched_index = button, index }
|
162
169
|
proper_wait 0.6
|
163
170
|
end
|
@@ -190,6 +197,7 @@ describe 'UIActionSheet' do
|
|
190
197
|
|
191
198
|
before do
|
192
199
|
@touched = nil
|
200
|
+
@touched_index = nil
|
193
201
|
@alert = UIActionSheet.alert('test', buttons: ['cancel', nil, 'ok']) { |button, index| @touched, @touched_index = button, index }
|
194
202
|
proper_wait 0.6
|
195
203
|
end
|
@@ -222,6 +230,7 @@ describe 'UIActionSheet' do
|
|
222
230
|
|
223
231
|
before do
|
224
232
|
@touched = nil
|
233
|
+
@touched_index = nil
|
225
234
|
@alert = UIActionSheet.alert('test', buttons: [nil, 'destructive', 'ok']) { |button, index| @touched, @touched_index = button, index }
|
226
235
|
proper_wait 0.6
|
227
236
|
end
|
@@ -254,6 +263,7 @@ describe 'UIActionSheet' do
|
|
254
263
|
|
255
264
|
before do
|
256
265
|
@touched = nil
|
266
|
+
@touched_index = nil
|
257
267
|
@alert = UIActionSheet.alert('test', buttons: [nil, nil, 'test1', 'test2']) { |button, index| @touched, @touched_index = button, index }
|
258
268
|
proper_wait 0.6
|
259
269
|
end
|
@@ -262,7 +272,7 @@ describe 'UIActionSheet' do
|
|
262
272
|
@alert.dismissWithClickedButtonIndex(-1, animated: false) if @alert.visible?
|
263
273
|
end
|
264
274
|
|
265
|
-
it 'should
|
275
|
+
it 'should not have cancel button' do
|
266
276
|
@alert.cancelButtonIndex.should == -1
|
267
277
|
end
|
268
278
|
|
@@ -285,10 +295,59 @@ describe 'UIActionSheet' do
|
|
285
295
|
|
286
296
|
end
|
287
297
|
|
298
|
+
describe 'with :buttons defined as a hash' do
|
299
|
+
|
300
|
+
before do
|
301
|
+
@touched = nil
|
302
|
+
@touched_index = nil
|
303
|
+
@alert = UIActionSheet.alert('test',
|
304
|
+
buttons: {
|
305
|
+
cancel: 'Cancel',
|
306
|
+
destructive: 'Destructive',
|
307
|
+
test1: 'Test1',
|
308
|
+
test2: 'Test2',
|
309
|
+
}) { |button, index| @touched, @touched_index = button, index }
|
310
|
+
proper_wait 0.6
|
311
|
+
end
|
312
|
+
|
313
|
+
after do
|
314
|
+
# @alert.dismissWithClickedButtonIndex(-1, animated: false) if @alert.visible?
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'should call block with :destructive when cancel button is pressed' do
|
318
|
+
@alert.destructiveButtonIndex.should == 0
|
319
|
+
@alert.dismissWithClickedButtonIndex(@alert.destructiveButtonIndex, animated: false)
|
320
|
+
@touched.should == :destructive
|
321
|
+
@touched_index.should == @alert.destructiveButtonIndex
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'should call block with :cancel when cancel button is pressed' do
|
325
|
+
@alert.cancelButtonIndex.should == 3
|
326
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
327
|
+
@touched.should == :cancel
|
328
|
+
@touched_index.should == @alert.cancelButtonIndex
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'should call block with :test1 when first button is pressed' do
|
332
|
+
@alert.firstOtherButtonIndex.should == 1
|
333
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
334
|
+
@touched.should == :test1
|
335
|
+
@touched_index.should == @alert.firstOtherButtonIndex
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'should call block with :test2 when second button is pressed' do
|
339
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex + 1, animated: false)
|
340
|
+
@touched.should == :test2
|
341
|
+
@touched_index.should == @alert.firstOtherButtonIndex + 1
|
342
|
+
end
|
343
|
+
|
344
|
+
end
|
345
|
+
|
288
346
|
describe 'with all handlers defined' do
|
289
347
|
|
290
348
|
before do
|
291
349
|
@touched = nil
|
350
|
+
@touched_index = nil
|
292
351
|
@alert = UIActionSheet.alert('test',
|
293
352
|
buttons: ['cancel', 'destructive', 'test1', 'test2'],
|
294
353
|
cancel: ->{ @touched = :cancel },
|
@@ -325,10 +384,52 @@ describe 'UIActionSheet' do
|
|
325
384
|
|
326
385
|
end
|
327
386
|
|
387
|
+
describe 'with all handlers defined and buttons as a hash' do
|
388
|
+
|
389
|
+
before do
|
390
|
+
@touched = nil
|
391
|
+
@touched_index = nil
|
392
|
+
@alert = UIActionSheet.alert('test',
|
393
|
+
buttons: {cancel: 'cancel', destructive: 'destructive', test1: 'test1', test2: 'test2'},
|
394
|
+
cancel: ->{ @touched = :cancel },
|
395
|
+
destructive: ->{ @touched = :destructive },
|
396
|
+
success: ->(button, index){ @touched, @touched_index = button, index },
|
397
|
+
)
|
398
|
+
proper_wait 0.6
|
399
|
+
end
|
400
|
+
|
401
|
+
it 'should call block with :cancel when cancel button is pressed' do
|
402
|
+
@alert.cancelButtonIndex.should == 3
|
403
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
404
|
+
@touched.should == :cancel
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'should call block with :destructive when destructive button is pressed' do
|
408
|
+
@alert.destructiveButtonIndex.should == 0
|
409
|
+
@alert.dismissWithClickedButtonIndex(@alert.destructiveButtonIndex, animated: false)
|
410
|
+
@touched.should == :destructive
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'should call block with "test1" when first button is pressed' do
|
414
|
+
@alert.firstOtherButtonIndex.should == 1
|
415
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
416
|
+
@touched.should == :test1
|
417
|
+
@touched_index.should == @alert.firstOtherButtonIndex
|
418
|
+
end
|
419
|
+
|
420
|
+
it 'should call block with "test2" when second button is pressed' do
|
421
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex + 1, animated: false)
|
422
|
+
@touched.should == :test2
|
423
|
+
@touched_index.should == @alert.firstOtherButtonIndex + 1
|
424
|
+
end
|
425
|
+
|
426
|
+
end
|
427
|
+
|
328
428
|
describe 'with success handler defined' do
|
329
429
|
|
330
430
|
before do
|
331
431
|
@touched = nil
|
432
|
+
@touched_index = nil
|
332
433
|
@alert = UIActionSheet.alert('test',
|
333
434
|
buttons: ['cancel', 'destructive', 'test1', 'test2'],
|
334
435
|
success: ->(button, index){ @touched, @touched_index = button, index },
|
data/spec/uialertview_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
describe
|
1
|
+
describe UIAlertView do
|
2
2
|
tests UIViewController # this is just needed so that a window is available
|
3
3
|
|
4
4
|
it 'should have :show option (show: false)' do
|
@@ -26,12 +26,26 @@ describe 'UIAlertView' do
|
|
26
26
|
alert.title.should == 'test title'
|
27
27
|
end
|
28
28
|
|
29
|
+
it 'should assign the title by options' do
|
30
|
+
alert = UIAlertView.alert(title: 'test title', show: false)
|
31
|
+
alert.title.should == 'test title'
|
32
|
+
end
|
33
|
+
|
29
34
|
it 'should support three args' do
|
30
35
|
alert = UIAlertView.alert('test title', 'test message', show: false)
|
36
|
+
alert.title.should == 'test title'
|
37
|
+
alert.message.should == 'test message'
|
38
|
+
alert.visible?.should == false
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should assign the title and message by options' do
|
42
|
+
alert = UIAlertView.alert(title: 'test title', message: 'test message', show: false)
|
43
|
+
alert.title.should == 'test title'
|
44
|
+
alert.message.should == 'test message'
|
31
45
|
alert.visible?.should == false
|
32
46
|
end
|
33
47
|
|
34
|
-
describe '
|
48
|
+
describe 'assigning a message' do
|
35
49
|
|
36
50
|
it 'should use the second arg' do
|
37
51
|
alert = UIAlertView.alert('test title', 'test message', show: false)
|
@@ -134,7 +148,7 @@ describe 'UIAlertView' do
|
|
134
148
|
@touched_index.should == 0
|
135
149
|
end
|
136
150
|
|
137
|
-
describe '
|
151
|
+
describe 'when :cancel and :success handlers are used' do
|
138
152
|
|
139
153
|
before do
|
140
154
|
@touched = nil
|
@@ -145,17 +159,17 @@ describe 'UIAlertView' do
|
|
145
159
|
end
|
146
160
|
|
147
161
|
after do
|
148
|
-
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
162
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false) if @alert.visible?
|
149
163
|
end
|
150
164
|
|
151
|
-
it 'should
|
165
|
+
it 'should call the :cancel block' do
|
152
166
|
proper_wait 0.6
|
153
167
|
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
154
168
|
|
155
169
|
@touched.should == :cancel
|
156
170
|
end
|
157
171
|
|
158
|
-
it 'should
|
172
|
+
it 'should call the :success block' do
|
159
173
|
proper_wait 0.6
|
160
174
|
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
161
175
|
|
@@ -172,10 +186,41 @@ describe 'UIAlertView' do
|
|
172
186
|
|
173
187
|
it 'should work with :secure_text_input' do
|
174
188
|
@called = false
|
175
|
-
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :secure_text_input)
|
189
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :secure_text_input) do |button, text|
|
190
|
+
@called = true
|
191
|
+
@text = text
|
192
|
+
end
|
193
|
+
proper_wait 0.6
|
194
|
+
alert.textFieldAtIndex(0).text = 'test text'
|
195
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
196
|
+
proper_wait 0.1
|
197
|
+
|
198
|
+
@called.should == true
|
199
|
+
@text.should == 'test text'
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should work with UIAlertViewStyleSecureTextInput' do
|
203
|
+
@called = false
|
204
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: UIAlertViewStyleSecureTextInput) do |button, text|
|
205
|
+
@called = true
|
206
|
+
@text = text
|
207
|
+
end
|
208
|
+
proper_wait 0.6
|
209
|
+
alert.textFieldAtIndex(0).text = 'test text'
|
210
|
+
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
211
|
+
proper_wait 0.1
|
212
|
+
|
213
|
+
@called.should == true
|
214
|
+
@text.should == 'test text'
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should work with :secure_text_input and pass the index' do
|
218
|
+
@called = false
|
219
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :secure_text_input) do |button, text, touched_index|
|
176
220
|
@called = true
|
177
221
|
@text = text
|
178
|
-
|
222
|
+
@touched_index = touched_index
|
223
|
+
end
|
179
224
|
proper_wait 0.6
|
180
225
|
alert.textFieldAtIndex(0).text = 'test text'
|
181
226
|
alert.dismissWithClickedButtonIndex(alert.firstOtherButtonIndex, animated: false)
|
@@ -183,12 +228,13 @@ describe 'UIAlertView' do
|
|
183
228
|
|
184
229
|
@called.should == true
|
185
230
|
@text.should == 'test text'
|
231
|
+
@touched_index.should == alert.firstOtherButtonIndex
|
186
232
|
end
|
187
233
|
|
188
234
|
it 'should work with :plain_text_input' do
|
189
|
-
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :plain_text_input)
|
235
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :plain_text_input) do |button, text|
|
190
236
|
@text = text
|
191
|
-
|
237
|
+
end
|
192
238
|
proper_wait 0.6
|
193
239
|
alert.textFieldAtIndex(0).text = 'test text'
|
194
240
|
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
@@ -197,10 +243,49 @@ describe 'UIAlertView' do
|
|
197
243
|
@text.should == 'test text'
|
198
244
|
end
|
199
245
|
|
246
|
+
it 'should work with UIAlertViewStylePlainTextInput' do
|
247
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: UIAlertViewStylePlainTextInput) do |button, text|
|
248
|
+
@text = text
|
249
|
+
end
|
250
|
+
proper_wait 0.6
|
251
|
+
alert.textFieldAtIndex(0).text = 'test text'
|
252
|
+
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
253
|
+
proper_wait 0.1
|
254
|
+
|
255
|
+
@text.should == 'test text'
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'should work with :plain_text_input and pass the index' do
|
259
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :plain_text_input) do |button, text, touched_index|
|
260
|
+
@text = text
|
261
|
+
@touched_index = touched_index
|
262
|
+
end
|
263
|
+
proper_wait 0.6
|
264
|
+
alert.textFieldAtIndex(0).text = 'test text'
|
265
|
+
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
266
|
+
proper_wait 0.1
|
267
|
+
|
268
|
+
@text.should == 'test text'
|
269
|
+
@touched_index.should == alert.cancelButtonIndex
|
270
|
+
end
|
271
|
+
|
200
272
|
it 'should work with :login_and_password_input' do
|
201
|
-
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :login_and_password_input)
|
273
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :login_and_password_input) do |button, text1, text2|
|
274
|
+
@text = "#{text1} + #{text2}"
|
275
|
+
end
|
276
|
+
proper_wait 0.6
|
277
|
+
alert.textFieldAtIndex(0).text = 'test text 1'
|
278
|
+
alert.textFieldAtIndex(1).text = 'test text 2'
|
279
|
+
alert.dismissWithClickedButtonIndex(alert.cancelButtonIndex, animated: false)
|
280
|
+
proper_wait 0.1
|
281
|
+
|
282
|
+
@text.should == 'test text 1 + test text 2'
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'should work with UIAlertViewStyleLoginAndPasswordInput' do
|
286
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: UIAlertViewStyleLoginAndPasswordInput) do |button, text1, text2|
|
202
287
|
@text = "#{text1} + #{text2}"
|
203
|
-
|
288
|
+
end
|
204
289
|
proper_wait 0.6
|
205
290
|
alert.textFieldAtIndex(0).text = 'test text 1'
|
206
291
|
alert.textFieldAtIndex(1).text = 'test text 2'
|
@@ -211,10 +296,10 @@ describe 'UIAlertView' do
|
|
211
296
|
end
|
212
297
|
|
213
298
|
it 'should work with :login_and_password_input and pass the index' do
|
214
|
-
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :login_and_password_input)
|
299
|
+
alert = UIAlertView.alert('test', buttons: ['cancel', 'ok'], style: :login_and_password_input) do |button, text1, text2, index|
|
215
300
|
@text = "#{text1} + #{text2}"
|
216
301
|
@touched_index = index
|
217
|
-
|
302
|
+
end
|
218
303
|
proper_wait 0.6
|
219
304
|
alert.textFieldAtIndex(0).text = 'test text 1'
|
220
305
|
alert.textFieldAtIndex(1).text = 'test text 2'
|
@@ -227,4 +312,65 @@ describe 'UIAlertView' do
|
|
227
312
|
|
228
313
|
end
|
229
314
|
|
315
|
+
describe 'with :buttons defined as a hash' do
|
316
|
+
|
317
|
+
before do
|
318
|
+
@touched = nil
|
319
|
+
@alert = UIAlertView.alert('test',
|
320
|
+
buttons: {
|
321
|
+
cancel: 'Cancel',
|
322
|
+
ok: 'Ok'
|
323
|
+
}) do |button|
|
324
|
+
@touched = button
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
after do
|
329
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false) if @alert.visible?
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'should work for :cancel' do
|
333
|
+
proper_wait 0.6
|
334
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
335
|
+
@touched.should == :cancel
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'should work for :ok' do
|
339
|
+
proper_wait 0.6
|
340
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
341
|
+
@touched.should == :ok
|
342
|
+
end
|
343
|
+
|
344
|
+
end
|
345
|
+
|
346
|
+
describe 'when :cancel and :success handlers are used and buttons as a hash' do
|
347
|
+
|
348
|
+
before do
|
349
|
+
@touched = nil
|
350
|
+
@alert = UIAlertView.alert('test', buttons: {cancel: 'cancel', ok: 'ok'},
|
351
|
+
cancel: ->{ @touched = :cancel },
|
352
|
+
success: ->{ @touched = :success }
|
353
|
+
)
|
354
|
+
end
|
355
|
+
|
356
|
+
after do
|
357
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false) if @alert.visible?
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'should call the :cancel block' do
|
361
|
+
proper_wait 0.6
|
362
|
+
@alert.dismissWithClickedButtonIndex(@alert.cancelButtonIndex, animated: false)
|
363
|
+
|
364
|
+
@touched.should == :cancel
|
365
|
+
end
|
366
|
+
|
367
|
+
it 'should call the :success block' do
|
368
|
+
proper_wait 0.6
|
369
|
+
@alert.dismissWithClickedButtonIndex(@alert.firstOtherButtonIndex, animated: false)
|
370
|
+
|
371
|
+
@touched.should == :success
|
372
|
+
end
|
373
|
+
|
374
|
+
end
|
375
|
+
|
230
376
|
end
|