druid-ts 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/ChangeLog +15 -0
  4. data/Gemfile +1 -0
  5. data/druid.gemspec +1 -0
  6. data/features/button.feature +2 -1
  7. data/features/checkbox.feature +2 -1
  8. data/features/div.feature +2 -1
  9. data/features/element.feature +2 -0
  10. data/features/file_field.feature +2 -1
  11. data/features/form.feature +2 -1
  12. data/features/hidden_field.feature +2 -1
  13. data/features/html/nested_elements.html +20 -0
  14. data/features/image.feature +2 -1
  15. data/features/javascript.feature +13 -0
  16. data/features/link.feature +1 -1
  17. data/features/list_item.feature +2 -1
  18. data/features/nested_elements.feature +12 -0
  19. data/features/ordered_list.feature +2 -1
  20. data/features/paragraph.feature +2 -1
  21. data/features/radio_button.feature +2 -1
  22. data/features/sample-app/public/jquery-1.3.2.js +4376 -0
  23. data/features/sample-app/public/jquery.html +28 -0
  24. data/features/sample-app/public/prototype-1.6.0.3.js +4320 -0
  25. data/features/sample-app/public/prototype.html +32 -0
  26. data/features/sample-app/sample_app.rb +30 -0
  27. data/features/select_list.feature +13 -1
  28. data/features/span.feature +2 -1
  29. data/features/step_definations/button_steps.rb +4 -0
  30. data/features/step_definations/checkbox_steps.rb +4 -0
  31. data/features/step_definations/div_steps.rb +4 -0
  32. data/features/step_definations/element_steps.rb +8 -0
  33. data/features/step_definations/file_field_steps.rb +4 -0
  34. data/features/step_definations/form_steps.rb +4 -0
  35. data/features/step_definations/hidden_field_steps.rb +4 -0
  36. data/features/step_definations/image_steps.rb +4 -0
  37. data/features/step_definations/javasript_steps.rb +29 -0
  38. data/features/step_definations/list_item_steps.rb +4 -0
  39. data/features/step_definations/nested_elements_steps.rb +15 -0
  40. data/features/step_definations/ordered_list_steps.rb +4 -0
  41. data/features/step_definations/paragraph_steps.rb +4 -0
  42. data/features/step_definations/radio_button_steps.rb +4 -0
  43. data/features/step_definations/select_list_steps.rb +16 -0
  44. data/features/step_definations/span_steps.rb +4 -0
  45. data/features/step_definations/table_cell_steps.rb +4 -0
  46. data/features/step_definations/table_steps.rb +4 -0
  47. data/features/step_definations/text_area_steps.rb +4 -0
  48. data/features/step_definations/text_field_steps.rb +8 -0
  49. data/features/step_definations/unordered_list_steps.rb +4 -0
  50. data/features/support/ajax_test_environment.rb +26 -0
  51. data/features/support/url_helper.rb +1 -0
  52. data/features/table.feature +2 -1
  53. data/features/table_cell.feature +2 -1
  54. data/features/text_area.feature +2 -1
  55. data/features/text_field.feature +7 -1
  56. data/features/unordered_list.feature +2 -1
  57. data/lib/druid.rb +39 -1
  58. data/lib/druid/accessors.rb +230 -82
  59. data/lib/druid/elements/element.rb +7 -1
  60. data/lib/druid/elements/ordered_list.rb +18 -3
  61. data/lib/druid/elements/select_list.rb +24 -0
  62. data/lib/druid/elements/text_area.rb +1 -1
  63. data/lib/druid/elements/text_field.rb +4 -0
  64. data/lib/druid/elements/unordered_list.rb +18 -3
  65. data/lib/druid/javascript/jquery.rb +12 -0
  66. data/lib/druid/javascript/prototype.rb +12 -0
  67. data/lib/druid/javascript_framework_facade.rb +72 -0
  68. data/lib/druid/version.rb +1 -1
  69. data/spec/druid/druid_spec.rb +18 -3
  70. data/spec/druid/elements/element_spec.rb +5 -0
  71. data/spec/druid/elements/ordered_list_spec.rb +12 -4
  72. data/spec/druid/elements/select_list_spec.rb +17 -0
  73. data/spec/druid/elements/text_area_spec.rb +1 -1
  74. data/spec/druid/elements/text_field_spec.rb +5 -0
  75. data/spec/druid/elements/unordered_list_spec.rb +12 -4
  76. data/spec/druid/javascript_framework_facade_spec.rb +59 -0
  77. metadata +36 -1
@@ -56,13 +56,15 @@ module Druid
56
56
  frame << {iframe: identifier}
57
57
  block.call(frame)
58
58
  end
59
+
59
60
  #
60
- # add three methods - one to select a link and another
61
- # to return a link element, and another one to select a link and not wait for the corresponding action to complete
61
+ # adds three methods - one to select a link, another
62
+ # to return a PageObject::Elements::Link object representing
63
+ # the link, and another that checks the link's existence.
62
64
  #
63
- # Example: link(:add_to_cart, :text => "Add to Cart")
64
- # will generate the 'add_to_cart' and 'add_to_cart_element', 'add_to_cart_no_wait'
65
- # methods.
65
+ # @example
66
+ # link(:add_to_cart, :text => "Add to Cart")
67
+ # # will generate 'add_to_cart', 'add_to_cart_element', and 'add_to_cart?' methods
66
68
  #
67
69
  # @param the name used for the generated methods
68
70
  # @param identifier how we find a link. The valid values are:
@@ -85,16 +87,22 @@ module Druid
85
87
  link_for(identifier.clone)
86
88
  # block ? call_block(&block) : link_for(identifier.clone)
87
89
  end
90
+ define_method("#{name}?") do
91
+ return call_block(&block) if block_given?
92
+ link_for(identifier.clone).exist?
93
+ end
88
94
  alias_method "#{name}_link".to_sym, "#{name}_element".to_sym
89
95
  end
90
96
 
91
97
  #
92
- # adds three methods to the page object - one to set text in a text field,
93
- # another to retrieve text from a text field and another to return the text
94
- # field element.
98
+ # adds four methods to the page object - one to set text in a text field,
99
+ # another to retrieve text from a text field, another to return the text
100
+ # field element, another to check the text field's existence.
95
101
  #
96
- # Example: text_field(:first_name, {:id => "first_name"})
97
- # will generate the 'first_name', 'first_name=' and 'first_name_element methods.
102
+ # @example
103
+ # text_field(:first_name, :id => "first_name")
104
+ # # will generate 'first_name', 'first_name=', 'first_name_element',
105
+ # # 'first_name?' methods
98
106
  #
99
107
  # @param the name used for the generated methods
100
108
  # @param identifier how we find a text_field. The valid values are:
@@ -121,16 +129,23 @@ module Druid
121
129
  text_field_for(identifier.clone)
122
130
  # block ? call_block(&block) : text_field_for(identifier.clone)
123
131
  end
132
+ define_method("#{name}?") do
133
+ return call_block(&block) if block_given?
134
+ text_field_for(identifier.clone).exist?
135
+ end
124
136
  alias_method "#{name}_text_field".to_sym, "#{name}_element".to_sym
125
137
  end
138
+
126
139
  #
127
- # adds four methods - one to check, another to uncheck, another
128
- # to return the state of a checkbox, and a final method to return
129
- # a checkbox element.
140
+ # adds five methods - one to check, another to uncheck, another
141
+ # to return the state of a checkbox, another to return
142
+ # a PageObject::Elements::CheckBox object representing the checkbox, and
143
+ # a final method to check the checkbox's existence.
130
144
  #
131
- # Example: checkbox(:active, {:name => "is_active"})
132
- # will generate the 'check_active', 'uncheck_active',
133
- # 'active_checked?' and 'active_element' methods.
145
+ # @example
146
+ # checkbox(:active, :name => "is_active")
147
+ # # will generate 'check_active', 'uncheck_active', 'active_checked?',
148
+ # # 'active_element', and 'active?' methods
134
149
  #
135
150
  # @param the name used for the generated methods
136
151
  # @param identifier how we find a checkbox. The valid values are:
@@ -159,15 +174,22 @@ module Druid
159
174
  checkbox_for(identifier.clone)
160
175
  # block ? call_block(&block) : checkbox_for(identifier.clone)
161
176
  end
177
+ define_method("#{name}?") do
178
+ return call_block(&block) if block_given?
179
+ checkbox_for(identifier.clone).exist?
180
+ end
162
181
  alias_method "#{name}_checkbox".to_sym, "#{name}_element".to_sym
163
182
  end
183
+
164
184
  #
165
- # adds three methods - one to select an item in a drop-down,
166
- # another to fetch the currently selected item and another
167
- # to retrieve the select list element.
185
+ # adds four methods - one to select an item in a drop-down,
186
+ # another to fetch the currently selected item, another
187
+ # to retrieve the select list element, and another to check the
188
+ # drop down's existence.
168
189
  #
169
- # Example: select_list(:state, {:id => "state"})
170
- # will generate the 'state', 'state=' and 'state_element' methods
190
+ # @example
191
+ # select_list(:state, :id => "state")
192
+ # # will generate 'state', 'state=', 'state_element', 'state?' methods
171
193
  #
172
194
  # @param the name used for the generated methods
173
195
  # @param identifier how we find a select_list. The valid values are:
@@ -191,16 +213,24 @@ module Druid
191
213
  select_list_for(identifier.clone)
192
214
  # block ? call_block(&block) : select_list_for(identifier.clone)
193
215
  end
216
+ define_method("#{name}?") do
217
+ return call_block(&block) if block_given?
218
+ select_list_for(identifier.clone).exist?
219
+ end
194
220
  alias_method "#{name}_select_list".to_sym, "#{name}_element".to_sym
195
221
  end
222
+
196
223
  #
197
- # adds three methods - one to select
198
- # another to return if a radio button is selected, and
199
- # another method to return a radio_button element
224
+ # adds five methods - one to select, another to clear,
225
+ # another to return if a radio button is selected,
226
+ # another method to return a PageObject::Elements::RadioButton
227
+ # object representing the radio button element, and another to check
228
+ # the radio button's existence.
200
229
  #
201
- # Example: radio_button(:north, {:id => "north"})
202
- # will generate 'select_north'
203
- # 'north_selected?' and 'north_element' methods
230
+ # @example
231
+ # radio_button(:north, :id => "north")
232
+ # # will generate 'select_north', 'clear_north', 'north_selected?',
233
+ # # 'north_element', and 'north?' methods
204
234
  #
205
235
  # @param the name used for the generated methods
206
236
  # @param identifier how we find a radio_button. The valid values are:
@@ -229,14 +259,20 @@ module Druid
229
259
  radio_button_for(identifier.clone)
230
260
  # block ? call_block(&block) : radio_button_for(identifier.clone)
231
261
  end
262
+ define_method("#{name}?") do
263
+ return call_block(&block) if block_given?
264
+ radio_button_for(identifier.clone).exist?
265
+ end
232
266
  alias_method "#{name}_radio_button".to_sym, "#{name}_element".to_sym
233
267
  end
268
+
234
269
  #
235
- # adds two methods - one to click a button and another to
236
- # return the button element.
270
+ # adds three methods - one to click a button, another to
271
+ # return the button element, and another to check the button's existence.
237
272
  #
238
- # Example: button(:purchase, :id => 'purchase')
239
- # will generate a 'purchase' and 'purchase_element' methods.
273
+ # @example
274
+ # button(:purchase, :id => 'purchase')
275
+ # # will generate 'purchase', 'purchase_element', and 'purchase?' methods
240
276
  #
241
277
  # @param the name used for the generated methods
242
278
  # @param identifier how we find a button. The valid values are:
@@ -259,14 +295,20 @@ module Druid
259
295
  button_for(identifier.clone)
260
296
  # block ? call_block(&block) : button_for(identifier.clone)
261
297
  end
