wildcard_finders 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm gemset use wildcard_finders
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 okitan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # wildcard_finders
2
+
3
+ For people struggling with non-semantic html.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```sh
10
+ gem 'wildcard_finders'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```sh
22
+ $ gem install wildcard_finders
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ it "can find image using regexp" do
29
+ page.find_img_like :src => /\.png$/ # => <Capybara::Node> # first img tag which is png
30
+
31
+ page.should have_img_like :src => /\.jpg$/ # => expect at least one img tag of jpg
32
+ page.should have_no_img_like :src => /\.bmp$/ # => expect no img tag of bmp
33
+ end
34
+ ```
35
+
36
+ See WildcardFinders::Finders::METHODS for ohter available finders.
37
+ Every finder has automatically have matchers: both has_xxx_like? and has_no_xxx_like?.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,24 @@
1
+ require "capybara"
2
+ require "wildcard_matchers"
3
+
4
+ module WildcardFinders
5
+ autoload :Finders, "wildcard_finders/finders"
6
+ autoload :Matchers, "wildcard_finders/matchers"
7
+ end
8
+
9
+ module Capybara
10
+ module Node
11
+ class Base
12
+ include ::WildcardFinders::Finders, ::WildcardFinders::Matchers
13
+ end
14
+ end
15
+
16
+ class Session
17
+ [ ::WildcardFinders::Finders::METHODS, ::WildcardFinders::Matchers::METHODS ].flatten.each do |method|
18
+ define_method(method) do |*args, &block|
19
+ @touched = true
20
+ current_node.__send__(method, *args, &block)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ require "capybara/node/finders"
2
+
3
+ module WildcardFinders
4
+ module Finders
5
+ METHODS = []
6
+
7
+ # not to add METHODS
8
+ def find_tag_like(tag, matcher, opts = {})
9
+ tags = all(tag).select do |e|
10
+ hash = matcher.keys.each_with_object({}) {|key, h| h[key] = e[key] }
11
+ WildcardMatchers.wildcard_match?(hash, matcher)
12
+ end
13
+
14
+ tags.first # not compatible with capybara 2.x
15
+ end
16
+
17
+ def self.method_added(name)
18
+ METHODS.push(name)
19
+ end
20
+
21
+ # I'll never add semantic tags
22
+ %w[ img a input form link ].each do |name|
23
+ define_method("find_#{name}_like") do |matcher, opts = {}|
24
+ find_tag_like(name, matcher, opts)
25
+ end
26
+ end
27
+
28
+ # synonym
29
+ { "a" => %w[ anchor ],
30
+ "img" => %w[ image ],
31
+ }.each do |tag, synonyms|
32
+ synonyms.each do |synonym|
33
+ module_eval %{
34
+ alias find_#{synonym}_like find_#{tag}_like
35
+ }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ require "capybara/node/matchers"
2
+
3
+ module WildcardFinders
4
+ module Matchers
5
+ METHODS = []
6
+
7
+ def self.method_added(name)
8
+ METHODS.push(name)
9
+ end
10
+
11
+ ::WildcardFinders::Finders::METHODS.each do |method|
12
+ if method =~ /\Afind_/
13
+ matcher_method = method.to_s.sub("find", "has") + "?"
14
+ no_matcher_method = method.to_s.sub("find", "has_no") + "?"
15
+
16
+ define_method(matcher_method) do |*args, &block|
17
+ wait_method = respond_to?(:synchronize) ? :synchronize : :wait_until
18
+
19
+ __send__(wait_method) do
20
+ result = __send__(method, *args, &block)
21
+ result or raise Capybara::ExpectationNotMet, "no results for #{matcher_method}:#{args}"
22
+ end
23
+
24
+ true
25
+ end
26
+
27
+ define_method(no_matcher_method) do |*args, &block|
28
+ wait_method = respond_to?(:synchronize) ? :synchronize : :wait_until
29
+
30
+ __send__(wait_method) do
31
+ result = __send__(method, *args, &block)
32
+ result and raise Capybara::ExpectationNotMet, "some results for #{matcher_method}:#{args}"
33
+ end
34
+
35
+ true
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "wildcard_finders"
6
+ gem.version = File.read(File.join(File.dirname(__FILE__), "VERSION")).chomp
7
+ gem.authors = ["okitan"]
8
+ gem.email = ["okitakunio@gmail.com"]
9
+ gem.description = "finders for capybara"
10
+ gem.summary = "finders for people strugling non-semantic doms"
11
+ gem.homepage = "https://github.com/okitan/wildcard_finders"
12
+
13
+ gem.files = `git ls-files`.split($/)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.require_paths = ["lib"]
17
+
18
+ gem.add_dependency "capybara"
19
+ gem.add_dependency "wildcard_matchers"
20
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wildcard_finders
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - okitan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capybara
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: wildcard_matchers
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: finders for capybara
47
+ email:
48
+ - okitakunio@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rvmrc
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - VERSION
60
+ - lib/wildcard_finders.rb
61
+ - lib/wildcard_finders/finders.rb
62
+ - lib/wildcard_finders/matchers.rb
63
+ - wildcard_finders.gemspec
64
+ homepage: https://github.com/okitan/wildcard_finders
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.24
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: finders for people strugling non-semantic doms
88
+ test_files: []
89
+ has_rdoc: