watir-rails 2.2.3 → 2.3.0

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
2
  SHA256:
3
- metadata.gz: '0890e02a5cef434105541f81252240ad701f28bb828643f84aaf6b6745eb6cbf'
4
- data.tar.gz: b13169b1ea1a2bbfa49b79968eb5568e3137e2319e48a5172e70ab7f0f50572d
3
+ metadata.gz: 70a4bf116e756c213c309ccd099175324a364a69bdf3e9e7b43889b2430220b3
4
+ data.tar.gz: 5debf047f4f0fef4474bc81b712dc47f085cc14989e4ae068bab2283f6cfb655
5
5
  SHA512:
6
- metadata.gz: 9aa0f04dfa0f53060fd48765c040f26158e647254bc9ca049c8ebc2bca4f89ef3bd2c117c7ccc2bc9c05a94b1a4a4c47a04c2f93eda59aeb835d72963d6624d7
7
- data.tar.gz: 264a48bb5458b09926950e32709184d909ce4e15123e90bc8ff2ae0f6091c16f4e1aab39b2d421ba1f087f86a7ae9f3f5cf59bfbcb4c352ab9b95b39830b8c16
6
+ metadata.gz: 28658a949209812b349e100afcf9a7d7850a09080f1bd23b4e784a9250b8a1c21c04f37d9cdccfeb07e60c0a13b095e3a3727ab3c99246ae433509d105ddd5ea
7
+ data.tar.gz: 7f2f3901a136c79515f2a323e95c302898db125ab478ffcb13b81069eafcddbe4e40d1b5462f2b48508d132415c58267a92dae0210e608e81ed410d1f8b0c14f
@@ -0,0 +1,53 @@
1
+ name: Run watir-rails CI
2
+
3
+ 'on':
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-20.04
12
+ continue-on-error: ${{ matrix.ruby-version == 'debug' }}
13
+ strategy:
14
+ matrix:
15
+ BUNDLE_GEMFILE: [gemfiles/Gemfile.rails-3.x, gemfiles/Gemfile.rails-4.x, Gemfile]
16
+ ruby-version: [2.6.3, debug]
17
+ exclude:
18
+ # rails-4.2 requires BigDecimal.new (dropped in ruby-2.7)
19
+ - { BUNDLE_GEMFILE: gemfiles/Gemfile.rails-4.x, ruby-version: debug }
20
+ # The issue on rails-3.2 + head is json-1.8.6 compat (simplecov
21
+ # uses it), we could potentially workaround it using, for example, Oj
22
+ - { BUNDLE_GEMFILE: gemfiles/Gemfile.rails-3.x, ruby-version: debug }
23
+ env:
24
+ BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.BUNDLE_GEMFILE }}
25
+ LCOV_REPORT_PATH: './coverage/lcov.info'
26
+
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+
30
+ - uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ # rails < 5 doesn't support bundler-2
34
+ bundler: 1
35
+ bundler-cache: true
36
+
37
+ - run: bundle exec rake
38
+
39
+ - uses: coverallsapp/github-action@master
40
+ with:
41
+ github-token: ${{ secrets.GITHUB_TOKEN }}
42
+ path-to-lcov: ${{ env.LCOV_REPORT_PATH }}
43
+ parallel: true
44
+ flag-name: ruby-${{ matrix.ruby-version }}_gemfile-${{ matrix.BUNDLE_GEMFILE }}
45
+
46
+ coveralls:
47
+ needs: test
48
+ runs-on: ubuntu-20.04
49
+ steps:
50
+ - uses: coverallsapp/github-action@master
51
+ with:
52
+ github-token: ${{ secrets.GITHUB_TOKEN }}
53
+ parallel-finished: true
data/.gitignore CHANGED
File without changes
data/.travis.yml CHANGED
@@ -2,7 +2,6 @@ rvm:
2
2
  - 2.6.3
3
3
  - ruby-head
4
4
  gemfile:
5
- - gemfiles/Gemfile.rails-2.x
6
5
  - gemfiles/Gemfile.rails-3.x
7
6
  - gemfiles/Gemfile.rails-4.x
8
7
  - Gemfile
@@ -12,4 +11,3 @@ notifications:
12
11
  matrix:
13
12
  allow_failures:
14
13
  - rvm: ruby-head
15
-
data/.yardopts CHANGED
File without changes
data/CHANGES.md CHANGED
@@ -1,7 +1,11 @@
1
+ ### 2.3.0 - 2023/02/18
2
+
3
+ * Make `Watir::Rails.boot` use previously selected port in subsequent calls. PR #34 by Bartek Bulat.
4
+
1
5
  ### 2.2.3 - 2021/04/16
2
6
 
3
7
  * Fix a possible initialization problem with Watir 7.0.0+. See #32.
4
-
8
+
5
9
  ### 2.2.2 - 2020/06/04
6
10
 
7
11
  * Fix a situation where checking if server is running without using specified port. PR #27 by Stefan Rotariu.
data/Gemfile CHANGED
@@ -2,4 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "coveralls", require: false
5
+ gem "simplecov", require: false
6
+ gem "simplecov-lcov", require: false
data/LICENSE CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
@@ -2,5 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec path: ".."
4
4
 
5
- gem "coveralls", require: false
6
- gem "rails", "~> 3.0"
5
+ gem "simplecov", require: false
6
+ gem "simplecov-lcov", require: false
7
+ gem "rails", "~> 3.0"
@@ -2,5 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec path: ".."
4
4
 
5
- gem "coveralls", require: false
5
+ gem "simplecov", require: false
6
+ gem "simplecov-lcov", require: false
6
7
  gem "rails", "~> 4.0"
@@ -1,45 +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
+ 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
+
File without changes
@@ -1,5 +1,5 @@
1
1
  module Watir
2
2
  class Rails
3
- VERSION = "2.2.3"
3
+ VERSION = "2.3.0"
4
4
  end
5
5
  end
data/lib/watir/rails.rb CHANGED
@@ -3,12 +3,7 @@ require "net/http"
3
3
  require "rack"
4
4
  require "watir"
5
5
 
6
- begin
7
- require "rails"
8
- rescue LoadError
9
- # Load legacy Rails
10
- require "initializer"
11
- end
6
+ require "rails"
12
7
 
13
8
  require File.expand_path("rails/browser.rb", File.dirname(__FILE__))
14
9
  require File.expand_path("rails/middleware.rb", File.dirname(__FILE__))
@@ -23,9 +18,10 @@ module Watir
23
18
  # Start the Rails server for tests.
24
19
  # Will be called automatically by {Watir::Browser#initialize}.
25
20
  #
26
- # @param [Integer] port port for the Rails up to run on. If omitted random port will be picked.
21
+ # @param [Integer] port port for the Rails up to run on. If omitted use
22
+ # previously selected port or select random available port.
27
23
  def boot(port: nil)
28
- @port = port || find_available_port
24
+ @port = port || @port || find_available_port
29
25
 
30
26
  unless running?
31
27
  @middleware = Middleware.new(app)
@@ -87,13 +83,7 @@ module Watir
87
83
  # @return [Boolean] true if exceptions should be ignored, false otherwise.
88
84
  def ignore_exceptions?
89
85
  if @ignore_exceptions.nil?
90
- show_exceptions = if legacy_rails?
91
- ::Rails.configuration.action_dispatch.show_exceptions
92
- else
93
- ::Rails.application.config.action_dispatch.show_exceptions
94
- end
95
-
96
- if show_exceptions
86
+ if ::Rails.application.config.action_dispatch.show_exceptions
97
87
  warn '[WARN] "action_dispatch.show_exceptions" is set to "true", disabling watir-rails exception catcher.'
98
88
  @ignore_exceptions = true
99
89
  end
@@ -121,15 +111,9 @@ module Watir
121
111
  #
122
112
  # @return [Object] Rails Rack app.
123
113
  def app
124
- legacy = legacy_rails?
125
114
  @app ||= Rack::Builder.new do
126
115
  map "/" do
127
- if legacy
128
- use ::Rails::Rack::Static
129
- run ActionController::Dispatcher.new
130
- else
131
- run ::Rails.application
132
- end
116
+ run ::Rails.application
133
117
  end
134
118
  end.to_app
135
119
  end
@@ -166,11 +150,6 @@ module Watir
166
150
  Rack::Handler::WEBrick.run(app, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
167
151
  end
168
152
  end
169
-
170
- def legacy_rails?
171
- ::Rails.version.to_f < 3.0
172
- end
173
-
174
153
  end
175
154
  end
176
155
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,17 @@
1
1
  require "simplecov"
2
- require 'coveralls'
3
2
 
4
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
3
+ if ENV["LCOV_REPORT_PATH"]
4
+ require "simplecov-lcov"
5
+
6
+ SimpleCov::Formatter::LcovFormatter.config do |c|
7
+ c.report_with_single_file = true
8
+ root_dir = File.expand_path('..', __dir__)
9
+ c.single_report_path = File.expand_path(ENV.fetch('LCOV_REPORT_PATH'), root_dir)
10
+ end
11
+
12
+ SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
13
+ end
14
+
5
15
  SimpleCov.start
6
16
 
7
17
  # Make sure that fake watir gems are loaded for specs.
@@ -12,4 +22,11 @@ require "watir/rails"
12
22
  RSpec.configure do |c|
13
23
  c.color = true
14
24
  c.order = :random
25
+
26
+ c.after do
27
+ described_class.instance_variable_set(:@port, nil)
28
+ described_class.instance_variable_set(:@server_thread, nil)
29
+ described_class.instance_variable_set(:@server, nil)
30
+ described_class.instance_variable_set(:@app, nil)
31
+ end
15
32
  end
@@ -1,11 +1,11 @@
1
- # Needed to simulate watir gem.
2
-
3
- module Watir
4
- class Browser
5
- def initialize(*args)
6
- end
7
-
8
- def goto(url)
9
- end
10
- end
11
- end
1
+ # Needed to simulate watir gem.
2
+
3
+ module Watir
4
+ class Browser
5
+ def initialize(*args)
6
+ end
7
+
8
+ def goto(url)
9
+ end
10
+ end
11
+ end
@@ -24,6 +24,21 @@ describe Watir::Browser do
24
24
  expect_any_instance_of(Watir::Browser).to receive(:add_exception_hook)
25
25
  Watir::Browser.new
26
26
  end
27
+
28
+ context 'when boot was already called' do
29
+ let(:app) { -> (_env) { [200, {}, 'OK'] } }
30
+ before do
31
+ Watir::Rails.instance_variable_set(:@app, app)
32
+ Watir::Rails.boot
33
+ end
34
+
35
+ it 'does not start new server thread' do
36
+ middleware = Watir::Rails.middleware
37
+
38
+ Watir::Browser.new
39
+ expect(middleware).to eq(Watir::Rails.middleware)
40
+ end
41
+ end
27
42
  end
28
43
 
29
44
  context "#goto" do
File without changes
@@ -7,6 +7,8 @@ describe Watir::Rails do
7
7
  described_class.instance_eval { @middleware = @port = @server_thread = @host = @app = nil }
8
8
  end
9
9
 
10
+ let(:thread) { described_class.instance_variable_get(:@server_thread) }
11
+
10
12
  context ".boot" do
11
13
  it "starts the server unless already running" do
12
14
  server = ->(app, port) {}
@@ -16,7 +18,8 @@ describe Watir::Rails do
16
18
  expect(server).to receive(:call).once
17
19
 
18
20
  described_class.boot
19
- wait_until_server_started
21
+
22
+ thread.join(10) || raise("Server thread not finished")
20
23
  end
21
24
 
22
25
  it "does nothing if server is already running" do
@@ -39,22 +42,21 @@ describe Watir::Rails do
39
42
  described_class.boot
40
43
  }.to raise_error(Timeout::Error)
41
44
  end
42
-
43
- def wait_until_server_started
44
- Timeout.timeout(10) { sleep 0.1 while described_class.instance_variable_get(:@server_thread).alive? }
45
- end
46
45
  end
47
46
 
48
47
  context ".server" do
48
+ let(:server) { ->(app, port) {} }
49
+
49
50
  it "allows to customize server" do
50
51
  allow(described_class).to receive_messages(app: double("app"), find_available_port: 42)
51
52
  allow(described_class).to receive(:running?).twice.and_return(false, true)
52
53
 
53
- server = ->(app, port) {}
54
54
  described_class.server = server
55
55
  expect(server).to receive(:call)
56
56
 
57
57
  described_class.boot
58
+
59
+ thread.join(10) || raise("Server thread not finished")
58
60
  end
59
61
  end
60
62
 
@@ -81,17 +83,7 @@ describe Watir::Rails do
81
83
  expect(described_class).not_to be_ignore_exceptions
82
84
  end
83
85
 
84
- it "true if Rails.action_dispatch.show_exceptions is set to true for older Rails" do
85
- allow(described_class).to receive_messages(legacy_rails?: true)
86
- described_class.ignore_exceptions = nil
87
- allow(::Rails).to receive_message_chain(:configuration,
88
- :action_dispatch, :show_exceptions).and_return(true)
89
-
90
- expect(described_class).to be_ignore_exceptions
91
- end
92
-
93
- it "true if Rails.action_dispatch.show_exceptions is set to true for Rails 3" do
94
- allow(described_class).to receive_messages(legacy_rails?: false)
86
+ it "true if Rails.action_dispatch.show_exceptions is set to true" do
95
87
  described_class.ignore_exceptions = nil
96
88
  allow(::Rails).to receive_message_chain(:application,
97
89
  :config, :action_dispatch, :show_exceptions).and_return(true)
@@ -99,17 +91,7 @@ describe Watir::Rails do
99
91
  expect(described_class).to be_ignore_exceptions
100
92
  end
101
93
 
102
- it "false if Rails.action_dispatch.show_exceptions is set to false for older Rails" do
103
- allow(described_class).to receive_messages(legacy_rails?: true)
104
- described_class.ignore_exceptions = nil
105
- allow(::Rails).to receive_message_chain(:configuration,
106
- :action_dispatch, :show_exceptions).and_return(false)
107
-
108
- expect(described_class).not_to be_ignore_exceptions
109
- end
110
-
111
- it "true if Rails.action_dispatch.show_exceptions is set to false for Rails 3" do
112
- allow(described_class).to receive_messages(legacy_rails?: false)
94
+ it "true if Rails.action_dispatch.show_exceptions is set to false" do
113
95
  described_class.ignore_exceptions = nil
114
96
  allow(::Rails).to receive_message_chain(:application,
115
97
  :config, :action_dispatch, :show_exceptions).and_return(false)
data/watir-rails.gemspec CHANGED
@@ -1,26 +1,27 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/watir/rails/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{Use Watir (http://github.com/watir/watir) in Rails.}
8
- gem.summary = %q{Use 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.license = "MIT"
17
- gem.version = Watir::Rails::VERSION
18
-
19
- gem.add_dependency "rack"
20
- gem.add_dependency "rails"
21
- gem.add_dependency "watir", ">= 6.0.0.beta4"
22
-
23
- gem.add_development_dependency "yard"
24
- gem.add_development_dependency "redcarpet"
25
- gem.add_development_dependency "rspec", "~> 3.0"
26
- end
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/watir/rails/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{Use Watir (http://github.com/watir/watir) in Rails.}
8
+ gem.summary = %q{Use 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.license = "MIT"
17
+ gem.version = Watir::Rails::VERSION
18
+ gem.required_ruby_version = ">= 2.4.0"
19
+
20
+ gem.add_dependency "rack"
21
+ gem.add_dependency "rails", ">= 3"
22
+ gem.add_dependency "watir", ">= 6.0.0.beta4"
23
+
24
+ gem.add_development_dependency "yard"
25
+ gem.add_development_dependency "redcarpet"
26
+ gem.add_development_dependency "rspec", "~> 3.0"
27
+ end
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: 2.2.3
4
+ version: 2.3.0
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: 2021-04-16 00:00:00.000000000 Z
11
+ date: 2023-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: watir
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +101,7 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
+ - ".github/workflows/ci.yml"
104
105
  - ".gitignore"
105
106
  - ".travis.yml"
106
107
  - ".yardopts"
@@ -109,7 +110,6 @@ files:
109
110
  - LICENSE
110
111
  - README.md
111
112
  - Rakefile
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
@@ -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
@@ -134,16 +134,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: '0'
137
+ version: 2.4.0
138
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.7.6.2
146
- signing_key:
144
+ rubygems_version: 3.3.25
145
+ signing_key:
147
146
  specification_version: 4
148
147
  summary: Use Watir (http://github.com/watir/watir) in Rails.
149
148
  test_files:
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec path: ".."
4
-
5
- gem "coveralls", require: false
6
- gem "rails", "~> 2.0"