298
+ define_method("#{name}?") do
299
+ return call_block(&block) if block_given?
300
+ button_for(identifier.clone).exist?
301
+ end
262
302
  alias_method "#{name}_button".to_sym, "#{name}_element".to_sym
263
303
  end
304
+
264
305
  #
265
- # adds two methods - one to retrieve the text from a div
266
- # and another to return the div element
306
+ # adds three methods - one to retrieve the text from a div,
307
+ # another to return the div element, and another to check the div's existence.
267
308
  #
268
- # Example: div(:message, {:id => 'message'})
269
- # will generate a 'message' and 'message_element' methods
309
+ # @example
310
+ # div(:message, :id => 'message')
311
+ # # will generate 'message', 'message_element', and 'message?' methods
270
312
  #
271
313
  # @param the name used for the generated methods
272
314
  # @param identifier how we find a div. The valid values are:
@@ -288,13 +330,20 @@ module Druid
288
330
  div_for(identifier.clone)
289
331
  # block ? call_block(&block) : div_for(identifier.clone)
290
332
  end
333
+ define_method("#{name}?") do
334
+ return call_block(&block) if block_given?
335
+ div_for(identifier.clone).exist?
336
+ end
291
337
  alias_method "#{name}_div".to_sym, "#{name}_element".to_sym
292
338
  end
339
+
293
340
  #
294
- # adds a method to retrieve the table element
341
+ # adds two methods - one to retrieve the table element, and another to
342
+ # check the table's existence.
295
343
  #
296
- # Example: table(:cart, :id => 'shopping_cart')
297
- # will generate a 'cart_element' method.
344
+ # @example
345
+ # table(:cart, :id => 'shopping_cart')
346
+ # # will generate a 'cart_element' and 'cart?' method
298
347
  #
299
348
  # @param the name used for the generated methods
300
349
  # @param identifier how we find a table. The valid values are:
@@ -310,14 +359,21 @@ module Druid
310
359
  table_for(identifier.clone)
311
360
  # block ? call_block(&block) : table_for(identifier.clone)
312
361
  end
362
+ define_method("#{name}?") do
363
+ return call_block(&block) if block_given?
364
+ table_for(identifier.clone).exist?
365
+ end
313
366
  alias_method "#{name}_table".to_sym, "#{name}_element".to_sym
314
367
  end
368
+
315
369
  #
316
- # adds two methods one to retrieve the text from a table cell
317
- # and another to return the table cell element
370
+ # adds three methods - one to retrieve the text from a table cell,
371
+ # another to return the table cell element, and another to check the cell's
372
+ # existence.
318
373
  #
319
- # Example: cell(:total, :id => 'total_cell')
320
- # will generate a 'total' and 'total_element' methods
374
+ # @example
375
+ # cell(:total, :id => 'total_cell')
376
+ # # will generate 'total', 'total_element', and 'total?' methods
321
377
  #
322
378
  # @param the name used for the generated methods
323
379
  # @param identifier how we find a cell. The valid values are:
@@ -338,14 +394,20 @@ module Druid
338
394
  cell_for(identifier.clone)
339
395
  # block ? call_block(&block) : cell_for(identifier.clone)
340
396
  end
397
+ define_method("#{name}?") do
398
+ return call_block(&block) if block_given?
399
+ cell_for(identifier.clone).exist?
400
+ end
341
401
  alias_method "#{name}_cell".to_sym, "#{name}_element".to_sym
342
402
  end
403
+
343
404
  #
344
- # adds two methods - one to retrieve the text from a span
345
- # and another to return the span element
405
+ # adds three methods - one to retrieve the text from a span,
406
+ # another to return the span element, and another to check the span's existence.
346
407
  #
347
- # Example: span(:alert, {:id => 'alert'})
348
- # will generate a 'alert' and 'alert_element' methods
408
+ # @example
409
+ # span(:alert, :id => 'alert')
410
+ # # will generate 'alert', 'alert_element', and 'alert?' methods
349
411
  #
350
412
  # @param the name used for the generated methods
351
413
  # @param identifier how we find a span. The valid values are:
