4
4
require "test/unit"
5
5
require "yaml"
6
6
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
+
7
17
module NetIMAPTestHelpers
8
18
module TestFixtureGenerators
9
19
@@ -30,7 +40,9 @@ def generate_tests_from(fixture_data: nil, fixture_file: nil)
30
40
case type
31
41
32
42
when :parser_assert_equal
33
- test => response :, expected :;
43
+ response = test . fetch ( :response )
44
+ expected = test . fetch ( :expected )
45
+
34
46
define_method name do
35
47
with_debug do
36
48
parser = Net ::IMAP ::ResponseParser . new
@@ -40,18 +52,21 @@ def generate_tests_from(fixture_data: nil, fixture_file: nil)
40
52
end
41
53
42
54
when :parser_pending
43
- test => response :;
55
+ response = test . fetch ( :response )
56
+
44
57
define_method name do
45
58
with_debug do
46
59
parser = Net ::IMAP ::ResponseParser . new
47
60
actual = parser . parse response
48
- puts YAML . dump name => { response :, expected : actual }
61
+ puts YAML . dump name => { response : response , expected : actual }
49
62
pend "update tests with expected data..."
50
63
end
51
64
end
52
65
53
66
when :assert_parse_failure
54
- test => response :, message :;
67
+ response = test . fetch ( :response )
68
+ message = test . fetch ( :message )
69
+
55
70
define_method name do
56
71
err = assert_raise ( Net ::IMAP ::ResponseParseError ) do
57
72
Net ::IMAP ::ResponseParser . new . parse response
0 commit comments