watir-hanami 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 +44 -0
- data/Rakefile +9 -0
- data/gemfiles/Gemfile.hanami-1.3.x +6 -0
- data/lib/watir/hanami.rb +139 -0
- data/lib/watir/hanami/browser.rb +33 -0
- data/lib/watir/hanami/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/hanami/browser_spec.rb +52 -0
- data/spec/watir/hanami/middleware_spec.rb +30 -0
- data/spec/watir/hanami_spec.rb +110 -0
- data/watir-hanami.gemspec +26 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ee4ea0794418290819af42cfade2afa442f1d8b660a1d4c4aae32ffde47e5277
|
4
|
+
data.tar.gz: caea98037cdabfffa353ee2f6220043f4ce78ad61fb5cf6b56ca944229227ee6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abf2b4c1e099e356002e68067bfb93b3e683bcd3a478cbc02b74171898acf719de4032dd016f177ce4e4c87b324c7bb0c3f6954521772b8e35243734af68f070
|
7
|
+
data.tar.gz: d81fd04dd35ab6469e8029e2e5ad5c81e4431faf2acc2a67f8d1c8c51d150500bc5be6a40538c700e9bfc9fdfc3b271e261988ebf25618acdbee6a27957350d8
|
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,44 @@
|
|
1
|
+
# Watir::Hanami
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/watir-hanami.png)](http://badge.fury.io/rb/watir-hanami)
|
3
|
+
[![Build Status](https://api.travis-ci.org/mjacobus/watir-hanami.png)](http://travis-ci.org/mjacobus/watir-hanami)
|
4
|
+
[![Coverage](https://coveralls.io/repos/mjacobus/watir-hanami/badge.png?branch=master)](https://coveralls.io/r/mjacobus/watir-hanami)
|
5
|
+
|
6
|
+
This gem makes [Watir](https://github.com/watir/watir) work with Hanami.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this code to your Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
group :test do
|
14
|
+
gem "watir-hanami"
|
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
|
+
browser = Watir::Browser.new
|
24
|
+
browser.goto home_path
|
25
|
+
browser.text_field(name: "first").set "Jarmo"
|
26
|
+
browser.text_field(name: "last").set "Pertman"
|
27
|
+
browser.button(name: "sign_in").click
|
28
|
+
```
|
29
|
+
|
30
|
+
## Limitations
|
31
|
+
|
32
|
+
* This is a [quick] adaptation of [watir-rails](https://github.com/watir/watir-rails). All the heavy lifting was done by those folks.
|
33
|
+
|
34
|
+
|
35
|
+
## Contributors
|
36
|
+
|
37
|
+
* [Jarmo Pertman](https://github.com/jarmo)
|
38
|
+
* [Alex Rodionov](https://github.com/p0deje)
|
39
|
+
* [Marcelo Jacobus](https://github.com/mjacobus)
|
40
|
+
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
See [LICENSE](https://github.com/mjacobus/watir-hanami/blob/master/LICENSE).
|
data/Rakefile
ADDED
data/lib/watir/hanami.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "net/http"
|
3
|
+
require "rack"
|
4
|
+
require "watir"
|
5
|
+
|
6
|
+
require File.expand_path("hanami/browser.rb", File.dirname(__FILE__))
|
7
|
+
require File.expand_path("hanami/middleware.rb", File.dirname(__FILE__))
|
8
|
+
|
9
|
+
module Watir
|
10
|
+
class Hanami
|
11
|
+
class << self
|
12
|
+
private :new
|
13
|
+
attr_reader :port, :middleware
|
14
|
+
attr_writer :server
|
15
|
+
attr_writer :port
|
16
|
+
|
17
|
+
# Start the Hanami
|
18
|
+
# Will be called automatically by {Watir::Browser#initialize}.
|
19
|
+
#
|
20
|
+
# @param [Integer] port port for the Hanami
|
21
|
+
def boot(port: nil)
|
22
|
+
unless running?
|
23
|
+
@middleware = Middleware.new(app)
|
24
|
+
@port = port || find_available_port
|
25
|
+
|
26
|
+
@server_thread = Thread.new do
|
27
|
+
server.call @middleware, @port
|
28
|
+
end
|
29
|
+
|
30
|
+
Timeout.timeout(boot_timeout) { @server_thread.join(0.1) until running? }
|
31
|
+
end
|
32
|
+
rescue Timeout::Error
|
33
|
+
raise Timeout::Error, "Hanami Rack application timed out during boot"
|
34
|
+
end
|
35
|
+
|
36
|
+
# Host for Hanami app under test. Default is {.local_host}.
|
37
|
+
#
|
38
|
+
# @return [String] Host for Hanami app under test.
|
39
|
+
def host
|
40
|
+
@host || local_host
|
41
|
+
end
|
42
|
+
|
43
|
+
# Set host for Hanami app. Will be used by {Browser#goto} method.
|
44
|
+
#
|
45
|
+
# @param [String] host host to use when using {Browser#goto}.
|
46
|
+
def host=(host)
|
47
|
+
@host = host
|
48
|
+
end
|
49
|
+
|
50
|
+
# Local host for Hanami app under test.
|
51
|
+
#
|
52
|
+
# @return [String] Local host with the value of "127.0.0.1".
|
53
|
+
def local_host
|
54
|
+
"127.0.0.1"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Error rescued by the middleware.
|
58
|
+
#
|
59
|
+
# @return [Exception or NilClass]
|
60
|
+
def error
|
61
|
+
@middleware.error
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns true if there are pending requests to server.
|
65
|
+
#
|
66
|
+
# @return [Boolean]
|
67
|
+
def pending_requests?
|
68
|
+
@middleware.pending_requests?
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set error rescued by the middleware.
|
72
|
+
#
|
73
|
+
# @param value
|
74
|
+
def error=(value)
|
75
|
+
@middleware.error = value
|
76
|
+
end
|
77
|
+
|
78
|
+
# Check if Hanami app under test is running.
|
79
|
+
#
|
80
|
+
# @return [Boolean] true when Hanami app under test is running, false otherwise.
|
81
|
+
def running?
|
82
|
+
return false if @server_thread && @server_thread.join(0)
|
83
|
+
|
84
|
+
res = Net::HTTP.start(local_host, @port) { |http| http.get('/__identify__') }
|
85
|
+
|
86
|
+
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
|
87
|
+
return res.body == @app.object_id.to_s
|
88
|
+
end
|
89
|
+
rescue Errno::ECONNREFUSED, Errno::EBADF
|
90
|
+
return false
|
91
|
+
end
|
92
|
+
|
93
|
+
# Hanami app under test.
|
94
|
+
#
|
95
|
+
# @return [Object] Hanami Rack app.
|
96
|
+
def app
|
97
|
+
@app ||= Rack::Builder.new do
|
98
|
+
map "/" do
|
99
|
+
run ::Hanami.app
|
100
|
+
end
|
101
|
+
end.to_app
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def boot_timeout
|
107
|
+
60
|
108
|
+
end
|
109
|
+
|
110
|
+
def find_available_port
|
111
|
+
server = TCPServer.new(local_host, 0)
|
112
|
+
server.addr[1]
|
113
|
+
ensure
|
114
|
+
server.close if server
|
115
|
+
end
|
116
|
+
|
117
|
+
def server
|
118
|
+
@server ||= lambda do |app, port|
|
119
|
+
begin
|
120
|
+
require 'rack/handler/thin'
|
121
|
+
Thin::Logging.silent = true
|
122
|
+
return Rack::Handler::Thin.run(app, :Port => port)
|
123
|
+
rescue LoadError
|
124
|
+
end
|
125
|
+
|
126
|
+
begin
|
127
|
+
require 'rack/handler/puma'
|
128
|
+
return Rack::Handler::Puma.run(app, :Port => port, :Silent => true)
|
129
|
+
rescue LoadError
|
130
|
+
end
|
131
|
+
|
132
|
+
require 'rack/handler/webrick'
|
133
|
+
Rack::Handler::WEBrick.run(app, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Watir
|
2
|
+
# Reopened Watir::Browser class for working with Hanami
|
3
|
+
class Browser
|
4
|
+
# @private
|
5
|
+
alias_method :_original_initialize, :initialize
|
6
|
+
|
7
|
+
# Will start Hanami instance for Watir automatically and then invoke the
|
8
|
+
# original Watir::Browser#initialize method.
|
9
|
+
def initialize(*args)
|
10
|
+
Hanami.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 {Hanami.host} and {Hanami.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://#{Hanami.host}:#{Hanami.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 Hanami
|
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/hanami"
|
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::Hanami).to receive_messages(ignore_exceptions?: true) }
|
5
|
+
|
6
|
+
context "#initialize" do
|
7
|
+
it "starts Hanami before opening the browser" do
|
8
|
+
expect(Watir::Hanami).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::Hanami).to receive_messages(host: "foo.com", port: 42, boot: nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:browser) { Watir::Browser.new }
|
21
|
+
|
22
|
+
it "uses Hanami 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::Hanami::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::Hanami 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 Hanami 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
|
@@ -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 Hanami.}
|
8
|
+
gem.summary = %q{Use Watir (http://github.com/watir/watir) in Hanami.}
|
9
|
+
gem.homepage = "http://github.com/mjacobus/watir-hanami"
|
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-hanami"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.license = "MIT"
|
17
|
+
gem.version = Watir::Hanami::VERSION
|
18
|
+
|
19
|
+
gem.add_dependency "rack"
|
20
|
+
gem.add_dependency "hanami"
|
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
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watir-hanami
|
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: hanami
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: watir
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 6.0.0.beta4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 6.0.0.beta4
|
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 Hanami.
|
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/hanami.rb
|
113
|
+
- lib/watir/hanami/browser.rb
|
114
|
+
- lib/watir/hanami/middleware.rb
|
115
|
+
- lib/watir/version.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/support/watir.rb
|
118
|
+
- spec/watir/hanami/browser_spec.rb
|
119
|
+
- spec/watir/hanami/middleware_spec.rb
|
120
|
+
- spec/watir/hanami_spec.rb
|
121
|
+
- watir-hanami.gemspec
|
122
|
+
homepage: http://github.com/mjacobus/watir-hanami
|
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 Hanami.
|
146
|
+
test_files:
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
- spec/support/watir.rb
|
149
|
+
- spec/watir/hanami/browser_spec.rb
|
150
|
+
- spec/watir/hanami/middleware_spec.rb
|
151
|
+
- spec/watir/hanami_spec.rb
|