@@ -366,13 +428,20 @@ module Druid
366
428
  span_for(identifier.clone)
367
429
  # block ? call_block(&block) : span_for(identifier.clone)
368
430
  end
431
+ define_method("#{name}?") do
432
+ return call_block(&block) if block_given?
433
+ span_for(identifier.clone).exist?
434
+ end
369
435
  alias_method "#{name}_span".to_sym, "#{name}_element".to_sym
370
436
  end
437
+
371
438
  #
372
- # adds a method to retrieve the image element
439
+ # adds two methods - one to retrieve the image element, and another to
440
+ # check the image's existence.
373
441
  #
374
- # Example: image(:photo, :id => 'photo_id')
375
- # will generate a 'photo_element' method.
442
+ # @example
443
+ # image(:logo, :id => 'logo')
444
+ # # will generate 'logo_element' and 'logo?' methods
376
445
  #
377
446
  # @param the name used for the generated methods
378
447
  # @param identifier how we find a image. The valid values are:
@@ -390,14 +459,20 @@ module Druid
390
459
  image_for(identifier.clone)
391
460
  # block ? call_block(&block) : image_for(identifier.clone)
392
461
  end
462
+ define_method("#{name}?") do
463
+ return call_block(&block) if block_given?
464
+ image_for(identifier.clone).exist?
465
+ end
393
466
  alias_method "#{name}_image".to_sym, "#{name}_element".to_sym
394
467
  end
468
+
395
469
  #
396
- # adds a method to retrieve the form element
470
+ # adds two methods - one to retrieve the form element, and another to
471
+ # check the form's existence.
397
472
  #
398
473
  # @example
399
474
  # form(:login, :id => 'login')
400
- # # will generate a 'login_element' method
475
+ # # will generate 'login_element' and 'login?' methods
401
476
  #
402
477
  # @param [String] the name used for the generated methods
403
478
  # @param [Hash] identifier how we find a form. The valid keys are:
@@ -414,15 +489,21 @@ module Druid
414
489
  form_for(identifier.clone)
415
490
  # block ? call_block(&block) : form_for(identifier.clone)
416
491
  end
492
+ define_method("#{name}?") do
493
+ return call_block(&block) if block_given?
494
+ form_for(identifier.clone).exist?
495
+ end
417
496
  alias_method "#{name}_form".to_sym, "#{name}_element".to_sym
418
497
  end
498
+
419
499
  #
420
- # adds two methods to the page object - one to get the text from a hidden field
421
- # and another to retrieve the hidden field element.
500
+ # adds three methods to the page object - one to get the text from a hidden field,
501
+ # another to retrieve the hidden field element, and another to check the hidden
502
+ # field's existence.
422
503
  #
423
504
  # @example
424
505
  # hidden_field(:user_id, :id => "user_identity")
425
- # # will generate 'user_id' and 'user_id_element' methods
506
+ # # will generate 'user_id', 'user_id_element' and 'user_id?' methods
426
507
  #
427
508
  # @param [String] the name used for the generated methods
428
509
  # @param [Hash] identifier how we find a hidden field. The valid keys are:
@@ -446,15 +527,21 @@ module Druid
446
527
  return hidden_field_value_for identifier.clone unless block_given?
447
528
  self.send("#{name}_element").value
448
529
  end
530
+ define_method("#{name}?") do
531
+ return call_block(&block) if block_given?
532
+ hidden_field_for(identifier.clone).exist?
533
+ end
449
534
  alias_method "#{name}_hidden_field".to_sym, "#{name}_element".to_sym
450
535
  end
536
+
451
537
  #
452
- # adds two methods - one to retrieve the text from a list item
453
- # and another to return the list item element
538
+ # adds three methods - one to retrieve the text from a list item,
539
+ # another to return the list item element, and another to check the list item's
540
+ # existence.
454
541
  #
455
542
  # @example
456
543
  # list_item(:item_one, :id => 'one')
457
- # # will generate 'item_one' and 'item_one_element' methods
544
+ # # will generate 'item_one', 'item_one_element', and 'item_one?' methods
458
545
  #
