Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpep committed Sep 19, 2023
1 parent 63af66a commit bc157f9
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions spec/support/mock_server.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
require "net/http"
require "socket"

module Helpers
module MockServer
def mock_server
def mock_server(host, *args)
raise Net::OpenTimeout if host =~ /timeout/

client_socket, server_socket = Socket.pair(:UNIX, :STREAM, 0)

allow(client_socket).to receive(:setsockopt)
Expand Down Expand Up @@ -30,20 +33,11 @@ def mock_server
end


puts "!!! Net::HTTP::VERSION: #{Net::HTTP::VERSION}"

RSpec.configure do |config|
config.include Helpers::MockServer

config.before do
allow(Socket).to receive(:tcp) do |host, *args|
raise Net::OpenTimeout if host =~ /timeout/

mock_server
end

# allow(TCPSocket).to receive(:open).and_wrap_original do |original_method, *args|
# client_socket
# end
allow(Socket).to receive(:tcp, &method(:mock_server))
allow(TCPSocket).to receive(:open, &method(:mock_server))
end
end

0 comments on commit bc157f9

Please sign in to comment.