dill 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14cc24cbf9c3bf17b0c28cb0b79f2478ee23ca84
4
- data.tar.gz: 02ec3456de6a2b0b39788fe39d95676d90507bb7
3
+ metadata.gz: 9e51865a645c651a3eae6d77230e52f18a9b37a9
4
+ data.tar.gz: 9d5395859b6c729d7c94738e596beb0ab5857d04
5
5
  SHA512:
6
- metadata.gz: 9fc8dfb00b1031f177cc34c32b973b72386bd29cb06c3aaf104001bb720b648fc02a65b1a7021ee637aee489ba09374ba063618836fe24f4902903ee6b475a39
7
- data.tar.gz: a1595c25983178de326f53b3c37be841741242a36dcfee677103251e0bc20102784c83592791db4e050ff7053de4cc85581a35b8b26cdbc16907ae5ed509c28b
6
+ metadata.gz: 55bd0b55b84a05b7a7e2875505c34be44f3b9b3d461899c09324380e71909d393999348df79a5e9de9b73dbcd3bb683098410d41b121c6972903d70ecd6cf1f2
7
+ data.tar.gz: acf82c3c0f3515d6970407045eda8224143a4484826ea437a37d38569aa0b61aeb5a0f960cd4412589f87b3882dae4266ec74b6f591eb507a28546eaa519edec
@@ -20,6 +20,7 @@ module Dill
20
20
  class MissingWidget < StandardError; end
21
21
  class AmbiguousWidget < StandardError; end
22
22
  class InvalidOption < StandardError; end
23
+ class InvalidRadioButton < StandardError; end
23
24
 
24
25
  def deprecate(method, alternate_method, once=false)
25
26
  @deprecation_notified ||= {}
@@ -22,6 +22,16 @@ module Dill
22
22
  widget(name, *args).hover
23
23
  end
24
24
 
25
+ # Double clicks the widget defined by +name+ and optional +args+.
26
+ def double_click(name, *args)
27
+ widget(name, *args).double_click
28
+ end
29
+
30
+ # Right clicks the widget defined by +name+ and optional +args+.
31
+ def right_click(name, *args)
32
+ widget(name, *args).right_click
33
+ end
34
+
25
35
  # @return [Document] the current document with the class of the
26
36
  # current object set as the widget lookup scope.
27
37
  def document
@@ -1,3 +1,3 @@
1
1
  module Dill
2
- VERSION = '0.8.1'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -51,6 +51,7 @@ require 'dill/widgets/list_item'
51
51
  require 'dill/widgets/list'
52
52
  require 'dill/widgets/field'
53
53
  require 'dill/widgets/check_box'
54
+ require 'dill/widgets/radio_button'
54
55
  require 'dill/widgets/select'
55
56
  require 'dill/widgets/text_field'
56
57
  require 'dill/widgets/field_group'
@@ -9,5 +9,11 @@ module Dill
9
9
  def root
10
10
  Capybara.current_session
11
11
  end
12
+
13
+ def body
14
+ xml = Nokogiri::HTML(Capybara.page.body).to_xml
15
+
16
+ Nokogiri::XML(xml, &:noblanks).to_xhtml
17
+ end
12
18
  end
13
19
  end
@@ -174,6 +174,68 @@ module Dill
174
174
  end
175
175
  end
176
176
 
177
+ # Creates a new radio button group accessor.
178
+ #
179
+ # Adds the following methods to the widget:
180
+ #
181
+ # <name>:: Gets the text of the current checked button, or +nil+,
182
+ # if no button is checked.
183
+ # <name>_value:: Gets the value of the current checked button, or +nil+,
184
+ # if no button is checked.
185
+ # <name>=:: Checks a button in the current container. Pass the text of
186
+ # the label or the id or value of the button you want to choose.
187
+ #
188
+ # @example
189
+ # # Given the following HTML:
190
+ # #
191
+ # # <form>
192
+ # # <p class='checked'>
193
+ # # <label for="checked">Checked button</label>
194
+ # # <input type="radio" id="checked" name="c" value="checked_value" checked>
195
+ # # <label for="checked_two">Checked button two</label>
196
+ # # <input type="radio" id="checked_two" name="c" value="checked_two_value">
197
+ # # </p>
198
+ # # <p class='unchecked'>
199
+ # # <label for="unchecked">Unchecked button</label>
200
+ # # <input type="radio" id="unchecked" name="u" value="unchecked_value_one">
201
+ # # <label for="unchecked_two">Unchecked button two</label>
202
+ # # <input type="radio" id="unchecked_two" name="u" value="unchecked_value_two">
203
+ # # </p>
204
+ # # </form>
205
+ # class MyFieldGroup < Dill::FieldGroup
206
+ # root 'form'
207
+ #
208
+ # radio_button :checked, '.checked'
209
+ # radio_button :unchecked, '.unchecked'
210
+ # end
211
+ #
212
+ # form = widget(:my_field_group)
213
+ #
214
+ # form.checked #=> "Checked button"
215
+ # form.unchecked #=> nil
216
+ #
217
+ # form.unchecked = "Unchecked button" # Choose by label text
218
+ # form.unchecked #=> "Unchecked button"
219
+ # form.unchecked_value #=> "unchecked_value_one"
220
+ #
221
+ # form.unchecked = "unchecked_two" # Choose by id
222
+ # form.unchecked #=> "Unchecked button two"
223
+ # form.unchecked_value #=> "unchecked_value_two"
224
+ #
225
+ # form.unchecked = "unchecked_value_one" # Choose by value
226
+ # form.unchecked #=> "Unchecked button"
227
+ #
228
+ # @param name the name of the radio_button group accessor.
229
+ # @param locator the locator for the radio_button group.
230
+ #
231
+ def self.radio_button(name, locator = nil)
232
+ field name, locator, RadioButton
233
+
234
+ define_method "#{name}_value" do
235
+ widget(name).value
236
+ end
237
+ end
238
+
177
239
  # Creates a new text field accessor.
