Skip to content

Commit

Permalink
fix: Use Rackup::Server when rack version is >= 3.0 (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
josegomezr authored Aug 23, 2024
1 parent a14367e commit d6602f1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/teaspoon/rackup_server_shim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'rack'
require 'rackup'

module Teaspoon
if Gem::Version.new(Rack.release) > '3.0'
RackupServerShim = ::Rackup::Server
else
RackupServerShim = ::Rack::Server
end
end
3 changes: 2 additions & 1 deletion lib/teaspoon/server.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "socket"
require "timeout"
require "webrick"
require_relative "rackup_server_shim"

module Teaspoon
class Server
Expand All @@ -16,7 +17,7 @@ def start

thread = Thread.new do
disable_logging
server = Rack::Server.new(rack_options)
server = RackupServerShim.new(rack_options)
server.start
end
wait_until_started(thread)
Expand Down
6 changes: 3 additions & 3 deletions spec/teaspoon/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end

it "starts a rack server" do
expect(Rack::Server).to receive(:new).and_return(server)
expect(Teaspoon::RackupServerShim).to receive(:new).and_return(server)
expect(server).to receive(:start)

subject.start
Expand All @@ -41,7 +41,7 @@
)
end

it "creates a Rack::Server with the correct setting" do
it "creates a Teaspoon::RackupServerShim with the correct setting" do
expected_opts = {
app: Rails.application,
Host: subject.host,
Expand All @@ -52,7 +52,7 @@
server: Teaspoon.configuration.server,
Silent: true,
}
expect(Rack::Server).to receive(:new).with(expected_opts).and_return(server)
expect(Teaspoon::RackupServerShim).to receive(:new).with(expected_opts).and_return(server)

subject.start
@block.call
Expand Down
1 change: 1 addition & 0 deletions teaspoon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |s|

s.required_ruby_version = ">= 2.7"
s.add_runtime_dependency "railties", ">= 5.0"
s.add_runtime_dependency "rackup", ">= 2.1"
s.add_development_dependency "simplecov", "< 0.18"
if RUBY_VERSION > "3"
s.add_development_dependency "webrick"
Expand Down

0 comments on commit d6602f1

Please sign in to comment.