watir-rack 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +14 -0
- data/.yardopts +6 -0
- data/Gemfile +5 -0
- data/LICENSE +45 -0
- data/README.md +46 -0
- data/Rakefile +9 -0
- data/gemfiles/Gemfile.hanami-1.3.x +6 -0
- data/lib/watir/rack.rb +142 -0
- data/lib/watir/rack/browser.rb +33 -0
- data/lib/watir/rack/middleware.rb +50 -0
- data/lib/watir/version.rb +5 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/watir.rb +11 -0
- data/spec/watir/rack/browser_spec.rb +52 -0
- data/spec/watir/rack/middleware_spec.rb +30 -0
- data/spec/watir/rack_spec.rb +110 -0
- data/watir-rack.gemspec +26 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 18c5b0959f42b1fcd75d23e3e2aa590767a60fd8b3631eb8fc5130b93602e9aa
|
4
|
+
data.tar.gz: 354a863eed8965c1d551a4d2aa59eb00e9c902e4a9a3e4fa3cbf823fa06cd6bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2d330f80301223e6a396a43cd5bb17ccd732e8c91eb36bec3e24a90ab4c569cd7b94d47d2aaea1160fa34cb314f815d8f9b2ccb9a483d6c0f1e1c6c1d20ac2b9
|
7
|
+
data.tar.gz: ed2a46cda21d09e697769de3a07e362686bf3f250aa68186914e3cb66bc62c237cbe2d08f918360a88734e210c6d2c00230871fe22c156adc5943db2d6791149
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Copyright (c) 2019 Marcelo Jacobus
|
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.
|
23
|
+
|
24
|
+
Copyright (c) 2012-2013 Jarmo Pertman
|
25
|
+
|
26
|
+
MIT License
|
27
|
+
|
28
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
29
|
+
a copy of this software and associated documentation files (the
|
30
|
+
"Software"), to deal in the Software without restriction, including
|
31
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
32
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
33
|
+
permit persons to whom the Software is furnished to do so, subject to
|
34
|
+
the following conditions:
|
35
|
+
|
36
|
+
The above copyright notice and this permission notice shall be
|
37
|
+
included in all copies or substantial portions of the Software.
|
38
|
+
|
39
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
40
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
41
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
42
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
43
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
44
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
45
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Watir::Rack
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/watir-rack.png)](http://badge.fury.io/rb/watir-rack)
|
3
|
+
[![Build Status](https://api.travis-ci.org/mjacobus/watir-rack.png)](http://travis-ci.org/mjacobus/watir-rack)
|
4
|
+
[![Coverage](https://coveralls.io/repos/mjacobus/watir-rack/badge.png?branch=master)](https://coveralls.io/r/mjacobus/watir-rack)
|
5
|
+
|
6
|
+
This gem makes [Watir](https://github.com/watir/watir) work with any Rack App.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this code to your Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
group :test do
|
14
|
+
gem "watir-rack"
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Just use Watir like you've always done in your requests/integration tests:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
Watir::Rack.app = Hanami.app
|
24
|
+
|
25
|
+
browser = Watir::Browser.new
|
26
|
+
browser.goto home_path
|
27
|
+
browser.text_field(name: "first").set "Jarmo"
|
28
|
+
browser.text_field(name: "last").set "Pertman"
|
29
|
+
browser.button(name: "sign_in").click
|
30
|
+
```
|
31
|
+
|
32
|
+
## Limitations
|
33
|
+
|
34
|
+
* This is a [quick] adaptation of [watir-rails](https://github.com/watir/watir-rails). All the heavy lifting was done by those folks.
|
35
|
+
|
36
|
+
|
37
|
+
## Contributors
|
38
|
+
|
39
|
+
* [Jarmo Pertman](https://github.com/jarmo)
|
40
|
+
* [Alex Rodionov](https://github.com/p0deje)
|
41
|
+
* [Marcelo Jacobus](https://github.com/mjacobus)
|
42
|
+
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
See [LICENSE](https://github.com/mjacobus/watir-rack/blob/master/LICENSE).
|
data/Rakefile
ADDED
data/lib/watir/rack.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "net/http"
|
3
|
+
require "rack"
|
4
|
+
require "watir"
|
5
|
+
|
6
|
+
require File.expand_path("rack/browser.rb", File.dirname(__FILE__))
|
7
|
+
require File.expand_path("rack/middleware.rb", File.dirname(__FILE__))
|
8
|
+
|
9
|
+
module Watir
|
10
|
+
class Rack
|
11
|
+
class << self
|
12
|
+
private :new
|
13
|
+
attr_accessor :test_app
|
14
|
+
attr_reader :port, :middleware
|
15
|
+
attr_writer :server
|
16
|
+
attr_writer :port
|
17
|
+
|
18
|
+
# Start the Rack
|
19
|
+
# Will be called automatically by {Watir::Browser#initialize}.
|
20
|
+
#
|
21
|
+
# @param [Integer] port port for the Rack
|
22
|
+
def boot(port: nil)
|
23
|
+
unless running?
|
24
|
+
@middleware = Middleware.new(app)
|
25
|
+
@port = port || find_available_port
|
26
|
+
|
27
|
+
@server_thread = Thread.new do
|
28
|
+
server.call @middleware, @port
|
29
|
+
end
|
30
|
+
|
31
|
+
Timeout.timeout(boot_timeout) { @server_thread.join(0.1) until running? }
|
32
|
+
end
|
33
|
+
rescue Timeout::Error
|
34
|
+
raise Timeout::Error, "Rack Rack application timed out during boot"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Host for Rack app under test. Default is {.local_host}.
|
38
|
+
#
|
39
|
+
# @return [String] Host for Rack app under test.
|
40
|
+
def host
|
41
|
+
@host || local_host
|
42
|
+
end
|
43
|
+
|
44
|
+
# Set host for Rack app. Will be used by {Browser#goto} method.
|
45
|
+
#
|
46
|
+
# @param [String] host host to use when using {Browser#goto}.
|
47
|
+
def host=(host)
|
48
|
+
@host = host
|
49
|
+
end
|
50
|
+
|
51
|
+
# Local host for Rack app under test.
|
52
|
+
#
|
53
|
+
# @return [String] Local host with the value of "127.0.0.1".
|
54
|
+
def local_host
|
55
|
+
"127.0.0.1"
|
56
|
+
end
|
57
|
+
|
58
|
+
# Error rescued by the middleware.
|
59
|
+
#
|
60
|
+
# @return [Exception or NilClass]
|
61
|
+
def error
|
62
|
+
@middleware.error
|
63
|
+
end
|
64
|
+
|
65
|
+
# Returns true if there are pending requests to server.
|
66
|
+
#
|
67
|
+
# @return [Boolean]
|
68
|
+
def pending_requests?
|
69
|
+
@middleware.pending_requests?
|
70
|
+
end
|
71
|
+
|
72
|
+
# Set error rescued by the middleware.
|
73
|
+
#
|
74
|
+
# @param value
|
75
|
+
def error=(value)
|
76
|
+
@middleware.error = value
|
77
|
+
end
|
78
|
+
|
79
|
+
# Check if Rack app under test is running.
|
80
|
+
#
|
81
|
+
# @return [Boolean] true when Rack app under test is running, false otherwise.
|
82
|
+
def running?
|
83
|
+
return false if @server_thread && @server_thread.join(0)
|
84
|
+
|
85
|
+
res = Net::HTTP.start(local_host, @port) { |http| http.get('/__identify__') }
|
86
|
+
|
87
|
+
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
|
88
|
+
return res.body == @app.object_id.to_s
|
89
|
+
end
|
90
|
+
rescue Errno::ECONNREFUSED, Errno::EBADF
|
91
|
+
return false
|
92
|
+
end
|
93
|
+
|
94
|
+
# Rack app under test.
|
95
|
+
#
|
96
|
+
# @return [Object] Rack Rack app.
|
97
|
+
def app
|
98
|
+
test_app = self.test_app
|
99
|
+
|
100
|
+
@app ||= ::Rack::Builder.new do
|
101
|
+
map "/" do
|
102
|
+
run test_app
|
103
|
+
end
|
104
|
+
end.to_app
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def boot_timeout
|
110
|
+
60
|
111
|
+
end
|
112
|
+
|
113
|
+
def find_available_port
|
114
|
+
server = TCPServer.new(local_host, 0)
|
115
|
+
server.addr[1]
|
116
|
+
ensure
|
117
|
+
server.close if server
|
118
|
+
end
|
119
|
+
|
120
|
+
def server
|
121
|
+
@server ||= lambda do |app, port|
|
122
|
+
begin
|
123
|
+
require 'rack/handler/thin'
|
124
|
+
Thin::Logging.silent = true
|
125
|
+
return ::Rack::Handler::Thin.run(app, :Port => port)
|
126
|
+
rescue LoadError
|
127
|
+
end
|
128
|
+
|
129
|
+
begin
|
130
|
+
require 'rack/handler/puma'
|
131
|
+
return ::Rack::Handler::Puma.run(app, :Port => port, :Silent => true)
|
132
|
+
rescue LoadError
|
133
|
+
end
|
134
|
+
|
135
|
+
require 'rack/handler/webrick'
|
136
|
+
::Rack::Handler::WEBrick.run(app, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Watir
|
2
|
+
# Reopened Watir::Browser class for working with Rack
|
3
|
+
class Browser
|
4
|
+
# @private
|
5
|
+
alias_method :_original_initialize, :initialize
|
6
|
+
|
7
|
+
# Will start Rack instance for Watir automatically and then invoke the
|
8
|
+
# original Watir::Browser#initialize method.
|
9
|
+
def initialize(*args)
|
10
|
+
Rack.boot
|
11
|
+
_original_initialize *args
|
12
|
+
end
|
13
|
+
|
14
|
+
# @private
|
15
|
+
alias_method :_original_goto, :goto
|
16
|
+
|
17
|
+
# Opens the url with the browser instance.
|
18
|
+
# Will add {Rack.host} and {Rack.port} to the url when path is specified.
|
19
|
+
#
|
20
|
+
# @example Go to the regular url:
|
21
|
+
# browser.goto "http://google.com"
|
22
|
+
#
|
23
|
+
# @example Go to the controller path:
|
24
|
+
# browser.goto home_path
|
25
|
+
#
|
26
|
+
# @param [String] url URL to be navigated to.
|
27
|
+
def goto(url)
|
28
|
+
url = "http://#{Rack.host}:#{Rack.port}#{url}" unless url =~ %r{^(about|data|https?):}i
|
29
|
+
_original_goto url
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Watir
|
2
|
+
class Rack
|
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/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
5
|
+
SimpleCov.start
|
6
|
+
|
7
|
+
# Make sure that fake watir gems are loaded for specs.
|
8
|
+
$LOAD_PATH.unshift File.expand_path("support", File.dirname(__FILE__))
|
9
|
+
|
10
|
+
require "watir/rack"
|
11
|
+
|
12
|
+
RSpec.configure do |c|
|
13
|
+
c.color = true
|
14
|
+
c.order = :random
|
15
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Watir::Browser do
|
4
|
+
before { allow(Watir::Rack).to receive_messages(ignore_exceptions?: true) }
|
5
|
+
|
6
|
+
context "#initialize" do
|
7
|
+
it "starts Rack before opening the browser" do
|
8
|
+
expect(Watir::Rack).to receive(:boot)
|
9
|
+
expect_any_instance_of(Watir::Browser).to receive(:_original_initialize).and_call_original
|
10
|
+
|
11
|
+
Watir::Browser.new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "#goto" do
|
16
|
+
before do
|
17
|
+
allow(Watir::Rack).to receive_messages(host: "foo.com", port: 42, boot: nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:browser) { Watir::Browser.new }
|
21
|
+
|
22
|
+
it "uses Rack for paths specified as an url" do
|
23
|
+
expect(browser).to receive(:_original_goto).with("http://foo.com:42/foo/bar")
|
24
|
+
browser.goto("/foo/bar")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "does not alter url with http:// scheme" do
|
28
|
+
expect(browser).to receive(:_original_goto).with("http://baz.org/lol")
|
29
|
+
browser.goto("http://baz.org/lol")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "does not alter url with https:// scheme" do
|
33
|
+
expect(browser).to receive(:_original_goto).with("https://baz.org/lol")
|
34
|
+
browser.goto("https://baz.org/lol")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "does not alter about:urls" do
|
38
|
+
expect(browser).to receive(:_original_goto).with("about:url")
|
39
|
+
browser.goto("about:url")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not alter data:urls" do
|
43
|
+
expect(browser).to receive(:_original_goto).with("data:url")
|
44
|
+
browser.goto("data:url")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "alters the unknown urls" do
|
48
|
+
expect(browser).to receive(:_original_goto).with("http://foo.com:42/xxx:yyy")
|
49
|
+
browser.goto("http://foo.com:42/xxx:yyy")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Watir::Rack::Middleware do
|
4
|
+
let(:app) { double("app") }
|
5
|
+
let(:middleware) { described_class.new app }
|
6
|
+
|
7
|
+
context "#call" do
|
8
|
+
it "/__identify__ returns app id" do
|
9
|
+
expect(app).not_to receive(:call)
|
10
|
+
expect(middleware.call("PATH_INFO" => "/__identify__")).to eq([200, {}, [app.object_id.to_s]])
|
11
|
+
end
|
12
|
+
|
13
|
+
it "other requests are forwarded to the app" do
|
14
|
+
env = {}
|
15
|
+
expect(app).to receive(:call).with(env)
|
16
|
+
middleware.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "errors are stored and re-raised" do
|
20
|
+
error = RuntimeError.new
|
21
|
+
allow(app).to receive(:call).and_raise error
|
22
|
+
|
23
|
+
expect {
|
24
|
+
middleware.call({})
|
25
|
+
}.to raise_error(error)
|
26
|
+
|
27
|
+
expect(middleware.error).to eq(error)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Watir::Rack do
|
4
|
+
before do
|
5
|
+
allow(described_class).to receive(:warn)
|
6
|
+
described_class.instance_eval { @middleware = @port = @server_thread = @host = @app = nil }
|
7
|
+
end
|
8
|
+
|
9
|
+
context ".boot" do
|
10
|
+
it "starts the server unless already running" do
|
11
|
+
server = ->(app, port) {}
|
12
|
+
allow(described_class).to receive_messages(app: double("app"), find_available_port: 42)
|
13
|
+
expect(described_class).to receive(:running?).twice.and_return(false, true)
|
14
|
+
expect(described_class).to receive(:server).and_return(server)
|
15
|
+
expect(server).to receive(:call).once
|
16
|
+
|
17
|
+
described_class.boot
|
18
|
+
wait_until_server_started
|
19
|
+
end
|
20
|
+
|
21
|
+
it "does nothing if server is already running" do
|
22
|
+
allow(described_class).to receive_messages(app: double("app"), find_available_port: 42)
|
23
|
+
expect(described_class).to receive(:running?).once.and_return(true)
|
24
|
+
expect(described_class).not_to receive(:server)
|
25
|
+
|
26
|
+
described_class.boot
|
27
|
+
end
|
28
|
+
|
29
|
+
it "raises an error if Rack won't boot with timeout" do
|
30
|
+
server = ->(app, port) {}
|
31
|
+
allow(described_class).to receive_messages(app: double("app"),
|
32
|
+
find_available_port: 42, boot_timeout: 0.01)
|
33
|
+
expect(described_class).to receive(:running?).at_least(:twice).and_return(false)
|
34
|
+
expect(described_class).to receive(:server).and_return(server)
|
35
|
+
expect(server).to receive(:call)
|
36
|
+
|
37
|
+
expect {
|
38
|
+
described_class.boot
|
39
|
+
}.to raise_error(Timeout::Error)
|
40
|
+
end
|
41
|
+
|
42
|
+
def wait_until_server_started
|
43
|
+
Timeout.timeout(10) { sleep 0.1 while described_class.instance_variable_get(:@server_thread).alive? }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context ".server" do
|
48
|
+
it "allows to customize server" do
|
49
|
+
allow(described_class).to receive_messages(app: double("app"), find_available_port: 42)
|
50
|
+
allow(described_class).to receive(:running?).twice.and_return(false, true)
|
51
|
+
|
52
|
+
server = ->(app, port) {}
|
53
|
+
described_class.server = server
|
54
|
+
expect(server).to receive(:call)
|
55
|
+
|
56
|
+
described_class.boot
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context ".host" do
|
61
|
+
it "@host if specified" do
|
62
|
+
described_class.host = "my_host"
|
63
|
+
expect(described_class.host).to eq("my_host")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "local_host if @host is not specified" do
|
67
|
+
described_class.host = nil
|
68
|
+
expect(described_class.host).to eq("127.0.0.1")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context ".running?" do
|
73
|
+
it "false if server thread is running" do
|
74
|
+
fake_thread = double("thread", join: :still_running)
|
75
|
+
described_class.instance_variable_set(:@server_thread, fake_thread)
|
76
|
+
|
77
|
+
expect(described_class).not_to be_running
|
78
|
+
end
|
79
|
+
|
80
|
+
it "false if server cannot be accessed" do
|
81
|
+
fake_thread = double("thread", join: nil)
|
82
|
+
described_class.instance_variable_set(:@server_thread, fake_thread)
|
83
|
+
|
84
|
+
expect(Net::HTTP).to receive(:start).and_raise Errno::ECONNREFUSED
|
85
|
+
expect(described_class).not_to be_running
|
86
|
+
end
|
87
|
+
|
88
|
+
it "false if server response is not success" do
|
89
|
+
fake_thread = double("thread", join: nil)
|
90
|
+
described_class.instance_variable_set(:@server_thread, fake_thread)
|
91
|
+
app = double("app")
|
92
|
+
described_class.instance_variable_set(:@app, app)
|
93
|
+
|
94
|
+
response = double(Net::HTTPSuccess, is_a?: false)
|
95
|
+
expect(Net::HTTP).to receive(:start).and_return response
|
96
|
+
expect(described_class).not_to be_running
|
97
|
+
end
|
98
|
+
|
99
|
+
it "true if server response is success" do
|
100
|
+
fake_thread = double("thread", join: nil)
|
101
|
+
described_class.instance_variable_set(:@server_thread, fake_thread)
|
102
|
+
app = double("app")
|
103
|
+
described_class.instance_variable_set(:@app, app)
|
104
|
+
|
105
|
+
response = double(Net::HTTPSuccess, is_a?: true, body: app.object_id.to_s)
|
106
|
+
expect(Net::HTTP).to receive(:start).and_return response
|
107
|
+
expect(described_class).to be_running
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
data/watir-rack.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
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{Use Watir (http://github.com/watir/watir) in Rack.}
|
8
|
+
gem.summary = %q{Use Watir (http://github.com/watir/watir) in Rack.}
|
9
|
+
gem.homepage = "http://github.com/mjacobus/watir-rack"
|
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-rack"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.license = "MIT"
|
17
|
+
gem.version = Watir::Rack::VERSION
|
18
|
+
|
19
|
+
gem.add_dependency "rack"
|
20
|
+
gem.add_dependency "watir", ">= 6.0.0.beta4"
|
21
|
+
|
22
|
+
gem.add_development_dependency "watir-rack"
|
23
|
+
gem.add_development_dependency "yard"
|
24
|
+
gem.add_development_dependency "redcarpet"
|
25
|
+
gem.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watir-rack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jarmo Pertman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: watir
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.0.0.beta4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 6.0.0.beta4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: watir-rack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redcarpet
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: Use Watir (http://github.com/watir/watir) in Rack.
|
98
|
+
email:
|
99
|
+
- jarmo.p@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- ".yardopts"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- gemfiles/Gemfile.hanami-1.3.x
|
112
|
+
- lib/watir/rack.rb
|
113
|
+
- lib/watir/rack/browser.rb
|
114
|
+
- lib/watir/rack/middleware.rb
|
115
|
+
- lib/watir/version.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/support/watir.rb
|
118
|
+
- spec/watir/rack/browser_spec.rb
|
119
|
+
- spec/watir/rack/middleware_spec.rb
|
120
|
+
- spec/watir/rack_spec.rb
|
121
|
+
- watir-rack.gemspec
|
122
|
+
homepage: http://github.com/mjacobus/watir-rack
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.7.6
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Use Watir (http://github.com/watir/watir) in Rack.
|
146
|
+
test_files:
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
- spec/support/watir.rb
|
149
|
+
- spec/watir/rack/browser_spec.rb
|
150
|
+
- spec/watir/rack/middleware_spec.rb
|
151
|
+
- spec/watir/rack_spec.rb
|