-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathirb_test.rb
More file actions
111 lines (96 loc) · 2.88 KB
/
irb_test.rb
File metadata and controls
111 lines (96 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# frozen_string_literal: true
require_relative '../support/console_test_case'
module DEBUGGER__
class IrbTest < ConsoleTestCase
def setup
@original_pager = ENV["PAGER"]
@original_home = ENV["HOME"]
@original_xdg_config_home = ENV["XDG_CONFIG_HOME"]
@original_irbrc = ENV["IRBRC"]
ENV["PAGER"] = "cat"
ENV["HOME"] = ENV["XDG_CONFIG_HOME"] = Dir.mktmpdir
ENV["IRBRC"] = nil
end
def teardown
ENV["PAGER"] = @original_pager
ENV["HOME"] = @original_home
ENV["XDG_CONFIG_HOME"] = @original_xdg_config_home
ENV["IRBRC"] = @original_irbrc
end
def program
<<~RUBY
1| a = 1
2| b = 2
RUBY
end
def test_irb_command_is_disabled_in_remote_mode
debug_code(program, remote: :remote_only) do
type 'irb'
assert_line_text 'IRB is not supported on the remote console.'
type 'q!'
end
debug_code(program, remote: :remote_only) do
type 'config set irb_console true'
assert_line_text 'IRB is not supported on the remote console.'
type 'q!'
end
end
def test_irb_command_switches_console_to_irb
debug_code(program, remote: false) do
type 'irb'
type '123'
assert_raw_line_text 'irb:rdbg(main):002> 123'
type 'irb_info'
assert_line_text('IRB version:')
type 'next'
type 'info'
assert_line_text([/a = 1/, /b = nil/])
# disable irb console
type 'config set irb_console false'
type '456'
assert_raw_line_text '(rdbg) 456'
type 'q!'
end
end
def test_irb_console_config_activates_irb
ENV["RUBY_DEBUG_IRB_CONSOLE"] = "true"
debug_code(program, remote: false) do
type '123'
assert_raw_line_text 'irb:rdbg(main):002> 123'
type 'irb_info'
assert_line_text('IRB version:')
type 'next'
type 'info'
assert_line_text([/a = 1/, /b = nil/])
# disable irb console
type 'config set irb_console false'
type '456'
assert_raw_line_text '(rdbg) 456'
type 'q!'
end
ensure
ENV["RUBY_DEBUG_IRB_CONSOLE"] = nil
end
def test_irb_console_evaluated_result_is_set_as_underscore_local
debug_code(program, remote: false) do
type 'irb'
type "_"
assert_line_text(/nil/)
type "3 * 3"
assert_raw_line_text 'irb:rdbg(main):003> 3 * 3'
type "foo = _"
type "9 == foo"
assert_line_text(/true/)
type "c"
end
end
private
# assert_line_text ignores the prompt line, so we can't use it to assert the prompt transition
# assert_raw_line_text is a workaround for that
def assert_raw_line_text(expectation)
@scenario.push(Proc.new do |test_info|
assert_include(test_info.last_backlog.join, expectation)
end)
end
end
end