178
240
  #
179
241
  # Adds the following methods to the widget:
@@ -0,0 +1,62 @@
1
+ module Dill
2
+ # A radio button.
3
+ class RadioButton < Field
4
+ widget :checked, -> {
5
+ case Capybara.current_driver
6
+ when :rack_test
7
+ ['[checked]']
8
+ else
9
+ ['input:checked']
10
+ end
11
+ }
12
+ widget :checked_label_by_value, -> (val) { [:xpath, ".//label[input[@type='radio' and @value='#{val}']]"] }
13
+ widget :checked_label_by_id, -> (id) { [:xpath, ".//label[@for='#{id}']"] }
14
+ widget :button_by_value, -> (val) { "[value='#{val}']" }
15
+
16
+ def self.root(selector)
17
+ super(["#{selector}"])
18
+ end
19
+
20
+ # @return [String] The text of the checked button's label.
21
+ def get
22
+ if visible?(:checked_label_by_value, value)
23
+ widget(:checked_label_by_value, value).text
24
+ elsif visible?(:checked_label_by_id, id)
25
+ widget(:checked_label_by_id, id).text
26
+ else
27
+ nil
28
+ end
29
+ end
30
+
31
+ # @return [String] The value of the checked button.
32
+ def value
33
+ visible?(:checked) ? widget(:checked).root.value : nil
34
+ end
35
+
36
+ # @return [String] The id of the checked button.
37
+ def id
38
+ visible?(:checked) ? widget(:checked).id : nil
39
+ end
40
+
41
+ # First attempts to choose the button by id or label text
42
+ # Then attempts to choose the button by value
43
+ def set(str)
44
+ root.choose(str)
45
+ rescue
46
+ begin
47
+ widget(:button_by_value, str).root.set(true)
48
+ rescue Dill::MissingWidget => e
49
+ raise InvalidRadioButton.new(e.message).
50
+ tap { |x| x.set_backtrace e.backtrace }
51
+ end
52
+ end
53
+
54
+ # @return the text of the checked button, or an empty string if
55
+ # no button is checked.
56
+ def_delegator :get, :to_s
57
+
58
+ def to_cell
59
+ get
60
+ end
61
+ end
62
+ end
@@ -268,6 +268,60 @@ module Dill
268
268
  end
269
269
  end
270
270
 
271
+ # Double clicks the current widget, or the child widget given by +name+.
272
+ #
273
+ # === Usage
274
+ #
275
+ # Given the following widget definition:
276
+ #
277
+ # class Container < Dill::Widget
278
+ # root '#container'
279
+ #
280
+ # widget :link, 'a'
281
+ # end
282
+ #
283
+ # Send +double_click+ with no arguments to trigger an +ondblclick+ event on +#container+.
284
+ #
285
+ # widget(:container).double_click
286
+ #
287
+ # This is the equivalent of doing the following using Capybara:
288
+ #
289
+ # find('#container').double_click
290
+ def double_click(*args)
291
+ if args.empty?
292
+ root.double_click
293
+ else
294
+ widget(*args).double_click
295
+ end
296
+ end
297
+
298
+ # Right clicks the current widget, or the child widget given by +name+.
299
+ #
300
+ # === Usage
301
+ #
302
+ # Given the following widget definition:
303
+ #
304
+ # class Container < Dill::Widget
305
+ # root '#container'
306
+ #
307
+ # widget :link, 'a'
308
+ # end
309
+ #
310
+ # Send +right_click+ with no arguments to trigger an +oncontextmenu+ event on +#container+.
311
+ #
312
+ # widget(:container).right_click
313
+ #
314
+ # This is the equivalent of doing the following using Capybara:
315
+ #
316
+ # find('#container').right_click
317
+ def right_click(*args)
318
+ if args.empty?
319
+ root.right_click
320
+ else
321
+ widget(*args).right_click
322
+ end
323
+ end
324
+
271
325
  # Determines if the widget underlying an action exists.
272
326
  #
273
327
  # @param name the name of the action
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Leal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-16 00:00:00.000000000 Z
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec-given
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -201,6 +215,7 @@ files:
201
215
  - lib/dill/widgets/list_item.rb
202
216
  - lib/dill/widgets/parts/container.rb
203
217
  - lib/dill/widgets/parts/struct.rb
218
+ - lib/dill/widgets/radio_button.rb
204
219
  - lib/dill/widgets/select.rb
205
220
  - lib/dill/widgets/string_value.rb
206
221
  - lib/dill/widgets/table.rb