wildcard_finders 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile_for_capybara_1.x +6 -0
- data/Gemfile_for_capybara_2.0.x +6 -0
- data/VERSION +1 -1
- data/lib/wildcard_finders/finders.rb +29 -11
- data/lib/wildcard_finders.rb +2 -1
- data/spec/test_app.rb +16 -0
- data/spec/wildcard_finders/finders_spec.rb +34 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a86602a53c25883d36e6a431727278cd9130aa96
|
4
|
+
data.tar.gz: 21bd97dd507e77bf35037e7bb6c5bf8abb746a45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90eeb41f97178af3d68cfbbd3d2ff7e9e6e0eb8c6a74586bd5e698d1d10032537f7b90947ef930917909f2b4a9e8920f78d799640b96e0ba70b5f8eae4b7cafb
|
7
|
+
data.tar.gz: 0206955180e98f11289be3632ccc22edcc4d4ab1c53e8a9196c8bdb22888e8d408a1f80dcf77a3c8c4838de94162b8e51e28e9c3d1d0238a5aa16fe7d101d4cb
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "capybara/node/finders"
|
2
|
+
require "xpath"
|
2
3
|
|
3
4
|
module WildcardFinders
|
4
5
|
module Finders
|
@@ -6,20 +7,37 @@ module WildcardFinders
|
|
6
7
|
|
7
8
|
# not to add METHODS
|
8
9
|
def find_tag_like(tag, matcher = nil, opts = {}, &block)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
if matcher.is_a?(Hash) && matcher.values.all? {|v| v.is_a?(String) }
|
11
|
+
find_exactly(tag, matcher)
|
12
|
+
else
|
13
|
+
all(tag).select do |e|
|
14
|
+
if matcher.is_a?(Hash)
|
15
|
+
hash = matcher.keys.each_with_object({}) {|key, h| h[key] = e[key] }
|
16
|
+
WildcardMatchers.wildcard_match?(hash, matcher)
|
17
|
+
else
|
18
|
+
WildcardMatchers.wildcard_match?(e, block || matcher)
|
19
|
+
end
|
20
|
+
end.first # not compatible with capybara 2.x
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_exactly(tag, matcher)
|
25
|
+
xpath = XPath.generate do |x|
|
26
|
+
attr_matcher = matcher.map do |key, value|
|
27
|
+
case key
|
28
|
+
when :text
|
29
|
+
x.text.equals(value)
|
30
|
+
when :class
|
31
|
+
x.attr(:class).contains(value)
|
32
|
+
else
|
33
|
+
x.attr(key).equals(value)
|
34
|
+
end
|
19
35
|
end
|
36
|
+
|
37
|
+
x.descendant(tag.to_sym)[attr_matcher.inject(&:&)]
|
20
38
|
end
|
21
39
|
|
22
|
-
|
40
|
+
find(:xpath, xpath)
|
23
41
|
end
|
24
42
|
|
25
43
|
def self.method_added(name)
|
data/lib/wildcard_finders.rb
CHANGED
@@ -17,7 +17,8 @@ module Capybara
|
|
17
17
|
[ ::WildcardFinders::Finders::METHODS, ::WildcardFinders::Matchers::METHODS ].flatten.each do |method|
|
18
18
|
define_method(method) do |*args, &block|
|
19
19
|
@touched = true
|
20
|
-
|
20
|
+
scope = self.respond_to?(:current_scope) ? current_scope : current_node # difference between 2.0 and 2.1
|
21
|
+
scope.__send__(method, *args, &block)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
data/spec/test_app.rb
CHANGED
@@ -11,6 +11,22 @@ a id="onclick_hoge" onclick="hoge"
|
|
11
11
|
_SLIM_
|
12
12
|
end
|
13
13
|
|
14
|
+
get "/@class" do
|
15
|
+
slim <<_SLIM_
|
16
|
+
a id="hoge_fuga" class="hoge fuga"
|
17
|
+
a id="fuga_ugu" class="fuga ugu"
|
18
|
+
_SLIM_
|
19
|
+
end
|
20
|
+
|
21
|
+
get "/text" do
|
22
|
+
slim <<_SLIM_
|
23
|
+
a id="text_hoge_href_hoge" href="hoge"
|
24
|
+
| hoge
|
25
|
+
a id="text_fuga_href_hoge" href="hoge"
|
26
|
+
| fuga
|
27
|
+
_SLIM_
|
28
|
+
end
|
29
|
+
|
14
30
|
__END__
|
15
31
|
|
16
32
|
@@ layout
|
@@ -8,6 +8,9 @@ describe WildcardFinders::Finders do
|
|
8
8
|
[ [ :href, /hoge/, "href_hoge" ],
|
9
9
|
[ :href, /fuga/, "href_fuga" ],
|
10
10
|
[ :onclick, /hoge/, "onclick_hoge" ],
|
11
|
+
[ :href, "hoge", "href_hoge" ],
|
12
|
+
[ :href, "fuga", "href_fuga" ],
|
13
|
+
[ :onclick, "hoge", "onclick_hoge" ],
|
11
14
|
]
|
12
15
|
end
|
13
16
|
|
@@ -27,5 +30,36 @@ describe WildcardFinders::Finders do
|
|
27
30
|
page.find_anchor_like(->(e) { value === e[attr] })[:id].should == expected_id
|
28
31
|
end
|
29
32
|
end
|
33
|
+
|
34
|
+
context "specifying class" do
|
35
|
+
where(:klass, :expected_id) do
|
36
|
+
[ [ "hoge", "hoge_fuga" ],
|
37
|
+
[ "ugu", "fuga_ugu" ],
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
with_them do
|
42
|
+
it "with specifying value finds out whether class has multi values" do
|
43
|
+
visit "/@class"
|
44
|
+
page.find_anchor_like(class: klass)[:id].should == expected_id
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "specifying text" do
|
50
|
+
where(:text, :href, :expected_id) do
|
51
|
+
[ [ "hoge", "hoge", "text_hoge_href_hoge" ],
|
52
|
+
[ "fuga", "hoge", "text_fuga_href_hoge" ],
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
with_them do
|
57
|
+
it "with specifying value also use text()" do
|
58
|
+
visit "/text"
|
59
|
+
page.find_anchor_like(text: text, href: href)[:id].should == expected_id
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
30
64
|
end
|
31
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wildcard_finders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okitan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -148,6 +148,8 @@ files:
|
|
148
148
|
- .travis.yml
|
149
149
|
- CHANGELOG.md
|
150
150
|
- Gemfile
|
151
|
+
- Gemfile_for_capybara_1.x
|
152
|
+
- Gemfile_for_capybara_2.0.x
|
151
153
|
- LICENSE.txt
|
152
154
|
- README.md
|
153
155
|
- Rakefile
|