Skip to content

Commit 1c721a7

Browse files
Set minimum tty versions, removed open3, refactored tests
1 parent cc0283b commit 1c721a7

File tree

8 files changed

+48
-39
lines changed

8 files changed

+48
-39
lines changed

Gemfile.lock

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
PATH
22
remote: .
33
specs:
4-
ruby-nginx (1.0.0.pre.beta)
4+
ruby-nginx (1.0.0.pre.beta.1)
55
erb
6-
open3
76
thor
8-
tty-command
9-
tty-prompt
7+
tty-command (~> 0.10, >= 0.10.1)
8+
tty-prompt (~> 0.23, >= 0.23.1)
109

1110
GEM
1211
remote: https://rubygems.org/
@@ -16,11 +15,10 @@ GEM
1615
diff-lcs (1.5.1)
1716
erb (4.0.4)
1817
cgi (>= 0.3.3)
19-
json (2.9.1)
18+
json (2.10.1)
2019
language_server-protocol (3.17.0.4)
2120
lint_roller (1.1.0)
2221
nio4r (2.7.4)
23-
open3 (0.2.1)
2422
parallel (1.26.3)
2523
parser (3.3.7.1)
2624
ast (~> 2.4.1)

lib/ruby/nginx/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module Ruby
44
module Nginx
5-
VERSION = "1.0.0-beta"
5+
VERSION = "1.0.0-beta.1"
66

77
Version = Gem::Version
88
end

ruby-nginx.gemspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ Gem::Specification.new do |spec|
2626
spec.require_paths = ["lib"]
2727

2828
spec.add_dependency "erb"
29-
spec.add_dependency "open3"
3029
spec.add_dependency "thor"
31-
spec.add_dependency "tty-command"
32-
spec.add_dependency "tty-prompt"
30+
spec.add_dependency "tty-command", "~> 0.10", ">= 0.10.1"
31+
spec.add_dependency "tty-prompt", "~> 0.23", ">= 0.23.1"
3332

3433
# For more information and examples about making a new gem, checkout our
3534
# guide at: https://bundler.io/guides/creating_gem.html

spec/ruby/nginx_add_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require "puma"
34
require "puma/configuration"
45

56
RSpec.describe Ruby::Nginx do
@@ -14,21 +15,21 @@
1415
end
1516

1617
it "adds the hosts mapping" do
17-
RetryExpectation.new(limit: 30, delay: 1).attempt do
18+
retry_expectation(limit: 30, delay: 1) do
1819
hosts = File.read("/etc/hosts")
1920
expect(hosts).to include("example.test")
2021
end
2122
end
2223

2324
it "creates the NGINX configuration" do
24-
RetryExpectation.new(limit: 30, delay: 1).attempt do
25+
retry_expectation(limit: 30, delay: 1) do
2526
path = File.expand_path("~/.ruby-nginx/servers/ruby_nginx_example_test.conf")
2627
expect(File.exist?(path)).to be_truthy
2728
end
2829
end
2930

3031
it "creates the SSL certificate" do
31-
RetryExpectation.new(limit: 30, delay: 1).attempt do
32+
retry_expectation(limit: 30, delay: 1) do
3233
path = File.expand_path("~/.ruby-nginx/certs/_example.test.pem")
3334
expect(File.exist?(path)).to be_truthy
3435

@@ -38,7 +39,7 @@
3839
end
3940

4041
it "creates the log files" do
41-
RetryExpectation.new(limit: 30, delay: 1).attempt do
42+
retry_expectation(limit: 30, delay: 1) do
4243
path = File.expand_path("~/.ruby-nginx/logs/example.test.access.log")
4344
expect(File.exist?(path)).to be_truthy
4445

@@ -48,7 +49,7 @@
4849
end
4950

5051
it "successfully builds up a NGINX site" do
51-
RetryExpectation.new(limit: 30, delay: 1).attempt do
52+
retry_expectation(limit: 30, delay: 1) do
5253
html = `curl -s http://example.test`
5354
expect(html).to include("Hello, from Ruby NGINX!")
5455

spec/ruby/nginx_remove_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
end
77

88
it "removes the hosts mapping" do
9-
RetryExpectation.new(limit: 30, delay: 1).attempt do
9+
retry_expectation(limit: 30, delay: 1) do
1010
hosts = File.read("/etc/hosts")
1111
expect(hosts).not_to include("example.test")
1212
end
1313
end
1414

1515
it "deletes the NGINX configuration" do
16-
RetryExpectation.new(limit: 30, delay: 1).attempt do
16+
retry_expectation(limit: 30, delay: 1) do
1717
path = File.expand_path("~/.ruby-nginx/servers/ruby_nginx_example_test.conf")
1818
expect(File.exist?(path)).to be_falsey
1919
end
2020
end
2121

2222
it "successfully tears down a NGINX site" do
23-
RetryExpectation.new(limit: 30, delay: 1).attempt do
23+
retry_expectation(limit: 30, delay: 1) do
2424
html = `curl -s http://example.test`
2525
expect(html).to eq("")
2626

spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# frozen_string_literal: true
22

3+
ENV["SKIP_PROMPT"] = "true"
4+
35
require "ruby/nginx"
46

57
Dir[File.expand_path("support/**/*.rb", __dir__)].each { |file| require file }
68

79
RSpec.configure do |config|
10+
config.include(RetryHelpers)
11+
812
# Enable flags like --only-failures and --next-failure
913
config.example_status_persistence_file_path = ".rspec_status"
1014

spec/support/dummy_server.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
require "puma"
2-
require "puma/cli"
31
require "singleton"
42

5-
ENV["SKIP_PROMPT"] = "true"
6-
DUMMY_PATH = File.expand_path("../dummy", __dir__)
7-
83
class DummyServer
94
include Singleton
105

116
def initialize
127
@semaphore = Mutex.new
13-
@server = nil
8+
@pid = nil
149
end
1510

1611
def start
1712
@semaphore.synchronize do
18-
@server = Thread.new do # standard:disable Style/GlobalVars
19-
Puma::CLI.new(["-s", "--dir=#{DUMMY_PATH}"]).run
13+
@pid = Process.fork do
14+
require "puma"
15+
require "puma/cli"
16+
17+
dummy_path = File.expand_path("../dummy", __dir__)
18+
19+
Puma::CLI.new(["-s", "--dir=#{dummy_path}"]).run
2020
end
2121
end
2222
end
2323

2424
def stop
2525
@semaphore.synchronize do
26-
@server.exit if @server.alive?
26+
Process.kill(:TERM, @pid)
27+
Process.wait
2728
end
2829
end
2930
end

spec/support/retry_expectation.rb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
class RetryExpectation
2-
def initialize(limit:, delay:)
3-
@limit = limit
4-
@delay = delay
5-
@count = 0
1+
module RetryHelpers
2+
class RetryExpectation
3+
def initialize(limit:, delay:)
4+
@limit = limit
5+
@delay = delay
6+
@count = 0
7+
end
8+
9+
def attempt
10+
yield
11+
rescue RSpec::Expectations::ExpectationNotMetError
12+
raise if @count >= @limit
13+
sleep(@delay) if @delay
14+
@count += 1
15+
retry
16+
end
617
end
718

8-
def attempt
9-
yield
10-
rescue RSpec::Expectations::ExpectationNotMetError
11-
raise if @count >= @limit
12-
sleep(@delay) if @delay
13-
@count += 1
14-
retry
19+
def retry_expectation(limit: 3, delay: 0.1, &block)
20+
RetryExpectation.new(limit: limit, delay: delay).attempt(&block)
1521
end
1622
end

0 commit comments

Comments
 (0)