watir-rails 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/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jarmo Pertman
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,42 @@
1
+ # Watir::Rails
2
+
3
+ This gem adds the [Watir](http://github.com/watir/watir) usage support when writing integration tests in Rails.
4
+
5
+ ## Installation
6
+
7
+ Add this code to your Gemfile:
8
+
9
+ group :test do
10
+ gem 'watir-rails'
11
+ end
12
+
13
+ ## Usage
14
+
15
+ Just use Watir like you've always done in your requests/integration tests:
16
+
17
+ browser = Watir::Browser.new
18
+ browser.goto home_path
19
+ browser.text_field(name: "first").set "Jarmo"
20
+ browser.text_field(name: "last").set "Pertman"
21
+ browser.button(name: "sign_in").click
22
+
23
+ ## Limitations
24
+
25
+ * Watir-Rails works currently only with the [Watir-WebDriver](http://github.com/watir/watir-webdriver) and not with
26
+ the [Watir-Classic](http://github.com/watir/watir-classic) due to the problems of running a server
27
+ in the separate thread when WIN32OLE is used.
28
+ The problem is probably caused by the fact that [WIN32OLE overwrites Thread#initialize](https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L607).
29
+
30
+ * When using Rails path/url helpers in your tests then always use path instead of url methods, because latter won't work!
31
+
32
+ ## License
33
+
34
+ See [LICENSE](https://github.com/watir/watir-rails/blob/master/LICENSE).
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,18 @@
1
+ module Watir
2
+ class Browser
3
+ alias_method :original_initialize, :initialize
4
+
5
+ def initialize(*args)
6
+ Rails.boot
7
+ original_initialize *args
8
+ end
9
+
10
+ alias_method :original_goto, :goto
11
+
12
+ def goto(url)
13
+ url = "http://#{Rails.host}:#{Rails.port}#{url}" unless url =~ %r{^http://}i
14
+ original_goto url
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,93 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'rack'
4
+ require 'watir-webdriver'
5
+ require File.expand_path("browser.rb", File.dirname(__FILE__))
6
+
7
+ module Watir
8
+ class Rails
9
+ class Middleware
10
+ def initialize(app)
11
+ @app = app
12
+ end
13
+
14
+ def call(env)
15
+ if env["PATH_INFO"] == "/__identify__"
16
+ [200, {}, [@app.object_id.to_s]]
17
+ else
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
22
+
23
+ class << self
24
+ private :new
25
+ attr_reader :port, :middleware
26
+
27
+ def boot
28
+ unless running?
29
+ @middleware = Middleware.new(app)
30
+ @port = find_available_port
31
+
32
+ @server_thread = Thread.new do
33
+ run_default_server @middleware, @port
34
+ end
35
+
36
+ Timeout.timeout(60) { @server_thread.join(0.1) until running? }
37
+ end
38
+ rescue TimeoutError
39
+ raise "Rack application timed out during boot"
40
+ end
41
+
42
+ def host
43
+ "127.0.0.1"
44
+ end
45
+
46
+ def running?
47
+ return false if @server_thread && @server_thread.join(0)
48
+
49
+ res = Net::HTTP.start(host, @port) { |http| http.get('/__identify__') }
50
+
51
+ if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
52
+ return res.body == @app.object_id.to_s
53
+ end
54
+ rescue Errno::ECONNREFUSED, Errno::EBADF
55
+ return false
56
+ end
57
+
58
+ def app
59
+ @app ||= Rack::Builder.new do
60
+ map "/" do
61
+ if ::Rails.version.to_f >= 3.0
62
+ run ::Rails.application
63
+ else # Rails 2
64
+ use ::Rails::Rack::Static
65
+ run ActionController::Dispatcher.new
66
+ end
67
+ end
68
+ end.to_app
69
+ end
70
+
71
+ private
72
+
73
+ def find_available_port
74
+ server = TCPServer.new('127.0.0.1', 0)
75
+ server.addr[1]
76
+ ensure
77
+ server.close if server
78
+ end
79
+
80
+ def run_default_server(app, port)
81
+ begin
82
+ require 'rack/handler/thin'
83
+ Thin::Logging.silent = true
84
+ Rack::Handler::Thin.run(app, :Port => port)
85
+ rescue LoadError
86
+ require 'rack/handler/webrick'
87
+ Rack::Handler::WEBrick.run(app, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
88
+ end
89
+ end
90
+
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,5 @@
1
+ module Watir
2
+ class Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/watir/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jarmo Pertman"]
6
+ gem.email = ["jarmo.p@gmail.com"]
7
+ gem.description = %q{Add support for Watir (http://github.com/watir/watir) in Rails.}
8
+ gem.summary = %q{Add support for Watir (http://github.com/watir/watir) in Rails.}
9
+ gem.homepage = "http://github.com/watir/watir-rails"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "watir-rails"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Watir::Rails::VERSION
17
+
18
+ gem.add_dependency "rack"
19
+ gem.add_dependency "rails"
20
+ gem.add_dependency "watir-webdriver"
21
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watir-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jarmo Pertman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
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: rails
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
+ - !ruby/object:Gem::Dependency
47
+ name: watir-webdriver
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Add support for Watir (http://github.com/watir/watir) in Rails.
63
+ email:
64
+ - jarmo.p@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - lib/watir/browser.rb
75
+ - lib/watir/rails.rb
76
+ - lib/watir/version.rb
77
+ - watir-rails.gemspec
78
+ homepage: http://github.com/watir/watir-rails
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.24
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Add support for Watir (http://github.com/watir/watir) in Rails.
102
+ test_files: []
103
+ has_rdoc: