From cb6c27799cef254c47b5cf688cc9f169d89b1623 Mon Sep 17 00:00:00 2001 From: nick evans Date: Wed, 8 May 2024 14:57:27 -0400 Subject: [PATCH] Add core assertions for `assert_warn` --- Gemfile | 1 + test/net/smtp/test_smtp.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Gemfile b/Gemfile index 3dc2883..730174f 100644 --- a/Gemfile +++ b/Gemfile @@ -6,4 +6,5 @@ group :development do gem "bundler" gem "rake" gem "test-unit" + gem "test-unit-ruby-core", git: "https://github.com/ruby/test-unit-ruby-core" end diff --git a/test/net/smtp/test_smtp.rb b/test/net/smtp/test_smtp.rb index b394cb8..87119be 100644 --- a/test/net/smtp/test_smtp.rb +++ b/test/net/smtp/test_smtp.rb @@ -2,6 +2,9 @@ require 'net/smtp' require 'test/unit' +require "core_assertions" + +Test::Unit::TestCase.include Test::Unit::CoreAssertions module Net class TestSMTP < Test::Unit::TestCase @@ -628,6 +631,19 @@ def test_quit! smtp.quit! end + def test_quit_and_warn + server = FakeServer.start + def server.quit + @sock.puts "400 BUSY\r\n" + end + smtp = Net::SMTP.start 'localhost', server.port + assert_warn(/SMTPServerBusy during .*#quit!/i) do + smtp.quit!(exception: :warn) + end + assert_equal "QUIT\r\n", server.commands.last + refute smtp.started? + end + def test_quit_and_reraise server = FakeServer.start def server.quit