Skip to content

Commit

Permalink
♻️ Use Net::IMAP::FakeServer::TestHelper
Browse files Browse the repository at this point in the history
The module was originally extracted from this code, and this was
accidentally left behind when `Net::IMAP::FakeServer::TestHelper` was
originally committed.
  • Loading branch information
nevans committed Aug 28, 2023
1 parent c841cae commit fb9d9ee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
1 change: 1 addition & 0 deletions test/net/imap/fake_server/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def with_fake_server(select: nil, timeout: 5, **opts)
if select
client.select(select)
server.commands.pop
assert server.state.selected?
end
yield server, client
ensure
Expand Down
25 changes: 2 additions & 23 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class IMAPTest < Test::Unit::TestCase
SERVER_KEY = File.expand_path("../fixtures/server.key", __dir__)
SERVER_CERT = File.expand_path("../fixtures/server.crt", __dir__)

include Net::IMAP::FakeServer::TestHelper

def setup
@do_not_reverse_lookup = Socket.do_not_reverse_lookup
Socket.do_not_reverse_lookup = true
Expand Down Expand Up @@ -1031,29 +1033,6 @@ def test_unselect

private

def with_fake_server(select: nil, timeout: 5, **opts)
Timeout.timeout(timeout) do
server = Net::IMAP::FakeServer.new(timeout: timeout, **opts)
@threads << Thread.new do server.run end
tls = opts[:implicit_tls]
tls = {ca_file: server.config.tls[:ca_file]} if tls == true
client = Net::IMAP.new("localhost", port: server.port, ssl: tls)
begin
if select
client.select(select)
server.commands.pop
assert server.state.selected?
end
yield server, client
ensure
client.logout rescue pp $!
client.disconnect if !client.disconnected?
end
ensure
server&.shutdown
end
end

def imaps_test(timeout: 10)
Timeout.timeout(timeout) do
server = create_tcp_server
Expand Down

0 comments on commit fb9d9ee

Please sign in to comment.