watir-rails 1.2.1 → 2.2.2

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
- SHA1:
3
- metadata.gz: ae7a57e6b5536cac083dfa83bffa44461bd34d0f
4
- data.tar.gz: 62d7d8fcf2a10ed6ca3ea85df33cb102bcea39c3
2
+ SHA256:
3
+ metadata.gz: 51d6a45bcdb312a379e427c3a560c2a70aafe25b3aa2622721444d2903e50309
4
+ data.tar.gz: 4c80f41a3b0da65f8ec48b860badd3e71f651a83f50fababc325ac633ed7d5a9
5
5
  SHA512:
6
- metadata.gz: 48e9fac9f32993daf3fa757908413deb595e66362934a91b93aa571313ceac211d4f3ff6be886e72629f6622fc3ff033a2af73be7b1afe3a00c18f76c9393f08
7
- data.tar.gz: eaf0dea201e969a9fc4079fb8584abe730c9f94222902dadf02b5210557150643ad44719eab9ed998bfdcda66f392152e24f64a8087e9c3f1512536212bc26d5
6
+ metadata.gz: 3d5bbc1fc15eab822f650c956ce12dd252ac0a2071f11fe0fcdafbdc3f6d411255d5d190359e1099865a4bb7c25462e9d0317750350b2e993b36cf89904497ec
7
+ data.tar.gz: b245693600d488f7d89881243af9b3d1f87bb8e7ce603b19ead3739780512bd6c16cb0c066cd8ae32cc5a9476522050fd99c38f0a8a364e7d3d97b2e7eeb75dc
@@ -1,15 +1,14 @@
1
1
  rvm:
2
- - 2.3.1
3
- - 2.2.5
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.p@gmail.com
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
- ### 1.2.1 - 2016/06/15
2
-
3
- * Fix Browser#add_checker deprecation warning. PR #18 by Christophe Bliard.
4
-
5
- ### 1.2.0 - 2016/01/16
6
-
7
- * Add support for running Rails on Puma server. PR #15 by Andrey Koleshko.
8
-
9
- ### 1.1.0 - 2015/07/22
10
-
11
- * Remove strict `mime-types` dependency. See #13
12
-
13
- ### 1.0.4 - 2015/02/28
14
-
15
- * Allow to set Watir::Rails.ignore_exceptions to false. PR #8 by Andrey Koleshko.
16
-
17
- ### 1.0.3 - 2013/11/02
18
-
19
- * Make watir-rails working with Rails 2.3.x too.
20
-
21
- ### 1.0.2 - 2013/11/02
22
-
23
- * Make sure that newest Rails is going to be installed on an empty system.
24
-
25
- ### 1.0.1 - 2013/11/01
26
-
27
- * Add license to gemspec.
28
-
29
- ### 1.0.0 - 2013/10/05
30
-
31
- * Add watir as a dependency to make it possible to use with watir-classic too.
32
- * Add specs to keep the quality high.
33
- * Documentation fixes.
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
  [![Build Status](https://api.travis-ci.org/watir/watir-rails.png)](http://travis-ci.org/watir/watir-rails)
4
4
  [![Coverage](https://coveralls.io/repos/watir/watir-rails/badge.png?branch=master)](https://coveralls.io/r/watir/watir-rails)
5
5
 
6
- This gem makes the [Watir](https://github.com/watir/watir) work with Rails.
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 :default => :spec
6
- task :build => :spec
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
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: ".."
4
+
5
+ gem "coveralls", require: false
6
+ gem "rails", "~> 4.0"
@@ -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
- def boot
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
- run_default_server @middleware, @port
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 TimeoutError
37
- raise TimeoutError, "Rails Rack application timed out during boot"
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 run_default_server(app, port)
141
- begin
142
- require 'rack/handler/thin'
143
- Thin::Logging.silent = true
144
- return Rack::Handler::Thin.run(app, :Port => port)
145
- rescue LoadError
146
- end
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
- begin
149
- require 'rack/handler/puma'
150
- return Rack::Handler::Puma.run(app, :Port => port, :Silent => true)
151
- rescue LoadError
152
- end
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
- require 'rack/handler/webrick'
155
- Rack::Handler::WEBrick.run(app, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
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
- attr_accessor :error
6
-
7
- def initialize(app)
8
- @app = app
9
- end
10
-
11
- def call(env)
12
- if env["PATH_INFO"] == "/__identify__"
13
- [200, {}, [@app.object_id.to_s]]
14
- else
15
- begin
16
- @app.call(env)
17
- rescue => e
18
- @error = e
19
- raise e
20
- end
21
- end
22
- end
23
- end
24
-
25
- end
26
- end
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
@@ -1,5 +1,5 @@
1
- module Watir
2
- class Rails
3
- VERSION = "1.2.1"
4
- end
5
- end
1
+ module Watir
2
+ class Rails
3
+ VERSION = "2.2.2"
4
+ end
5
+ end
@@ -3,7 +3,9 @@
3
3
  module Watir
4
4
  class Browser
5
5
  def initialize(*args)
6
- require File.expand_path("fake_browser_with_goto", File.dirname(__FILE__))
6
+ end
7
+
8
+ def goto(url)
7
9
  end
8
10
  end
9
11
  end
@@ -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(:original_initialize).and_call_original
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 checker when exceptions are ignored" do
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(:add_exception_checker)
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 checker when exceptions are not ignored" do
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(:add_exception_checker)
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(:_new_goto).with("http://foo.com:42/foo/bar")
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(:_new_goto).with("http://baz.org/lol")
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(:_new_goto).with("https://baz.org/lol")
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(:_new_goto).with("about:url")
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(:_new_goto).with("data:url")
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(:_new_goto).with("http://foo.com:42/xxx:yyy")
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
@@ -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(:run_default_server).once
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(:run_default_server)
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(:run_default_server)
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"
@@ -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", "~> 5.0"
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: 1.2.1
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: 2016-06-15 00:00:00.000000000 Z
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: '5.0'
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: '5.0'
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
- - lib/watir/browser.rb
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
- rubyforge_project:
145
- rubygems_version: 2.4.4
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:
@@ -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
-
@@ -1,8 +0,0 @@
1
- # Needed to simulate watir driver's gem (watir-webdriver or watir-classic).
2
-
3
- module Watir
4
- class Browser
5
- def goto(*args)
6
- end
7
- end
8
- end