459
546
  # @param [String] the name used for the generated methods
460
547
  # @param [Hash] identifier how we find a list item. The valid keys are:
@@ -474,14 +561,20 @@ module Druid
474
561
  list_item_for(identifier.clone)
475
562
  # block ? call_block(&block) : list_item_for(identifier.clone)
476
563
  end
564
+ define_method("#{name}?") do
565
+ return call_block(&block) if block_given?
566
+ list_item_for(identifier.clone).exist?
567
+ end
477
568
  alias_method "#{name}_list_item".to_sym, "#{name}_element".to_sym
478
569
  end
570
+
479
571
  #
480
- # adds a method to retrieve the ordered list element
572
+ # adds two methods - one to retrieve the ordered list element, and another to
573
+ # test it's existence.
481
574
  #
482
575
  # @example
483
576
  # ordered_list(:top_five, :id => 'top')
484
- # # will generate a 'top_five_element' method
577
+ # # will generate 'top_five_element' and 'top_five?' methods
485
578
  #
486
579
  # @param [String] the name used for the generated methods
487
580
  # @param [Hash] identifier how we find an ordered list. The valid keys are:
@@ -497,16 +590,22 @@ module Druid
497
590
  ordered_list_for(identifier.clone)
498
591
  # block ? call_block(&block) : ordered_list_for(identifier.clone)
499
592
  end
593
+ define_method("#{name}?") do
594
+ return call_block(&block) if block_given?
595
+ ordered_list_for(identifier.clone).exist?
596
+ end
500
597
  alias_method "#{name}_ordered_list".to_sym, "#{name}_element".to_sym
501
598
  end
599
+
502
600
  #
503
- # adds three methods to the page object - one to set text in a text area,
504
- # another to retrieve text from a text area and another to return the text
505
- # area element.
601
+ # adds four methods to the page object - one to set text in a text area,
602
+ # another to retrieve text from a text area, another to return the text
603
+ # area element, and another to check the text area's existence.
506
604
  #
507
605
  # @example
508
606
  # text_area(:address, :id => "address")
509
- # # will generate 'address', 'address=' and 'address_element' methods
607
+ # # will generate 'address', 'address=', 'address_element',
608
+ # # 'address?' methods
510
609
  #
511
610
  # @param [String] the name used for the generated methods
512
611
  # @param [Hash] identifier how we find a text area. The valid keys are:
@@ -532,14 +631,20 @@ module Druid
532
631
  text_area_for(identifier.clone)
533
632
  # block ? call_block(&block) : text_area_for(identifier.clone)
534
633
  end
634
+ define_method("#{name}?") do
635
+ return call_block(&block) if block_given?
636
+ text_area_for(identifier.clone).exist?
637
+ end
535
638
  alias_method "#{name}_text_area".to_sym, "#{name}_element".to_sym
536
639
  end
640
+
537
641
  #
538
- # adds a method to retrieve the unordered list element
642
+ # adds two methods - one to retrieve the unordered list element, and another to
643
+ # check it's existence.
539
644
  #
540
645
  # @example
541
646
  # unordered_list(:menu, :id => 'main_menu')
542
- # # will generate a 'menu_element' method
647
+ # # will generate 'menu_element' and 'menu?' methods
543
648
  #
544
649
  # @param [String] the name used for the generated methods
545
650
  # @param [Hash] identifier how we find an unordered list. The valid keys are:
@@ -555,15 +660,20 @@ module Druid
555
660
  unordered_list_for(identifier.clone)
556
661
  # block ? call_block(&block) : unordered_list_for(identifier.clone)
557
662
  end
663
+ define_method("#{name}?") do
664
+ return call_block(&block) if block_given?
665
+ unordered_list_for(identifier.clone).exist?
666
+ end
558
667
  alias_method "#{name}_unordered_list".to_sym, "#{name}_element".to_sym
559
668
  end
560
669
 
561
670
  #
562
- # adds a method to retrieve the text of a h1 and a h1 element
671
+ # adds three methods - one to retrieve the text of a h1 element, another to
672
+ # retrieve a h1 element, and another to check for it's existence.
563
673
  #
