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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bde38ec3c83bf76883f655f17c284530da79c1f
4
- data.tar.gz: 52e3266429b605a07b270f6361c1ad6a80185fac
3
+ metadata.gz: a86602a53c25883d36e6a431727278cd9130aa96
4
+ data.tar.gz: 21bd97dd507e77bf35037e7bb6c5bf8abb746a45
5
5
  SHA512:
6
- metadata.gz: 2a76774c03d117502799055fc240800da20ec7e0842e074e669959cc993611ad273e2eacd2f7e233c49ac7b652a9f682b9599387dfdc7adc38094b238ba7b7f2
7
- data.tar.gz: 8e0950902e8f96a6f1f7a9bb32284ba1ac1d9098283174f0e75d0b32f1b681c4ac98f2bac98fa7a01d9fc169e422d6dfa614061d1eaabc2a671a3fbd9d9fcac2
6
+ metadata.gz: 90eeb41f97178af3d68cfbbd3d2ff7e9e6e0eb8c6a74586bd5e698d1d10032537f7b90947ef930917909f2b4a9e8920f78d799640b96e0ba70b5f8eae4b7cafb
7
+ data.tar.gz: 0206955180e98f11289be3632ccc22edcc4d4ab1c53e8a9196c8bdb22888e8d408a1f80dcf77a3c8c4838de94162b8e51e28e9c3d1d0238a5aa16fe7d101d4cb
data/.travis.yml CHANGED
@@ -3,3 +3,11 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - 2.0.0
6
+ gemfile:
7
+ - Gemfile
8
+ - Gemfile_for_capybara_1.x
9
+ - Gemfile_for_capybara_2.0.x
10
+ matrix:
11
+ exclude:
12
+ - rvm: 1.9.2
13
+ gemfile: Gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.3
2
+ * ADD
3
+ * use xpath when matcher can be converted
4
+
1
5
  # 0.0.2
2
6
  * CHANGE
3
7
  * find_tag_like can also accept proc as matcher or block
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "capybara", "~> 1.1"
6
+ gem "rspec-parameterized", github: "tomykaira/rspec-parameterized"
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "capybara", "~> 2.0.0"
6
+ gem "rspec-parameterized", github: "tomykaira/rspec-parameterized"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
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
- tags = all(tag).select do |e|
10
- if matcher.is_a?(Hash)
11
- hash = matcher.keys.each_with_object({}) {|key, h| h[key] = e[key] }
12
- WildcardMatchers.wildcard_match?(hash, matcher)
13
- elsif block_given? or matcher.is_a?(Proc)
14
- WildcardMatchers.wildcard_match?(e, block || matcher)
15
- elsif matcher # I don't know this behavior
16
- WildcardMatchers.wildcard_match?(e, matcher)
17
- else
18
- raise "no matcher or block is not given"
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
- tags.first # not compatible with capybara 2.x
40
+ find(:xpath, xpath)
23
41
  end
24
42
 
25
43
  def self.method_added(name)
@@ -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
- current_node.__send__(method, *args, &block)
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.2
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-03-27 00:00:00.000000000 Z
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