Skip to content

Commit 8d5f2ad

Browse files
committed
💚 Fix backwards incompatibility issues
Modern pattern matching syntax, implicit hash values, and YAML.unsafe_load_file.
1 parent 03fecc4 commit 8d5f2ad

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

test/net/imap/net_imap_test_helpers.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
require "test/unit"
55
require "yaml"
66

7+
# Compatibility with older versions, e.g. the version comes with ruby 2.7
8+
module YAMLPolyfill
9+
unless YAML.respond_to? :unsafe_load_file
10+
refine YAML.singleton_class do
11+
def unsafe_load_file(...) load_file(...) end
12+
end
13+
end
14+
end
15+
using YAMLPolyfill
16+
717
module NetIMAPTestHelpers
818
module TestFixtureGenerators
919

@@ -30,7 +40,9 @@ def generate_tests_from(fixture_data: nil, fixture_file: nil)
3040
case type
3141

3242
when :parser_assert_equal
33-
test => response:, expected:;
43+
response = test.fetch(:response)
44+
expected = test.fetch(:expected)
45+
3446
define_method name do
3547
with_debug do
3648
parser = Net::IMAP::ResponseParser.new
@@ -40,18 +52,21 @@ def generate_tests_from(fixture_data: nil, fixture_file: nil)
4052
end
4153

4254
when :parser_pending
43-
test => response:;
55+
response = test.fetch(:response)
56+
4457
define_method name do
4558
with_debug do
4659
parser = Net::IMAP::ResponseParser.new
4760
actual = parser.parse response
48-
puts YAML.dump name => {response:, expected: actual}
61+
puts YAML.dump name => {response: response, expected: actual}
4962
pend "update tests with expected data..."
5063
end
5164
end
5265

5366
when :assert_parse_failure
54-
test => response:, message:;
67+
response = test.fetch(:response)
68+
message = test.fetch(:message)
69+
5570
define_method name do
5671
err = assert_raise(Net::IMAP::ResponseParseError) do
5772
Net::IMAP::ResponseParser.new.parse response

0 commit comments

Comments
 (0)