wildcard_finders 0.1.1 → 0.2.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: a9a44948a9167397000feb8d66fc6934c901fa80
4
- data.tar.gz: be4c180e8adad420445ceaac79d8ed702be9f025
3
+ metadata.gz: 08e9bfbc82ce9fecd8da133569bf329caba7730d
4
+ data.tar.gz: c6b99935e3fd5842737e3b54f10bb17513b946e6
5
5
  SHA512:
6
- metadata.gz: 6eb482e38b8eb89394f53676cf2dcc60bfc97264f692ee8280ffedc27eb3291cee31185f61182e818d9ef0c4183c6100d90ce5fcd65f2593d0a3dbf47da8f470
7
- data.tar.gz: 1b063c025d5f3780502d4e64054904be2fcefad013f0890285111f56676b767064cd5f90c3d3c3bfe04d6bdb5f34bb5e7c799443035d75b05545f707b3f388c2
6
+ metadata.gz: 92a1eb85521d0b6e6781cbcd6cff8c3ff188821c0c982312ef0c452382bbfdbb4213344f83080a743b1d32337053505d70edc3e758339f7660f96ffc8790023d
7
+ data.tar.gz: 1cdf1dc1497902fbf05432fd4f88f64bb5f6d1e15254ccb41406594e5f8797d8898f94caaeeb76cb42c357191f8ae2a1c3194ee2f9bce5c626c6dc3fc2747e0f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.2.0
2
+ * CHANGE
3
+ * find_xxx_like raise errors when element not found
4
+ * find_xxx_like waits Capybara.default_wait_time
5
+
1
6
  # 0.1.1
2
7
  * ENHANCEMENT
3
8
  * have_xxx_like matcher allows block to use
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem "rspec-parameterized", github: "tomykaira/rspec-parameterized"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -6,18 +6,31 @@ module WildcardFinders
6
6
  METHODS = []
7
7
 
8
8
  # not to add METHODS
9
+ # FIXME: opts is not used. what was that?
9
10
  def find_tag_like(tag, matcher = nil, opts = {}, &block)
10
11
  if matcher.is_a?(Hash) && matcher.values.all? {|v| v.is_a?(String) }
11
12
  find_exactly(tag, matcher)
12
13
  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)
14
+ wait_method = respond_to?(:synchronize) ? :synchronize : :wait_until
15
+
16
+ results = []
17
+ __send__(wait_method) do
18
+ results = all(tag).select do |element|
19
+ if matcher.is_a?(Hash)
20
+ hash_from_element = matcher.keys.each_with_object({}) {|key, h| h[key] = element[key] }
21
+ WildcardMatchers.wildcard_match?(hash_from_element, matcher)
22
+ else
23
+ WildcardMatchers.wildcard_match?(element, block || matcher)
24
+ end
19
25
  end
20
- end.first # not compatible with capybara 2.x
26
+ end
27
+
28
+ if results.empty?
29
+ raise Capybara::ElementNotFound, "no <#{tag}> to match #{matcher}"
30
+ else
31
+ # not compatible for capybara 2.0
32
+ results.first
33
+ end
21
34
  end
22
35
  end
23
36
 
@@ -37,11 +50,7 @@ module WildcardFinders
37
50
  x.descendant(tag.to_sym)[attr_matcher.inject(&:&)]
38
51
  end
39
52
 
40
- begin
41
- find(:xpath, xpath)
42
- rescue Capybara::ElementNotFound
43
- nil
44
- end
53
+ find(:xpath, xpath)
45
54
  end
46
55
 
47
56
  def self.method_added(name)
@@ -19,25 +19,21 @@ module WildcardFinders
19
19
  rspec_no_matcher_method_without_block = method.to_s.sub("find", "have_no") + "_without_block"
20
20
 
21
21
  define_method(matcher_method) do |*args, &block|
22
- wait_method = respond_to?(:synchronize) ? :synchronize : :wait_until
23
-
24
- __send__(wait_method) do
25
- result = __send__(method, *args, &block)
26
- result or return(false)
22
+ begin
23
+ __send__(method, *args, &block)
24
+ true
25
+ rescue ::Capybara::ElementNotFound
26
+ false
27
27
  end
28
-
29
- true
30
28
  end
31
29
 
32
30
  define_method(no_matcher_method) do |*args, &block|
33
- wait_method = respond_to?(:synchronize) ? :synchronize : :wait_until
34
-
35
- __send__(wait_method) do
36
- result = __send__(method, *args, &block)
37
- result and return(false)
31
+ begin
32
+ __send__(method, *args, &block)
33
+ false
34
+ rescue ::Capybara::ElementNotFound
35
+ true
38
36
  end
39
-
40
- true
41
37
  end
42
38
 
43
39
  RSpec::Matchers.define(rspec_matcher_method_without_block) do |expected|
@@ -71,7 +71,7 @@ describe WildcardFinders::Finders do
71
71
  with_them do
72
72
  it "returns nil" do
73
73
  visit "/a"
74
- page.find_anchor_like(attr => value).should be_nil
74
+ expect { page.find_anchor_like(attr => value) }.to raise_exception(Capybara::ElementNotFound)
75
75
  end
76
76
  end
77
77
  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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - okitan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-26 00:00:00.000000000 Z
11
+ date: 2013-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara