watir-rails 1.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +4 -5
- data/CHANGES.md +54 -33
- data/README.md +1 -1
- data/Rakefile +3 -3
- data/gemfiles/Gemfile.rails-4.x +6 -0
- data/lib/watir/rails.rb +34 -22
- data/lib/watir/rails/browser.rb +45 -0
- data/lib/watir/rails/middleware.rb +50 -26
- data/lib/watir/version.rb +5 -5
- data/spec/support/watir.rb +3 -1
- data/spec/watir/{browser_spec.rb → rails/browser_spec.rb} +11 -11
- data/spec/watir/rails_spec.rb +20 -3
- data/watir-rails.gemspec +1 -1
- metadata +14 -17
- data/lib/watir/browser.rb +0 -67
- data/spec/support/fake_browser_with_goto.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51d6a45bcdb312a379e427c3a560c2a70aafe25b3aa2622721444d2903e50309
|
4
|
+
data.tar.gz: 4c80f41a3b0da65f8ec48b860badd3e71f651a83f50fababc325ac633ed7d5a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d5bbc1fc15eab822f650c956ce12dd252ac0a2071f11fe0fcdafbdc3f6d411255d5d190359e1099865a4bb7c25462e9d0317750350b2e993b36cf89904497ec
|
7
|
+
data.tar.gz: b245693600d488f7d89881243af9b3d1f87bb8e7ce603b19ead3739780512bd6c16cb0c066cd8ae32cc5a9476522050fd99c38f0a8a364e7d3d97b2e7eeb75dc
|
data/.travis.yml
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
rvm:
|
2
|
-
|
3
|
-
-
|
4
|
-
- 2.1.9
|
5
|
-
- ruby-head
|
2
|
+
- 2.6.3
|
3
|
+
- ruby-head
|
6
4
|
gemfile:
|
7
5
|
- gemfiles/Gemfile.rails-2.x
|
8
6
|
- gemfiles/Gemfile.rails-3.x
|
7
|
+
- gemfiles/Gemfile.rails-4.x
|
9
8
|
- Gemfile
|
10
9
|
notifications:
|
11
10
|
recipients:
|
12
|
-
- jarmo
|
11
|
+
- jarmo@jarmopertman.com
|
13
12
|
matrix:
|
14
13
|
allow_failures:
|
15
14
|
- rvm: ruby-head
|
data/CHANGES.md
CHANGED
@@ -1,33 +1,54 @@
|
|
1
|
-
###
|
2
|
-
|
3
|
-
* Fix
|
4
|
-
|
5
|
-
###
|
6
|
-
|
7
|
-
*
|
8
|
-
|
9
|
-
###
|
10
|
-
|
11
|
-
*
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
*
|
33
|
-
|
1
|
+
### 2.2.2 - 2020/06/04
|
2
|
+
|
3
|
+
* Fix a situation where checking if server is running without using specified port. PR #27 by Stefan Rotariu.
|
4
|
+
|
5
|
+
### 2.2.1 - 2019/05/12
|
6
|
+
|
7
|
+
* Fix EOFError on some environments. PR #25 by Slava Kardakov.
|
8
|
+
|
9
|
+
### 2.2.0 - 2019/05/08
|
10
|
+
|
11
|
+
* Add support for specifying custom server for test Rails instance. PR #23 by Alex Rodionov.
|
12
|
+
* Add support for cleaning up when test Rails server instance has served all requests. PR #23 by Alex Rodionov.
|
13
|
+
|
14
|
+
### 2.1.0 - 2019/03/19
|
15
|
+
|
16
|
+
* Add support for specifying Rails test-server port. PR #22 by Bartek Wilczek.
|
17
|
+
|
18
|
+
### 2.0.0 - 2016/09/24
|
19
|
+
|
20
|
+
* Add support for Watir 6.0.
|
21
|
+
|
22
|
+
### 1.2.1 - 2016/06/15
|
23
|
+
|
24
|
+
* Fix Browser#add_checker deprecation warning. PR #18 by Christophe Bliard.
|
25
|
+
|
26
|
+
### 1.2.0 - 2016/01/16
|
27
|
+
|
28
|
+
* Add support for running Rails on Puma server. PR #15 by Andrey Koleshko.
|
29
|
+
|
30
|
+
### 1.1.0 - 2015/07/22
|
31
|
+
|
32
|
+
* Remove strict `mime-types` dependency. See #13
|
33
|
+
|
34
|
+
### 1.0.4 - 2015/02/28
|
35
|
+
|
36
|
+
* Allow to set Watir::Rails.ignore_exceptions to false. PR #8 by Andrey Koleshko.
|
37
|
+
|
38
|
+
### 1.0.3 - 2013/11/02
|
39
|
+
|
40
|
+
* Make watir-rails working with Rails 2.3.x too.
|
41
|
+
|
42
|
+
### 1.0.2 - 2013/11/02
|
43
|
+
|
44
|
+
* Make sure that newest Rails is going to be installed on an empty system.
|
45
|
+
|
46
|
+
### 1.0.1 - 2013/11/01
|
47
|
+
|
48
|
+
* Add license to gemspec.
|
49
|
+
|
50
|
+
### 1.0.0 - 2013/10/05
|
51
|
+
|
52
|
+
* Add watir as a dependency to make it possible to use with watir-classic too.
|
53
|
+
* Add specs to keep the quality high.
|
54
|
+
* Documentation fixes.
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](http://travis-ci.org/watir/watir-rails)
|
4
4
|
[](https://coveralls.io/r/watir/watir-rails)
|
5
5
|
|
6
|
-
This gem makes
|
6
|
+
This gem makes [Watir](https://github.com/watir/watir) work with Rails.
|
7
7
|
|
8
8
|
|
9
9
|
## Installation
|
data/Rakefile
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
1
|
require "rspec/core/rake_task"
|
3
2
|
RSpec::Core::RakeTask.new(:spec)
|
4
3
|
|
5
|
-
task :
|
6
|
-
task :
|
4
|
+
task default: :spec
|
5
|
+
task release: :spec
|
6
|
+
require "bundler/gem_tasks"
|
7
7
|
|
8
8
|
require "yard"
|
9
9
|
YARD::Rake::YardocTask.new
|
data/lib/watir/rails.rb
CHANGED
@@ -10,7 +10,7 @@ rescue LoadError
|
|
10
10
|
require "initializer"
|
11
11
|
end
|
12
12
|
|
13
|
-
require File.expand_path("browser.rb", File.dirname(__FILE__))
|
13
|
+
require File.expand_path("rails/browser.rb", File.dirname(__FILE__))
|
14
14
|
require File.expand_path("rails/middleware.rb", File.dirname(__FILE__))
|
15
15
|
|
16
16
|
module Watir
|
@@ -18,23 +18,26 @@ module Watir
|
|
18
18
|
class << self
|
19
19
|
private :new
|
20
20
|
attr_reader :port, :middleware
|
21
|
-
attr_writer :ignore_exceptions
|
21
|
+
attr_writer :ignore_exceptions, :server
|
22
22
|
|
23
23
|
# Start the Rails server for tests.
|
24
24
|
# Will be called automatically by {Watir::Browser#initialize}.
|
25
|
-
|
25
|
+
#
|
26
|
+
# @param [Integer] port port for the Rails up to run on. If omitted random port will be picked.
|
27
|
+
def boot(port: nil)
|
28
|
+
@port = port || find_available_port
|
29
|
+
|
26
30
|
unless running?
|
27
31
|
@middleware = Middleware.new(app)
|
28
|
-
@port = find_available_port
|
29
32
|
|
30
33
|
@server_thread = Thread.new do
|
31
|
-
|
34
|
+
server.call @middleware, @port
|
32
35
|
end
|
33
36
|
|
34
37
|
Timeout.timeout(boot_timeout) { @server_thread.join(0.1) until running? }
|
35
38
|
end
|
36
|
-
rescue
|
37
|
-
raise
|
39
|
+
rescue Timeout::Error
|
40
|
+
raise Timeout::Error, "Rails Rack application timed out during boot"
|
38
41
|
end
|
39
42
|
|
40
43
|
# Host for Rails app under test. Default is {.local_host}.
|
@@ -65,6 +68,13 @@ module Watir
|
|
65
68
|
@middleware.error
|
66
69
|
end
|
67
70
|
|
71
|
+
# Returns true if there are pending requests to server.
|
72
|
+
#
|
73
|
+
# @return [Boolean]
|
74
|
+
def pending_requests?
|
75
|
+
@middleware.pending_requests?
|
76
|
+
end
|
77
|
+
|
68
78
|
# Set error rescued by the middleware.
|
69
79
|
#
|
70
80
|
# @param value
|
@@ -103,7 +113,7 @@ module Watir
|
|
103
113
|
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
|
104
114
|
return res.body == @app.object_id.to_s
|
105
115
|
end
|
106
|
-
rescue Errno::ECONNREFUSED, Errno::EBADF
|
116
|
+
rescue Errno::ECONNREFUSED, Errno::EBADF, EOFError
|
107
117
|
return false
|
108
118
|
end
|
109
119
|
|
@@ -137,22 +147,24 @@ module Watir
|
|
137
147
|
server.close if server
|
138
148
|
end
|
139
149
|
|
140
|
-
def
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
150
|
+
def server
|
151
|
+
@server ||= lambda do |app, port|
|
152
|
+
begin
|
153
|
+
require 'rack/handler/thin'
|
154
|
+
Thin::Logging.silent = true
|
155
|
+
return Rack::Handler::Thin.run(app, :Port => port)
|
156
|
+
rescue LoadError
|
157
|
+
end
|
147
158
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
159
|
+
begin
|
160
|
+
require 'rack/handler/puma'
|
161
|
+
return Rack::Handler::Puma.run(app, :Port => port, :Silent => true)
|
162
|
+
rescue LoadError
|
163
|
+
end
|
153
164
|
|
154
|
-
|
155
|
-
|
165
|
+
require 'rack/handler/webrick'
|
166
|
+
Rack::Handler::WEBrick.run(app, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
|
167
|
+
end
|
156
168
|
end
|
157
169
|
|
158
170
|
def legacy_rails?
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Watir
|
2
|
+
# Reopened Watir::Browser class for working with Rails
|
3
|
+
class Browser
|
4
|
+
# @private
|
5
|
+
alias_method :_original_initialize, :initialize
|
6
|
+
|
7
|
+
# Will start Rails instance for Watir automatically and then invoke the
|
8
|
+
# original Watir::Browser#initialize method.
|
9
|
+
def initialize(*args)
|
10
|
+
Rails.boot
|
11
|
+
_original_initialize *args
|
12
|
+
add_exception_hook unless Rails.ignore_exceptions?
|
13
|
+
end
|
14
|
+
|
15
|
+
# @private
|
16
|
+
alias_method :_original_goto, :goto
|
17
|
+
|
18
|
+
# Opens the url with the browser instance.
|
19
|
+
# Will add {Rails.host} and {Rails.port} to the url when path is specified.
|
20
|
+
#
|
21
|
+
# @example Go to the regular url:
|
22
|
+
# browser.goto "http://google.com"
|
23
|
+
#
|
24
|
+
# @example Go to the controller path:
|
25
|
+
# browser.goto home_path
|
26
|
+
#
|
27
|
+
# @param [String] url URL to be navigated to.
|
28
|
+
def goto(url)
|
29
|
+
url = "http://#{Rails.host}:#{Rails.port}#{url}" unless url =~ %r{^(about|data|https?):}i
|
30
|
+
_original_goto url
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def add_exception_hook
|
36
|
+
after_hooks.add do
|
37
|
+
if error = Rails.error
|
38
|
+
Rails.error = nil
|
39
|
+
raise error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -1,26 +1,50 @@
|
|
1
|
-
module Watir
|
2
|
-
class Rails
|
3
|
-
# @private
|
4
|
-
class Middleware
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
1
|
+
module Watir
|
2
|
+
class Rails
|
3
|
+
# @private
|
4
|
+
class Middleware
|
5
|
+
class PendingRequestsCounter
|
6
|
+
attr_reader :value
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@value = 0
|
10
|
+
@mutex = Mutex.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def increment
|
14
|
+
@mutex.synchronize { @value += 1 }
|
15
|
+
end
|
16
|
+
|
17
|
+
def decrement
|
18
|
+
@mutex.synchronize { @value -= 1 }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_accessor :error
|
23
|
+
|
24
|
+
def initialize(app)
|
25
|
+
@app = app
|
26
|
+
@counter = PendingRequestsCounter.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def pending_requests?
|
30
|
+
@counter.value > 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def call(env)
|
34
|
+
if env["PATH_INFO"] == "/__identify__"
|
35
|
+
[200, {}, [@app.object_id.to_s]]
|
36
|
+
else
|
37
|
+
@counter.increment
|
38
|
+
begin
|
39
|
+
@app.call(env)
|
40
|
+
rescue => e
|
41
|
+
@error = e
|
42
|
+
raise e
|
43
|
+
ensure
|
44
|
+
@counter.decrement
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/watir/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module Watir
|
2
|
-
class Rails
|
3
|
-
VERSION = "
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Watir
|
2
|
+
class Rails
|
3
|
+
VERSION = "2.2.2"
|
4
|
+
end
|
5
|
+
end
|
data/spec/support/watir.rb
CHANGED
@@ -6,22 +6,22 @@ describe Watir::Browser do
|
|
6
6
|
context "#initialize" do
|
7
7
|
it "starts Rails before opening the browser" do
|
8
8
|
expect(Watir::Rails).to receive(:boot)
|
9
|
-
expect_any_instance_of(Watir::Browser).to receive(:
|
9
|
+
expect_any_instance_of(Watir::Browser).to receive(:_original_initialize).and_call_original
|
10
10
|
|
11
11
|
Watir::Browser.new
|
12
12
|
end
|
13
13
|
|
14
|
-
it "does not add Exception
|
14
|
+
it "does not add Exception hook when exceptions are ignored" do
|
15
15
|
allow(Watir::Rails).to receive_messages(ignore_exceptions?: true, boot: nil)
|
16
16
|
|
17
|
-
expect_any_instance_of(Watir::Browser).not_to receive(:
|
17
|
+
expect_any_instance_of(Watir::Browser).not_to receive(:add_exception_hook)
|
18
18
|
Watir::Browser.new
|
19
19
|
end
|
20
20
|
|
21
|
-
it "adds Exception
|
21
|
+
it "adds Exception hook when exceptions are not ignored" do
|
22
22
|
allow(Watir::Rails).to receive_messages(ignore_exceptions?: false, boot: nil)
|
23
23
|
|
24
|
-
expect_any_instance_of(Watir::Browser).to receive(:
|
24
|
+
expect_any_instance_of(Watir::Browser).to receive(:add_exception_hook)
|
25
25
|
Watir::Browser.new
|
26
26
|
end
|
27
27
|
end
|
@@ -34,32 +34,32 @@ describe Watir::Browser do
|
|
34
34
|
let(:browser) { Watir::Browser.new }
|
35
35
|
|
36
36
|
it "uses Rails for paths specified as an url" do
|
37
|
-
expect(browser).to receive(:
|
37
|
+
expect(browser).to receive(:_original_goto).with("http://foo.com:42/foo/bar")
|
38
38
|
browser.goto("/foo/bar")
|
39
39
|
end
|
40
40
|
|
41
41
|
it "does not alter url with http:// scheme" do
|
42
|
-
expect(browser).to receive(:
|
42
|
+
expect(browser).to receive(:_original_goto).with("http://baz.org/lol")
|
43
43
|
browser.goto("http://baz.org/lol")
|
44
44
|
end
|
45
45
|
|
46
46
|
it "does not alter url with https:// scheme" do
|
47
|
-
expect(browser).to receive(:
|
47
|
+
expect(browser).to receive(:_original_goto).with("https://baz.org/lol")
|
48
48
|
browser.goto("https://baz.org/lol")
|
49
49
|
end
|
50
50
|
|
51
51
|
it "does not alter about:urls" do
|
52
|
-
expect(browser).to receive(:
|
52
|
+
expect(browser).to receive(:_original_goto).with("about:url")
|
53
53
|
browser.goto("about:url")
|
54
54
|
end
|
55
55
|
|
56
56
|
it "does not alter data:urls" do
|
57
|
-
expect(browser).to receive(:
|
57
|
+
expect(browser).to receive(:_original_goto).with("data:url")
|
58
58
|
browser.goto("data:url")
|
59
59
|
end
|
60
60
|
|
61
61
|
it "alters the unknown urls" do
|
62
|
-
expect(browser).to receive(:
|
62
|
+
expect(browser).to receive(:_original_goto).with("http://foo.com:42/xxx:yyy")
|
63
63
|
browser.goto("http://foo.com:42/xxx:yyy")
|
64
64
|
end
|
65
65
|
end
|
data/spec/watir/rails_spec.rb
CHANGED
@@ -9,9 +9,11 @@ describe Watir::Rails do
|
|
9
9
|
|
10
10
|
context ".boot" do
|
11
11
|
it "starts the server unless already running" do
|
12
|
+
server = ->(app, port) {}
|
12
13
|
allow(described_class).to receive_messages(app: double("app"), find_available_port: 42)
|
13
14
|
expect(described_class).to receive(:running?).twice.and_return(false, true)
|
14
|
-
expect(described_class).to receive(:
|
15
|
+
expect(described_class).to receive(:server).and_return(server)
|
16
|
+
expect(server).to receive(:call).once
|
15
17
|
|
16
18
|
described_class.boot
|
17
19
|
wait_until_server_started
|
@@ -20,16 +22,18 @@ describe Watir::Rails do
|
|
20
22
|
it "does nothing if server is already running" do
|
21
23
|
allow(described_class).to receive_messages(app: double("app"), find_available_port: 42)
|
22
24
|
expect(described_class).to receive(:running?).once.and_return(true)
|
23
|
-
expect(described_class).not_to receive(:
|
25
|
+
expect(described_class).not_to receive(:server)
|
24
26
|
|
25
27
|
described_class.boot
|
26
28
|
end
|
27
29
|
|
28
30
|
it "raises an error if Rails won't boot with timeout" do
|
31
|
+
server = ->(app, port) {}
|
29
32
|
allow(described_class).to receive_messages(app: double("app"),
|
30
33
|
find_available_port: 42, boot_timeout: 0.01)
|
31
34
|
expect(described_class).to receive(:running?).at_least(:twice).and_return(false)
|
32
|
-
expect(described_class).to receive(:
|
35
|
+
expect(described_class).to receive(:server).and_return(server)
|
36
|
+
expect(server).to receive(:call)
|
33
37
|
|
34
38
|
expect {
|
35
39
|
described_class.boot
|
@@ -41,6 +45,19 @@ describe Watir::Rails do
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
48
|
+
context ".server" do
|
49
|
+
it "allows to customize server" do
|
50
|
+
allow(described_class).to receive_messages(app: double("app"), find_available_port: 42)
|
51
|
+
allow(described_class).to receive(:running?).twice.and_return(false, true)
|
52
|
+
|
53
|
+
server = ->(app, port) {}
|
54
|
+
described_class.server = server
|
55
|
+
expect(server).to receive(:call)
|
56
|
+
|
57
|
+
described_class.boot
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
44
61
|
context ".host" do
|
45
62
|
it "@host if specified" do
|
46
63
|
described_class.host = "my_host"
|
data/watir-rails.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
|
19
19
|
gem.add_dependency "rack"
|
20
20
|
gem.add_dependency "rails"
|
21
|
-
gem.add_dependency "watir", "
|
21
|
+
gem.add_dependency "watir", ">= 6.0.0.beta4"
|
22
22
|
|
23
23
|
gem.add_development_dependency "yard"
|
24
24
|
gem.add_development_dependency "redcarpet"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watir-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarmo Pertman
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: watir
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 6.0.0.beta4
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 6.0.0.beta4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,14 +111,14 @@ files:
|
|
111
111
|
- Rakefile
|
112
112
|
- gemfiles/Gemfile.rails-2.x
|
113
113
|
- gemfiles/Gemfile.rails-3.x
|
114
|
-
-
|
114
|
+
- gemfiles/Gemfile.rails-4.x
|
115
115
|
- lib/watir/rails.rb
|
116
|
+
- lib/watir/rails/browser.rb
|
116
117
|
- lib/watir/rails/middleware.rb
|
117
118
|
- lib/watir/version.rb
|
118
119
|
- spec/spec_helper.rb
|
119
|
-
- spec/support/fake_browser_with_goto.rb
|
120
120
|
- spec/support/watir.rb
|
121
|
-
- spec/watir/browser_spec.rb
|
121
|
+
- spec/watir/rails/browser_spec.rb
|
122
122
|
- spec/watir/rails/middleware_spec.rb
|
123
123
|
- spec/watir/rails_spec.rb
|
124
124
|
- watir-rails.gemspec
|
@@ -126,7 +126,7 @@ homepage: http://github.com/watir/watir-rails
|
|
126
126
|
licenses:
|
127
127
|
- MIT
|
128
128
|
metadata: {}
|
129
|
-
post_install_message:
|
129
|
+
post_install_message:
|
130
130
|
rdoc_options: []
|
131
131
|
require_paths:
|
132
132
|
- lib
|
@@ -141,16 +141,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
|
-
|
145
|
-
|
146
|
-
signing_key:
|
144
|
+
rubygems_version: 3.0.3
|
145
|
+
signing_key:
|
147
146
|
specification_version: 4
|
148
147
|
summary: Use Watir (http://github.com/watir/watir) in Rails.
|
149
148
|
test_files:
|
150
149
|
- spec/spec_helper.rb
|
151
|
-
- spec/support/fake_browser_with_goto.rb
|
152
150
|
- spec/support/watir.rb
|
153
|
-
- spec/watir/browser_spec.rb
|
151
|
+
- spec/watir/rails/browser_spec.rb
|
154
152
|
- spec/watir/rails/middleware_spec.rb
|
155
153
|
- spec/watir/rails_spec.rb
|
156
|
-
has_rdoc:
|
data/lib/watir/browser.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
module Watir
|
2
|
-
# Reopened Watir::Browser class for working with Rails
|
3
|
-
class Browser
|
4
|
-
# @private
|
5
|
-
alias_method :original_initialize, :initialize
|
6
|
-
|
7
|
-
# Will start Rails instance for Watir automatically and then invoke the
|
8
|
-
# original Watir::Browser#initialize method.
|
9
|
-
def initialize(*args)
|
10
|
-
initialize_rails_with_watir *args
|
11
|
-
end
|
12
|
-
|
13
|
-
# Opens the url with the browser instance.
|
14
|
-
# Will add {Rails.host} and {Rails.port} to the url when path is specified.
|
15
|
-
#
|
16
|
-
# @example Go to the regular url:
|
17
|
-
# browser.goto "http://google.com"
|
18
|
-
#
|
19
|
-
# @example Go to the controller path:
|
20
|
-
# browser.goto home_path
|
21
|
-
#
|
22
|
-
# @param [String] url URL to be navigated to.
|
23
|
-
def goto(url)
|
24
|
-
url = "http://#{Rails.host}:#{Rails.port}#{url}" unless url =~ %r{^(about|data|https?):}i
|
25
|
-
_new_goto url
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def override_and_preserve_original_methods(*method_names, &block)
|
31
|
-
method_names.each do |method_name|
|
32
|
-
next if respond_to? "_original_#{method_name}", true
|
33
|
-
self.class.send :alias_method, "_original_#{method_name}", method_name
|
34
|
-
end
|
35
|
-
|
36
|
-
result = block.call
|
37
|
-
|
38
|
-
method_names.each do |method_name|
|
39
|
-
next if respond_to? "_new_#{method_name}", true
|
40
|
-
self.class.send :alias_method, "_new_#{method_name}", method_name
|
41
|
-
|
42
|
-
self.class.send :define_method, method_name do |*args|
|
43
|
-
send("_original_#{method_name}", *args)
|
44
|
-
#send("_new_#{method_name}", *args)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
result
|
49
|
-
end
|
50
|
-
|
51
|
-
def initialize_rails_with_watir(*args)
|
52
|
-
Rails.boot
|
53
|
-
override_and_preserve_original_methods(:goto) { original_initialize *args }
|
54
|
-
add_exception_checker unless Rails.ignore_exceptions?
|
55
|
-
end
|
56
|
-
|
57
|
-
def add_exception_checker
|
58
|
-
after_hooks.add do
|
59
|
-
if error = Rails.error
|
60
|
-
Rails.error = nil
|
61
|
-
raise error
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|