napybara 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +11 -21
- data/lib/napybara/element.rb +15 -6
- data/lib/napybara/version.rb +1 -1
- data/spec/integration/readme_spec.rb +2 -2
- data/spec/napybara/element_spec.rb +4 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d7b59ac7590d39a09e63cc572d21aa5c43f6c27
|
4
|
+
data.tar.gz: 9f3b75d890dbed6b3d19a0d4413950a212e3088f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6e6557bf502740bff951cca82f8a2fbd1f177cd725e04e2dc506b89118974231ef0a58a1dd64d022b3b53c102756855c284a65b9841f9792b20c915d0b64c2a
|
7
|
+
data.tar.gz: fbb927c8fa87961f978213aa665a03622369cb427fa954985a358db171313394ebcaf02ee7cf08efa1e9b9c6a578ce28c040000ffdb7e87f87b8e5d900a674d1
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -30,8 +30,8 @@ messages_page.form.submit!
|
|
30
30
|
expect(messages_page.message(Message.find(1))).to have_content('Hello world!')
|
31
31
|
expect(messages_page.message(Message.find(2))).to have_content('Kamusta mundo!')
|
32
32
|
|
33
|
-
expect(messages_page.
|
34
|
-
expect(messages_page.
|
33
|
+
expect(messages_page.messages[0]).to have_content('Hello world!')
|
34
|
+
expect(messages_page.messages[1]).to have_content('Kamusta mundo!')
|
35
35
|
```
|
36
36
|
|
37
37
|
With Napybara, now you can!
|
@@ -73,14 +73,13 @@ expect(messages_page.form.get['class']).to eq('new-message')
|
|
73
73
|
|
74
74
|
## Finding by object
|
75
75
|
|
76
|
-
In
|
77
|
-
|
78
|
-
can also accept an object when searching for the object's matching element:
|
76
|
+
In order to find an element representing a particular ruby object, you need to
|
77
|
+
add a separate selector which incorporates the ruby object's id:
|
79
78
|
|
80
79
|
```ruby
|
81
80
|
let(:messages_page) do
|
82
81
|
Napybara::Element.new(self) do |page|
|
83
|
-
page.finder :message, '#message-'
|
82
|
+
page.finder :message, '.message', '#message-{id}'
|
84
83
|
end
|
85
84
|
end
|
86
85
|
|
@@ -96,19 +95,11 @@ expect(messages_page.message(some_message).get['id'])
|
|
96
95
|
```
|
97
96
|
|
98
97
|
In the above example, the `message` finder looks for an element matching the
|
99
|
-
given selector (`#message
|
98
|
+
given selector (`#message-{id}`) with `some_message`'s id (`1`). So it ends up
|
100
99
|
looking for "#message-1".
|
101
100
|
|
102
|
-
|
101
|
+
If the ruby object is identified by a method other than the object's id, you can replace `{id}` with the method e.g. `{name}`, `{to_s}`.
|
103
102
|
|
104
|
-
As you may have observed, the finder added by `Napybara::Element#finder`
|
105
|
-
can be called with or without an object argument. Usually, you only want to use
|
106
|
-
just one of these two options; the selector you declare will determine what
|
107
|
-
option you want to use. For example, `#message-` only makes sense with an object
|
108
|
-
id at the end of the selector, so you want to call the `messages_page.message()`
|
109
|
-
finder with an object. On the other hand, `form.new-message` does not make sense
|
110
|
-
with an object id at the end of the selector, so you want to call the
|
111
|
-
`messages_page.form()` finder without an object argument.
|
112
103
|
|
113
104
|
## Checking if an element exists
|
114
105
|
|
@@ -139,14 +130,14 @@ Finally, `Napybara::Element#finder` adds a pluralized version of the finder. For
|
|
139
130
|
```ruby
|
140
131
|
let(:messages_page) do
|
141
132
|
Napybara::Element.new(self) do |page|
|
142
|
-
page.finder :
|
133
|
+
page.finder :message, '.message'
|
143
134
|
end
|
144
135
|
end
|
145
136
|
|
146
137
|
# ...
|
147
138
|
|
148
|
-
expect(messages_page.
|
149
|
-
expect(messages_page.
|
139
|
+
expect(messages_page.messages[0].get.text).to eq("Hello world!")
|
140
|
+
expect(messages_page.messages[1].get.text).to eq("Kamusta mundo!")
|
150
141
|
```
|
151
142
|
|
152
143
|
Napybara uses ActiveSupport to get the plural version of the finder name.
|
@@ -221,8 +212,7 @@ let(:messages_page) do
|
|
221
212
|
form.finder :submit_button, 'input[type=submit]'
|
222
213
|
end
|
223
214
|
|
224
|
-
page.finder :message, '.message-list #message-'
|
225
|
-
page.finder :message_item, '.message-list .message'
|
215
|
+
page.finder :message, '.message-list .message', '#message-{id}'
|
226
216
|
end
|
227
217
|
end
|
228
218
|
```
|
data/lib/napybara/element.rb
CHANGED
@@ -10,19 +10,19 @@ module Napybara
|
|
10
10
|
block.call(self) if block_given?
|
11
11
|
end
|
12
12
|
|
13
|
-
def finder(child_element_name, child_element_selector,
|
13
|
+
def finder(child_element_name, child_element_selector, record_selector = nil, &block)
|
14
14
|
self.define_singleton_method(child_element_name) do |record = nil|
|
15
|
-
selector = Selector.new(child_element_selector,
|
15
|
+
selector = Selector.new(child_element_selector, record_selector, record)
|
16
16
|
self.class.new(self.get.find(selector.to_s), &block)
|
17
17
|
end
|
18
18
|
|
19
19
|
self.define_singleton_method("has_#{child_element_name}?") do |record = nil|
|
20
|
-
selector = Selector.new(child_element_selector,
|
20
|
+
selector = Selector.new(child_element_selector, record_selector, record)
|
21
21
|
self.get.has_css?(selector.to_s)
|
22
22
|
end
|
23
23
|
|
24
24
|
self.define_singleton_method("has_no_#{child_element_name}?") do |record = nil|
|
25
|
-
selector = Selector.new(child_element_selector,
|
25
|
+
selector = Selector.new(child_element_selector, record_selector, record)
|
26
26
|
self.get.has_no_css?(selector.to_s)
|
27
27
|
end
|
28
28
|
|
@@ -33,13 +33,22 @@ module Napybara
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
class Selector < Struct.new(:child_element_selector, :
|
36
|
+
class Selector < Struct.new(:child_element_selector, :record_selector, :record)
|
37
|
+
METHOD_NAME_REGEX = /\{(\w+)\}/
|
38
|
+
def method_name
|
39
|
+
record_selector.match(METHOD_NAME_REGEX)[1]
|
40
|
+
end
|
41
|
+
|
37
42
|
def record_id
|
38
43
|
record && record.public_send(method_name)
|
39
44
|
end
|
40
45
|
|
41
46
|
def to_s
|
42
|
-
|
47
|
+
if record
|
48
|
+
record_selector.gsub(METHOD_NAME_REGEX, record_id.to_s)
|
49
|
+
else
|
50
|
+
child_element_selector
|
51
|
+
end
|
43
52
|
end
|
44
53
|
end
|
45
54
|
end
|
data/lib/napybara/version.rb
CHANGED
@@ -63,7 +63,7 @@ describe 'Readme example:' do
|
|
63
63
|
|
64
64
|
When "I add an object finder to the Napybara page wrapping the capybara page" do
|
65
65
|
@messages_page = Napybara::Element.new(capybara_page) do |page|
|
66
|
-
page.finder :message, '#message-'
|
66
|
+
page.finder :message, '.message', '#message-{id}'
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -82,7 +82,7 @@ describe 'Readme example:' do
|
|
82
82
|
When "I add finders to the Napybara page wrapping the capybara page" do
|
83
83
|
@messages_page = Napybara::Element.new(capybara_page) do |page|
|
84
84
|
page.finder :form, 'form.new-message'
|
85
|
-
page.finder :message, '#message-'
|
85
|
+
page.finder :message, '.message', '#message-{id}'
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -50,7 +50,7 @@ describe Napybara::Element do
|
|
50
50
|
|
51
51
|
it 'allows the element to find a sub-element with an id' do
|
52
52
|
page = described_class.new(capybara_page)
|
53
|
-
page.finder(:form, '#form-')
|
53
|
+
page.finder(:form, '.some-form', '#form-{id}')
|
54
54
|
|
55
55
|
object = OpenStruct.new(id: 1)
|
56
56
|
|
@@ -59,7 +59,7 @@ describe Napybara::Element do
|
|
59
59
|
|
60
60
|
it 'allows the element to find a sub-element with a record method' do
|
61
61
|
page = described_class.new(capybara_page)
|
62
|
-
page.finder(:form, '
|
62
|
+
page.finder(:form, '.some-form', '#form-{name}')
|
63
63
|
|
64
64
|
object = OpenStruct.new(name: 1)
|
65
65
|
|
@@ -88,7 +88,7 @@ describe Napybara::Element do
|
|
88
88
|
|
89
89
|
it 'adds a method to check if the element has a sub-element matching a record' do
|
90
90
|
page = described_class.new(capybara_page)
|
91
|
-
page.finder(:form, '#form-')
|
91
|
+
page.finder(:form, '.some-form', '#form-{id}')
|
92
92
|
|
93
93
|
object = OpenStruct.new(id: 1)
|
94
94
|
|
@@ -97,7 +97,7 @@ describe Napybara::Element do
|
|
97
97
|
|
98
98
|
it 'adds a method to check if the element has no sub-element matching a record' do
|
99
99
|
page = described_class.new(capybara_page)
|
100
|
-
page.finder(:form, '#form-')
|
100
|
+
page.finder(:form, '.some-form', '#form-{id}')
|
101
101
|
|
102
102
|
object = OpenStruct.new(id: 1)
|
103
103
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: napybara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Mendoza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- .rspec
|
191
191
|
- .rubocop.yml
|
192
192
|
- .travis.yml
|
193
|
+
- CHANGELOG.md
|
193
194
|
- Gemfile
|
194
195
|
- Guardfile
|
195
196
|
- LICENSE.txt
|