Skip to content

Commit c16d33d

Browse files
authored
Properly restore Reline::IOGate in test teardown (#593)
* Properly restore Reline::IOGate in test teardown * GeneralIO.reset should reset class variable existence
1 parent 4d34e52 commit c16d33d

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

lib/reline/general_io.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
class Reline::GeneralIO
44
def self.reset(encoding: nil)
55
@@pasting = false
6-
@@encoding = encoding
6+
if encoding
7+
@@encoding = encoding
8+
elsif defined?(@@encoding)
9+
remove_class_variable(:@@encoding)
10+
end
711
end
812

913
def self.encoding

test/reline/helper.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@
2121
module Reline
2222
class <<self
2323
def test_mode(ansi: false)
24-
remove_const('IOGate') if const_defined?('IOGate')
25-
const_set('IOGate', ansi ? Reline::ANSI : Reline::GeneralIO)
26-
if ENV['RELINE_TEST_ENCODING']
27-
encoding = Encoding.find(ENV['RELINE_TEST_ENCODING'])
28-
else
29-
encoding = Encoding::UTF_8
30-
end
31-
Reline::GeneralIO.reset(encoding: encoding) unless ansi
32-
core.config.instance_variable_set(:@test_mode, true)
33-
core.config.reset
24+
@original_iogate = IOGate
25+
remove_const('IOGate')
26+
const_set('IOGate', ansi ? Reline::ANSI : Reline::GeneralIO)
27+
if ENV['RELINE_TEST_ENCODING']
28+
encoding = Encoding.find(ENV['RELINE_TEST_ENCODING'])
29+
else
30+
encoding = Encoding::UTF_8
31+
end
32+
Reline::GeneralIO.reset(encoding: encoding) unless ansi
33+
core.config.instance_variable_set(:@test_mode, true)
34+
core.config.reset
3435
end
3536

3637
def test_reset
37-
remove_const('IOGate') if const_defined?('IOGate')
38-
const_set('IOGate', Reline::GeneralIO)
38+
remove_const('IOGate')
39+
const_set('IOGate', @original_iogate)
40+
Reline::GeneralIO.reset
3941
Reline.instance_variable_set(:@core, nil)
4042
end
4143

test/reline/test_reline_key.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
class Reline::TestKey < Reline::TestCase
55
def setup
6+
Reline.test_mode
67
end
78

89
def teardown

0 commit comments

Comments
 (0)