Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Use Net::IMAP::FakeServer::TestHelper #164

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading