capybara-grope 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ gem "capybara"
14
+ gem "grope"
15
+ gem "sinatra"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ capybara (0.4.1.2)
5
+ celerity (>= 0.7.9)
6
+ culerity (>= 0.2.4)
7
+ mime-types (>= 1.16)
8
+ nokogiri (>= 1.3.3)
9
+ rack (>= 1.0.0)
10
+ rack-test (>= 0.5.4)
11
+ selenium-webdriver (>= 0.0.27)
12
+ xpath (~> 0.1.3)
13
+ celerity (0.8.8)
14
+ childprocess (0.1.7)
15
+ ffi (~> 0.6.3)
16
+ culerity (0.2.15)
17
+ diff-lcs (1.1.2)
18
+ ffi (0.6.3)
19
+ rake (>= 0.8.7)
20
+ git (1.2.5)
21
+ grope (0.0.4)
22
+ mechanize (>= 1.0.0)
23
+ jeweler (1.5.2)
24
+ bundler (~> 1.0.0)
25
+ git (>= 1.2.5)
26
+ rake
27
+ json_pure (1.5.1)
28
+ mechanize (1.0.0)
29
+ nokogiri (>= 1.2.1)
30
+ mime-types (1.16)
31
+ nokogiri (1.4.4)
32
+ rack (1.2.1)
33
+ rack-test (0.5.7)
34
+ rack (>= 1.0)
35
+ rake (0.8.7)
36
+ rcov (0.9.9)
37
+ rspec (2.3.0)
38
+ rspec-core (~> 2.3.0)
39
+ rspec-expectations (~> 2.3.0)
40
+ rspec-mocks (~> 2.3.0)
41
+ rspec-core (2.3.1)
42
+ rspec-expectations (2.3.0)
43
+ diff-lcs (~> 1.1.2)
44
+ rspec-mocks (2.3.0)
45
+ rubyzip (0.9.4)
46
+ selenium-webdriver (0.1.3)
47
+ childprocess (~> 0.1.5)
48
+ ffi (~> 0.6.3)
49
+ json_pure
50
+ rubyzip
51
+ sinatra (1.1.2)
52
+ rack (~> 1.1)
53
+ tilt (~> 1.2)
54
+ tilt (1.2.2)
55
+ xpath (0.1.3)
56
+ nokogiri (~> 1.3)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 1.0.0)
63
+ capybara
64
+ grope
65
+ jeweler (~> 1.5.2)
66
+ rcov
67
+ rspec (~> 2.3.0)
68
+ sinatra
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 youpy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = capybara-grope
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to capybara-grope
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 youpy. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "capybara-grope"
16
+ gem.homepage = "http://github.com/youpy/capybara-grope"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Capybara driver for grope}
19
+ gem.description = %Q{Capybara driver for grope}
20
+ gem.email = "youpy@buycheapviagraonlinenow.com"
21
+ gem.authors = ["youpy"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "capybara-grope #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,162 @@
1
+ require 'grope'
2
+
3
+ class Capybara::Driver::Grope < Capybara::Driver::Base
4
+ class Node < Capybara::Driver::Node
5
+ def text
6
+ native.textContent
7
+ end
8
+
9
+ def [](name)
10
+ native.getAttribute(name.to_s)
11
+ end
12
+
13
+ def value
14
+ if tag_name == "select" and native.multiple?
15
+ native.selected_options
16
+ else
17
+ native.value
18
+ end
19
+ end
20
+
21
+ def set(value)
22
+ native.value = value
23
+ end
24
+
25
+ def select(option)
26
+ native.options.find do |o|
27
+ o.value == option.value
28
+ end.selected = 1
29
+ rescue
30
+ options = native.options.map { |o| "'#{o.textContent}'" }.join(', ')
31
+ raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
32
+ end
33
+
34
+ def unselect(option)
35
+ if native.multiple.zero?
36
+ raise Capybara::UnselectNotAllowed, "Cannot unselect option '#{option}' from single select box."
37
+ end
38
+
39
+ native.options.find do |o|
40
+ o.value == option.value
41
+ end.selected = 0
42
+ rescue
43
+ options = native.options.map { |o| "'#{o.textContent}'" }.join(', ')
44
+ raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
45
+ end
46
+
47
+ def click
48
+ js.click(native)
49
+ end
50
+
51
+ def drag_to(element)
52
+ js = driver.grope.eval(<<JS)
53
+ Grope.dd = function(draggable, droppable) {
54
+ var dispatchMouseEvent = function(e, type, dst) {
55
+ var evt = document.createEvent('MouseEvents');
56
+ var pos = getElementPosition(dst);
57
+ evt.initMouseEvent(type, true, true, window, 0, 0, 0, pos.left, pos.top, false, false, false, false, 0, null);
58
+ e.dispatchEvent(evt);
59
+ };
60
+ var getElementPosition = function(elem) {
61
+ var position = elem.getBoundingClientRect();
62
+ return {
63
+ left: Math.round(window.scrollX+position.left),
64
+ top: Math.round(window.scrollY+position.top),
65
+ width: elem.clientWidth,
66
+ height: elem.clientHeight
67
+ };
68
+ };
69
+
70
+ dispatchMouseEvent(draggable, 'mousedown', draggable);
71
+ dispatchMouseEvent(draggable, 'mousemove', droppable);
72
+ dispatchMouseEvent(draggable, 'mouseup', droppable);
73
+ };
74
+ return Grope;
75
+ JS
76
+ js.dd(self.native, element.native)
77
+ end
78
+
79
+ def tag_name
80
+ native.nodeName.downcase
81
+ end
82
+
83
+ def visible?
84
+ (driver.grope.document.defaultView.getComputedStyle(native, '').visibility == 'visible') &&
85
+ !(native.offsetWidth == 0 && native.offsetHeight == 0)
86
+ end
87
+
88
+ def checked?
89
+ native.getAttribute('checked') == "checked"
90
+ end
91
+
92
+ def selected?
93
+ native.getAttribute('selected') == "selected"
94
+ end
95
+
96
+ def path
97
+ # TODO
98
+ end
99
+
100
+ def trigger(event)
101
+ js._dispatchMouseEvent(native, event.to_s)
102
+ end
103
+
104
+ def find(xpath)
105
+ self.class.new(driver, driver.grope.find(xpath, native))
106
+ end
107
+
108
+ def all(xpath)
109
+ driver.grope.all(xpath, native).map { |n| self.class.new(driver, n) }
110
+ end
111
+
112
+ def js
113
+ @js ||= driver.grope.eval('return Grope')
114
+ end
115
+ end
116
+
117
+ attr_reader :app, :grope, :rack_server
118
+
119
+ def initialize(app)
120
+ @app = app
121
+ @rack_server = Capybara::Server.new(@app)
122
+ @rack_server.boot if Capybara.run_server
123
+ @grope = Grope::Env.new
124
+ end
125
+
126
+ def visit(path)
127
+ @grope.load(url(path))
128
+ @grope.wait
129
+ end
130
+
131
+ def current_url
132
+ @grope.document.URL
133
+ end
134
+
135
+ def source
136
+ @grope.document.documentElement.outerHTML
137
+ end
138
+
139
+ def body
140
+ @grope.document.body.outerHTML
141
+ end
142
+
143
+ def response_headers
144
+ response.headers
145
+ end
146
+
147
+ def find(selector)
148
+ @grope.all(selector).map { |node| Node.new(self, node) }
149
+ end
150
+
151
+ def wait?; true; end
152
+
153
+ def evaluate_script(script)
154
+ @grope.eval('return %s' % script)
155
+ end
156
+
157
+ private
158
+
159
+ def url(path)
160
+ rack_server.url(path)
161
+ end
162
+ end
@@ -0,0 +1,2 @@
1
+ require 'capybara'
2
+ require 'capybara/driver/grope_driver'
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Capybara::Driver::Grope do
4
+ before do
5
+ @driver = Capybara::Driver::Grope.new(TestApp)
6
+ end
7
+
8
+ it_should_behave_like "driver"
9
+ it_should_behave_like "driver with javascript support"
10
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ require 'rspec'
6
+ require 'capybara'
7
+ require 'capybara/grope'
8
+
9
+ spec_dir = nil
10
+ $:.detect do |dir|
11
+ if File.exists? File.join(dir, "capybara.rb")
12
+ spec_dir = File.expand_path(File.join(dir,"..","spec"))
13
+ $:.unshift( spec_dir )
14
+ end
15
+ end
16
+
17
+ require File.join(spec_dir,"spec_helper")
18
+
19
+ RSpec.configure do |config|
20
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-grope
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - youpy
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-19 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :development
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 0
34
+ version: 2.3.0
35
+ name: rspec
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ type: :development
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ name: bundler
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ prerelease: false
55
+ type: :development
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 7
62
+ segments:
63
+ - 1
64
+ - 5
65
+ - 2
66
+ version: 1.5.2
67
+ name: jeweler
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ prerelease: false
71
+ type: :development
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ name: rcov
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ prerelease: false
85
+ type: :development
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ name: capybara
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ prerelease: false
99
+ type: :development
100
+ requirement: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ name: grope
110
+ version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ prerelease: false
113
+ type: :development
114
+ requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ name: sinatra
124
+ version_requirements: *id007
125
+ description: Capybara driver for grope
126
+ email: youpy@buycheapviagraonlinenow.com
127
+ executables: []
128
+
129
+ extensions: []
130
+
131
+ extra_rdoc_files:
132
+ - LICENSE.txt
133
+ - README.rdoc
134
+ files:
135
+ - .document
136
+ - .rspec
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - LICENSE.txt
140
+ - README.rdoc
141
+ - Rakefile
142
+ - VERSION
143
+ - lib/capybara/driver/grope_driver.rb
144
+ - lib/capybara/grope.rb
145
+ - spec/driver/grope_driver_spec.rb
146
+ - spec/spec_helper.rb
147
+ has_rdoc: true
148
+ homepage: http://github.com/youpy/capybara-grope
149
+ licenses:
150
+ - MIT
151
+ post_install_message:
152
+ rdoc_options: []
153
+
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ requirements: []
175
+
176
+ rubyforge_project:
177
+ rubygems_version: 1.5.0
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: Capybara driver for grope
181
+ test_files:
182
+ - spec/driver/grope_driver_spec.rb
183
+ - spec/spec_helper.rb