forked from ruby/net-imap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 Add Net::IMAP::FakeServer::TestHelper
This simplifies using Net::IMAP::FakeServer in multiple test suites.
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../fake_server" | ||
|
||
module Net::IMAP::FakeServer::TestHelper | ||
|
||
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 if @threads | ||
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 | ||
end | ||
yield server, client | ||
ensure | ||
client.logout rescue pp $! | ||
client.disconnect if !client.disconnected? | ||
end | ||
ensure | ||
server&.shutdown | ||
end | ||
end | ||
|
||
end |