domino 0.9.0 → 0.10.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: 3059a81fc3233b83f748c35d895915d477778062
4
- data.tar.gz: 5ba1c3b35b0b12919712ad789dd3a50d8b4d2fea
3
+ metadata.gz: ef317e23fa5c56cda925292542b5c21a9427da0f
4
+ data.tar.gz: 8569c3441566aa337bbf547f21e51f6b426c9fd1
5
5
  SHA512:
6
- metadata.gz: 629bc9d4a700d9161ba1cc46953556fb42ad6d447a5d90ee64a5d410eb416a6095ef57c9a5bf94dd96ba664d335a4e095ee4e245fec6c69298aa4211672d0e84
7
- data.tar.gz: 9edb66f4135a320f85836e9e2c04af3f8eee8245cf8ea6c040e96da86fdf1ac30139c27c61be933bdfe63b83467b15a160ddc538a189c133207cbe1e2cfbb104
6
+ metadata.gz: 221ce20550753d6e51b23785aa9bda36ff4ccb7cc6a6f800bdec24a021e0f820bcdc0cfeb4ab632722306c5fc75806d68e3cc115d0891b14ed0be56db9b9059c
7
+ data.tar.gz: 63ab29831e4b94ab7c8cf94356de7f4ff2ab58dde5e15fe2406a08eb853ef089c0cd7a2833609c8ae9fd1ca18dcf3b63310f4acfc761c15f21be1141daa2a6f0
data/README.md CHANGED
@@ -168,6 +168,27 @@ end
168
168
  Provide your custom class using the `:as` option when defining your field,
169
169
  as shown in the example above.
170
170
 
171
+ ### Accessing the Attribute/Field Node
172
+
173
+ The named accessor method for any field or attribute will yield the Capybara
174
+ node of the attribute if you pass a block. You can use this to check
175
+ certain properties of the node without having to break out of your Dominos.
176
+
177
+ **Example:** Checking available options in a select field
178
+
179
+ ```ruby
180
+ person = Dom::PersonForm.find!
181
+ expected_options = ["- Select a Color -", "Red", "Blue", "Green"]
182
+ assert_equal expected_options, person.favorite_color { |n| n.all('option').map(&:text) }
183
+ ```
184
+
185
+ **Example:** Checking the tag of the node containing the attribute value
186
+
187
+ ```ruby
188
+ person = Dom::Person.find_by!(uuid: "e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f")
189
+ assert_equal "h2", person.name { |n| n.tag_name }
190
+ ```
191
+
171
192
  ## Integration with capybara
172
193
 
173
194
  Domino uses capybara internally to search html for nodes and
data/domino.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "domino"
4
- gem.version = "0.9.0"
4
+ gem.version = "0.10.0"
5
5
  gem.platform = Gem::Platform::RUBY
6
6
  gem.authors = ["Nick Gauthier"]
7
7
  gem.email = ["ngauthier@gmail.com"]
@@ -34,6 +34,14 @@ class Domino::Attribute
34
34
  value === value(node)
35
35
  end
36
36
 
37
+ def element(node)
38
+ if combinator?
39
+ node
40
+ else
41
+ node.find(selector)
42
+ end
43
+ end
44
+
37
45
  private
38
46
 
39
47
  def combinator?
@@ -12,8 +12,7 @@ class Domino::Form::Field
12
12
  # Delete any options for your field type that shouldn't be passed to
13
13
  # the field locator.
14
14
  # Default: noop
15
- def extract_field_options
16
- end
15
+ def extract_field_options; end
17
16
 
18
17
  # Convert the value from `#read` via callback if provided.
19
18
  def value(node)
@@ -2,7 +2,7 @@ class Domino::Form::SelectField < Domino::Form::Field
2
2
  # Returns the set of selected options that can be processed in the callback.
3
3
  def read(node)
4
4
  s = field(node)
5
- selected = s.all("option[selected]")
5
+ selected = s.all('option[selected]')
6
6
  s.multiple? ? selected : selected.first
7
7
  end
8
8
 
data/lib/domino/form.rb CHANGED
@@ -39,8 +39,12 @@ class Domino::Form < Domino
39
39
 
