domino 0.6.0 → 0.7.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: 554cc2cc550cceacec189b1fcab208a2f530c3b4
4
- data.tar.gz: 65dd95a5af9bfa19e04e38e3821cb016e01c8594
3
+ metadata.gz: 668a5c9b60cd2400258480a45f70444913a6c776
4
+ data.tar.gz: 411bee6d727404291237bd9fa7e286371f413cc4
5
5
  SHA512:
6
- metadata.gz: 98a53738194cc39ab9734ceeb69209735f84bb7bec6c06f672b6243556bc4d18fa272b7d5a682ac3fc6264b086eb4b2f09dbc9fd0473b46c09575f0096e0f8e0
7
- data.tar.gz: a65293c01ae787bc2df87372ad30b88d7f4b50a20156993e6d501493715e8ffd588e7f366ecec01d646eabdf76ea64466008a4cf8e8c610174e173c76ee7cd6a
6
+ metadata.gz: 4de9f8704851ef5e0f2891f44218db61022a65ec6a1bf11278fb966286a38df418f14b554992614436df2b310674ad454db7eac2aac43fb0ef8f038d69ca6256
7
+ data.tar.gz: 8812d350512383ba7b3503b3e9d2644e14f81215217caad816120a4ddb3ee106afc4884185f1cf255a6e82189e52a23f0ff29726c1a26bbf06767d597164f215
data/README.md CHANGED
@@ -7,42 +7,57 @@ View abstraction for integration testing
7
7
  To create a basic Domino class, inherit from Domino and
8
8
  define a selector and attributes:
9
9
 
10
- module Dom
11
- class Post < Domino
12
- selector '#posts .post'
13
- attribute :title # selector defaults to .title
14
- attribute :author_name # selector defaults to .author-name
15
- attribute :body, '.post-body' # example of selector override
16
-
17
- # pass a block if you want to modify the value
18
- attribute :comments do |text|
19
- text.to_i
20
- end
21
-
22
- attribute :posted_at do |text|
23
- Date.parse(text)
24
- end
25
- end
10
+ ```ruby
11
+ module Dom
12
+ class Post < Domino
13
+ selector '#posts .post'
14
+ attribute :title # selector defaults to .title
15
+ attribute :author_name # selector defaults to .author-name
16
+ attribute :body, '.post-body' # example of selector override
17
+
18
+ # pass a block if you want to modify the value
19
+ attribute :comments do |text|
20
+ text.to_i
26
21
  end
27
22
 
23
+ attribute :posted_at do |text|
24
+ Date.parse(text)
25
+ end
26
+ end
27
+ end
28
+ ```
29
+
28
30
  Now in your integration test you can use some of Domino's methods:
29
31
 
30
- assert_equal 4, Dom::Post.count
31
- refute_nil Dom::Post.find_by_title('First Post')
32
+ ```ruby
33
+ assert_equal 4, Dom::Post.count
34
+ refute_nil Dom::Post.find_by_title('First Post')
35
+
36
+ # Multiple attributes, returns first match if any
37
+ refute_nil Dom::Post.find_by(title: 'First Post', author: 'Jane Doe')
38
+
39
+ # Multiple attributes with exception if no match is found
40
+ refute_nil Dom::Post.find_by!(title: 'First Post', author: 'Jane Doe')
41
+
42
+ # Multiple attributes, returns all matches if any
43
+ assert_equal ["12/06/2014", "12/01/2014"], Dom::Post.where(author: 'Jane Doe').map(&:posted_on)
44
+ ```
32
45
 
33
46
  What makes it really powerful is defining scoped actions:
34
47
 
35
- module Dom
36
- class Post < Domino
37
- def delete
38
- within(id) { click_button 'Delete' }
39
- end
40
- end
48
+ ```ruby
49
+ module Dom
50
+ class Post < Domino
51
+ def delete
52
+ within(id) { click_button 'Delete' }
41
53
  end
54
+ end
55
+ end
42
56
 
43
- refute_nil Dom::Post.find_by_title('First Post')
44
- Dom::Post.find_by_title('First Post').delete
45
- assert_nil Dom::Post.find_by_title('First Post')
57
+ refute_nil Dom::Post.find_by_title('First Post')
58
+ Dom::Post.find_by_title('First Post').delete
59
+ assert_nil Dom::Post.find_by_title('First Post')
60
+ ```
46
61
 
47
62
  ## Integration with capybara
48
63
 
@@ -50,15 +65,17 @@ Domino uses capybara internally to search html for nodes and
50
65
  attributes. If you need to do something special, you can have direct
51
66
  access to the capybara node.
52
67
 
53
- module Dom
54
- class Account < Domino
55
- selector "#accounts li"
56
- # Returns this node text
57
- def text
58
- node.text
59
- end
60
- end
68
+ ```ruby
69
+ module Dom
70
+ class Account < Domino
71
+ selector "#accounts li"
72
+ # Returns this node text
73
+ def text
74
+ node.text
61
75
  end
76
+ end
77
+ end
78
+ ```
62
79
 
63
80
  For more information about using Capybara nodes, check [Capybara Documentation](https://github.com/jnicklas/capybara/blob/master/README.rdoc).
64
81
 
@@ -69,12 +86,16 @@ necessary to wait for elements to appear. Note that the following code
69
86
  simply collects all `Account` dominos currently on the page and
70
87
  returns the first:
71
88
 
72
- Dom::Account.first # returns nil if account is displayed asynchronously
89
+ ```ruby
90
+ Dom::Account.first # returns nil if account is displayed asynchronously
91
+ ```
73
92
 
74
93
  When you are waiting for a unique domino to appear, you can instead
75
94
  use the `find!` method:
76
95
 
77
- Dom::Account.find! # waits for matching element to appear
96
+ ```ruby
97
+ Dom::Account.find! # waits for matching element to appear
98
+ ```
78
99
 
79
100
  If no matching element appears, Capybara will raise an error telling
80
101
  you about the expected selector. Depending on the
@@ -91,7 +112,9 @@ Use them in your steps.
91
112
 
92
113
  Include "domino" in your Gemfile if using bundler, or simply
93
114
 
94
- require 'domino'
115
+ ```ruby
116
+ require 'domino'
117
+ ```
95
118
 
96
119
  If you're not using Bundler.
97
120
 
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.6.0"
4
+ gem.version = "0.7.0"
5
5
  gem.platform = Gem::Platform::RUBY
6
6
  gem.authors = ["Nick Gauthier"]
7
7
  gem.email = ["ngauthier@gmail.com"]
data/lib/domino.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'capybara/dsl'
2
+ require 'set'
2
3
  # To create a basic Domino class, inherit from Domino and
3
4
  # define a selector and attributes:
4
5
  #
@@ -65,12 +66,29 @@ class Domino
65
66
  # support asynchronous behavior, this method waits for a matching
66
67
  # node to appear.
67
68
  def find!
68
- if @selector.nil?
69
- raise Domino::Error.new("You must define a selector")
70
- end
69
+ require_selector!
71
70
  new(Capybara.current_session.find(@selector))
72
71
  end
73
72
 
73
+ # Returns Domino for capybara node matching all attributes.
74
+ def find_by(attributes)
75
+ where(attributes).first
76
+ end
77
+
78
+ # Returns Domino for capybara node matching all attributes.
79
+ #
80
+ # Raises an error if no matching node is found.
81
+ def find_by!(attributes)
82
+ find_by(attributes) or raise Capybara::ElementNotFound
83
+ end
84
+
85
+ # Returns collection of Dominos for capybara node matching all attributes.
86
+ def where(attributes)
87
+ select do |node|
88
+ attributes.to_set.subset?(node.attributes.to_set)
89
+ end
90
+ end
91
+
74
92
  # Define the selector for this Domino
75
93
  #
76
94
  # module Dom
@@ -130,9 +148,7 @@ class Domino
130
148
 
131
149
  # Return capybara nodes for this object
132
150
  def nodes
133
- if @selector.nil?
134
- raise Domino::Error.new("You must define a selector")
135
- end
151
+ require_selector!
136
152
  Capybara.current_session.all(@selector)
137
153
  end
138
154
 
@@ -140,6 +156,10 @@ class Domino
140
156
  def find_by_attribute(selector, value)
141
157
  detect{|node| value === node.attribute(selector) }
142
158
  end
159
+
160
+ def require_selector!(&block)
161
+ raise Domino::Error.new("You must define a selector") if @selector.nil?
162
+ end
143
163
  end
144
164
 
145
165
  # Get the text of the first dom element matching a selector
data/test/domino_test.rb CHANGED
@@ -159,4 +159,56 @@ class DominoTest < MiniTest::Unit::TestCase
159
159
  Dom::NoSelector.find!
160
160
  end
161
161
  end
162
+
163
+ def test_find_by
164
+ assert_equal 'Alice', Dom::Person.find_by(biography: 'Alice is fun').name
165
+ end
166
+
167
+ def test_find_by_with_multiple_attributes
168
+ assert_equal 'Alice', Dom::Person.find_by(biography: 'Alice is fun', age: 23, favorite_color: 'Blue').name
169
+ end
170
+
171
+ def test_find_by_without_selector
172
+ assert_raises Domino::Error do
173
+ Dom::NoSelector.find_by(foo: "bar")
174
+ end
175
+ end
176
+
177
+ def test_find_by_bang
178
+ assert_equal 'Alice', Dom::Person.find_by!(biography: 'Alice is fun').name
179
+ end
180
+
181
+ def test_find_by_bang_with_multiple_attributes
182
+ assert_equal 'Alice', Dom::Person.find_by!(biography: 'Alice is fun', age: 23, favorite_color: 'Blue').name
183
+ end
184
+
185
+ def test_find_by_bang_without_selector
186
+ assert_raises Domino::Error do
187
+ Dom::NoSelector.find_by(foo: "bar")
188
+ end
189
+ end
190
+
191
+ def test_find_by_bang_without_match
192
+ assert_raises Capybara::ElementNotFound do
193
+ Dom::Person.find_by!(foo: "bar")
194
+ end
195
+ end
196
+
197
+ def test_where_with_single_attribute
198
+ assert_equal %w(Bob Charlie), Dom::Person.where(favorite_color: "Red").map(&:name)
199
+ end
200
+
201
+ def test_where_with_multiple_attributes
202
+ assert_equal %w(Alice), Dom::Person.where(age: 23, favorite_color: 'Blue').map(&:name)
203
+ end
204
+
205
+ def test_where_without_match
206
+ assert_equal [], Dom::Person.where(favorite_color: "Yellow")
207
+ end
208
+
209
+ def test_where_without_selector
210
+ assert_raises Domino::Error do
211
+ Dom::NoSelector.where(foo: "bar")
212
+ end
213
+ end
162
214
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Gauthier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-11 00:00:00.000000000 Z
11
+ date: 2014-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.4.1
107
+ rubygems_version: 2.4.2
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: View abstraction for integration testing