564
674
  # @example
565
675
  # h1(:title, :id => 'title')
566
- # # will generate a 'title' and 'title_element' method
676
+ # # will generate 'title', 'title_element', and 'title?' methods
567
677
  #
568
678
  # @param [String] the name used for the generated methods
569
679
  # @param [Hash] identifier how we find a H1. You can use a multiple paramaters
@@ -584,15 +694,20 @@ module Druid
584
694
  return call_block(&block) if block_given?
585
695
  h1_for(identifier.clone)
586
696
  end
697
+ define_method("#{name}?") do
698
+ return call_block(&block) if block_given?
699
+ h1_for(identifier.clone).exist?
700
+ end
587
701
  alias_method "#{name}_h1".to_sym, "#{name}_element".to_sym
588
702
  end
589
703
 
590
704
  #
591
- # adds a method to retrieve the text of a h2 and a h2 element
705
+ # adds three methods - one to retrieve the text of a h2 element, another
706
+ # to retrieve a h2 element, and another to check for it's existence.
592
707
  #
593
708
  # @example
594
709
  # h2(:title, :id => 'title')
595
- # # will generate a 'title' and 'title_element' method
710
+ # # will generate 'title', 'title_element', and 'title?' methods
596
711
  #
597
712
  # @param [String] the name used for the generated methods
598
713
  # @param [Hash] identifier how we find a H2. You can use a multiple paramaters
@@ -613,15 +728,20 @@ module Druid
613
728
  return call_block(&block) if block_given?
614
729
  h2_for(identifier.clone)
615
730
  end
731
+ define_method("#{name}?") do
732
+ return call_block(&block) if block_given?
733
+ h2_for(identifier.clone).exist?
734
+ end
616
735
  alias_method "#{name}_h2".to_sym, "#{name}_element".to_sym
617
736
  end
618
737
 
619
738
  #
620
- # adds a method to retrieve the text of a h3 and a h3 element
739
+ # adds three methods - one to retrieve the text of a h3 element,
740
+ # another to return a h3 element, and another to check for it's existence.
621
741
  #
622
742
  # @example
623
743
  # h3(:title, :id => 'title')
624
- # # will generate a 'title' and 'title_element' method
744
+ # # will generate 'title', 'title_element', and 'title?' methods
625
745
  #
626
746
  # @param [String] the name used for the generated methods
627
747
  # @param [Hash] identifier how we find a H3. You can use a multiple paramaters
@@ -642,15 +762,20 @@ module Druid
642
762
  return call_block(&block) if block_given?
643
763
  h3_for(identifier.clone)
644
764
  end
765
+ define_method("#{name}?") do
766
+ return call_block(&block) if block_given?
767
+ h3_for(identifier.clone).exist?
768
+ end
645
769
  alias_method "#{name}_h3".to_sym, "#{name}_element".to_sym
646
770
  end
647
771
 
648
772
  #
649
- # adds a method to retrieve the text of a h4 and a h4 element
773
+ # adds three methods - one to retrieve the text of a h4 element,
774
+ # another to return a h4 element, and another to check for it's existence.
650
775
  #
651
776
  # @example
652
777
  # h4(:title, :id => 'title')
653
- # # will generate a 'title' and 'title_element' method
778
+ # # will generate 'title', 'title_element', and 'title?' methods
654
779
  #
655
780
  # @param [String] the name used for the generated methods
656
781
  # @param [Hash] identifier how we find a H4. You can use a multiple paramaters
@@ -671,15 +796,20 @@ module Druid
671
796
  return call_block(&block) if block_given?
672
797
  h4_for(identifier.clone)
673
798
  end
799
+ define_method("#{name}?") do
800
+ return call_block(&block) if block_given?
801
+ h4_for(identifier.clone).exist?
802
+ end
674
803
  alias_method "#{name}_h4".to_sym, "#{name}_element".to_sym
675
804
  end
676
805
 
677
806
  #