40
40
  field_definitions[attribute] = field_class.new(attribute, locator, options, &callback)
41
41
 
42
- define_method :"#{attribute}" do
43
- self.class.field_definitions[attribute].value(node)
42
+ define_method :"#{attribute}" do |&block|
43
+ if block.is_a?(Proc)
44
+ block.call(self.class.field_definitions[attribute].field(node))
45
+ else
46
+ self.class.field_definitions[attribute].value(node)
47
+ end
44
48
  end
45
49
 
46
50
  define_method :"#{attribute}=" do |value|
data/lib/domino.rb CHANGED
@@ -138,8 +138,12 @@ class Domino
138
138
 
139
139
  attribute_definitions[attribute] = Attribute.new(attribute, selector, &callback)
140
140
 
141
- define_method :"#{attribute}" do
142
- self.class.attribute_definitions[attribute].value(node)
141
+ define_method :"#{attribute}" do |&block|
142
+ if block.is_a?(Proc)
143
+ block.call(self.class.attribute_definitions[attribute].element(node))
144
+ else
145
+ self.class.attribute_definitions[attribute].value(node)
146
+ end
143
147
  end
144
148
 
145
149
  define_singleton_method :"find_by_#{attribute}" do |value|
@@ -187,14 +187,14 @@ class DominoFormTest < Minitest::Test
187
187
  end
188
188
 
189
189
  def test_static_create_with_no_matches
190
- visit "/"
190
+ visit '/'
191
191
  assert_raises Capybara::ElementNotFound do
192
192
  Dom::PersonForm.create name: 'Marie', last_name: 'Curie'
193
193
  end
194
194
  end
195
195
 
196
196
  def test_static_update_with_no_matches
197
- visit "/"
197
+ visit '/'
198
198
  assert_raises Capybara::ElementNotFound do
199
199
  Dom::PersonForm.update name: 'Marie', last_name: 'Curie'
200
200
  end
@@ -203,4 +203,16 @@ class DominoFormTest < Minitest::Test
203
203
  def test_supports_normal_attributes
204
204
  assert_equal({ action: '/people/23', submit_method: 'post' }, Dom::PersonForm.find!.attributes)
205
205
  end
206
+
207
+ def test_named_field_method_yields_node
208
+ person = Dom::PersonForm.find!
209
+ name_field_node = page.find_field('First Name')
210
+ assert_equal(name_field_node, person.name { |node| node })
211
+ person.name { |node| node }
212
+ end
213
+
214
+ def test_named_field_yield_usefulness
215
+ person = Dom::PersonForm.find!
216
+ assert_equal ['- Select a Color -', 'Red', 'Blue', 'Green'], person.favorite_color { |n| n.all('option').map(&:text) }
217
+ end
206
218
  end
data/test/domino_test.rb CHANGED
@@ -188,4 +188,21 @@ class DominoTest < Minitest::Test
188
188
  Dom::NoSelector.where(foo: 'bar')
189
189
  end
190
190
  end
191
+
192
+ def test_named_field_method_yields_node
193
+ person = Dom::Person.find_by!(uuid: 'e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f')
194
+ name_node = page.find(".person[data-uuid='e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f'] .name")
195
+ assert_equal(name_node, person.name { |node| node })
196
+ end
197
+
198
+ def test_named_field_method_yields_node_when_combinator
199
+ person = Dom::Person.find_by!(uuid: 'e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f')
200
+ uuid_node = page.find(".person[data-uuid='e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f']")
201
+ assert_equal(uuid_node, person.uuid { |node| node })
202
+ end
203
+
204
+ def test_named_field_yield_usefulness
205
+ person = Dom::Person.find_by!(uuid: 'e94bb2d3-71d2-4efb-abd4-ebc0cb58d19f')
206
+ assert_equal 'h2', person.name(&:tag_name)
207
+ end
191
208
  end
@@ -22,7 +22,7 @@ class TestApplication
22
22
  edit params
23
23
  when '/people/23'
24
24
  params = Rack::Utils.parse_nested_query(env.fetch('rack.input').read)
25
- edit params.merge(flash: "Person updated successfully.")
25
+ edit params.merge(flash: 'Person updated successfully.')
26
26
  end
27
27
  end
28
28
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Gauthier