678
- # adds a method to retrieve the text of a h5 and a h5 element
807
+ # adds three methods - one to retrieve the text of a h5 element,
808
+ # another to return a h5 element, and another to check for it's existence.
679
809
  #
680
810
  # @example
681
811
  # h5(:title, :id => 'title')
682
- # # will generate a 'title' and 'title_element' method
812
+ # # will generate 'title', 'title_element', and 'title?' methods
683
813
  #
684
814
  # @param [String] the name used for the generated methods
685
815
  # @param [Hash] identifier how we find a H5. You can use a multiple paramaters
@@ -700,15 +830,20 @@ module Druid
700
830
  return call_block(&block) if block_given?
701
831
  h5_for(identifier.clone)
702
832
  end
833
+ define_method("#{name}?") do
834
+ return call_block(&block) if block_given?
835
+ h5_for(identifier.clone).exist?
836
+ end
703
837
  alias_method "#{name}_h5".to_sym, "#{name}_element".to_sym
704
838
  end
705
839
 
706
840
  #
707
- # adds a method to retrieve the text of a h6 and a h6 element
841
+ # adds three methods - one to retrieve the text of a h6 element,
842
+ # another to return a h6 element, and another to check for it's existence.
708
843
  #
709
844
  # @example
710
845
  # h6(:title, :id => 'title')
711
- # # will generate a 'title' and 'title_element' method
846
+ # # will generate 'title', 'title_element', and 'title?' methods
712
847
  #
713
848
  # @param [String] the name used for the generated methods
714
849
  # @param [Hash] identifier how we find a H6. You can use a multiple paramaters
@@ -729,15 +864,20 @@ module Druid
729
864
  return call_block(&block) if block_given?
730
865
  h6_for(identifier.clone)
731
866
  end
867
+ define_method("#{name}?") do
868
+ return call_block(&block) if block_given?
869
+ h6_for(identifier.clone).exist?
870
+ end
732
871
  alias_method "#{name}_h6".to_sym, "#{name}_element".to_sym
733
872
  end
734
873
 
735
874
  #
736
- # adds a method to retrieve the text of a paragraph and a paragraph element
875
+ # adds three methods - one to retrieve the text of a paragraph, another
876
+ # to retrieve a paragraph element, and another to check the paragraph's existence.
737
877
  #
738
878
  # @example
739
879
  # paragraph(:title, :id => 'title')
740
- # # will generate a 'title' and 'title_element' method
880
+ # # will generate 'title', 'title_element', and 'title?' methods
741
881
  #
742
882
  # @param [String] the name used for the generated methods
743
883
  # @param [Hash] identifier how we find a paragraph. You can use a multiple paramaters
@@ -758,16 +898,20 @@ module Druid
758
898
  return call_block(&block) if block_given?
759
899
  paragraph_for(identifier.clone)
760
900
  end
901
+ define_method("#{name}?") do
902
+ return call_block(&block) if block_given?
903
+ paragraph_for(identifier.clone).exist?
904
+ end
761
905
  alias_method "#{name}_paragraph".to_sym, "#{name}_element".to_sym
762
906
  end
763
907
 
764
908
  #
765
- # adds a method to set the file for a file field and to retrieve
766
- # the file field element
909
+ # adds three methods - one to set the file for a file field, another to retrieve
910
+ # the file field element, and another to check it's existence.
767
911
  #
768
912
  # @example
769
913
  # file_field(:the_file, :id => 'file_to_upload')
770
- # # will generate a 'the_file=' and 'the_file_element' method
914
+ # # will generate 'the_file=', 'the_file_element', and 'the_file?' methods
771
915
  #
772
916
  # @param [String] the name used for the generated methods
773
917
  # @param [Hash] identifier how we find a file_field. You can use a multiple paramaters
@@ -789,6 +933,10 @@ module Druid
789
933
  return call_block(&block) if block_given?
790
934
  file_field_for(identifier.clone)
791
935
  end
936
+ define_method("#{name}?") do
937
+ return call_block(&block) if block_given?
938
+ file_field_for(identifier.clone).exist?
939
+ end
792
940
  end
793
941
  end
794
942
  end