Class: ResizeTerminalTest
- Defined in:
- lib/resize_terminal.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #teardown ⇒ Object
- #test_resize_terminal_invalid_response ⇒ Object
- #test_resize_terminal_no_response ⇒ Object
- #test_resize_terminal_non_interactive ⇒ Object
- #test_resize_terminal_successful ⇒ Object
- #test_resize_terminal_timeout ⇒ Object
Instance Method Details
#setup ⇒ Object
96 97 98 99 100 101 |
# File 'lib/resize_terminal.rb', line 96 def setup # Backup original ARGV and environment variables @original_argv = ARGV.dup @original_columns = ENV.fetch('COLUMNS', nil) @original_lines = ENV.fetch('LINES', nil) end |
#teardown ⇒ Object
103 104 105 106 107 108 |
# File 'lib/resize_terminal.rb', line 103 def teardown # Restore original ARGV and environment variables ARGV.replace(@original_argv) EnvInterface.set('COLUMNS', @original_columns) EnvInterface.set('LINES', @original_lines) end |
#test_resize_terminal_invalid_response ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/resize_terminal.rb', line 139 def test_resize_terminal_invalid_response # Simulate interactive terminal with invalid response $stdin.stub(:tty?, true) do ARGV.replace([]) response = "\e[999;999H\e[6n\e[InvalidResponse".dup $stdin.stub(:getch, -> { response.slice!(0) || '' }) do error = assert_raises(StandardError) do resize_terminal(require_stdout: false, debug: true) end assert_match /Error: Failed to match terminal response pattern/, error. end end end |
#test_resize_terminal_no_response ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/resize_terminal.rb', line 126 def test_resize_terminal_no_response # Simulate interactive terminal with no response $stdin.stub(:tty?, true) do ARGV.replace([]) $stdin.stub(:getch, -> { '' }) do error = assert_raises(StandardError) do resize_terminal(require_stdout: false, debug: true) end assert_equal 'Error: Timeout while reading terminal response. Unsupported terminal emulator.', error. end end end |
#test_resize_terminal_non_interactive ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/resize_terminal.rb', line 168 def test_resize_terminal_non_interactive # Simulate non-interactive terminal $stdin.stub(:tty?, false) do assert_output(nil, /Usage: resize_terminal/) do resize_terminal end end end |
#test_resize_terminal_successful ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/resize_terminal.rb', line 110 def test_resize_terminal_successful # Simulate interactive terminal $stdin.stub(:tty?, true) do ARGV.replace([]) columns = 40 + (2 * rand(10)) EnvInterface.set('COLUMNS', columns.to_s) EnvInterface.set('LINES', '24') response = "\e[999;999H\e[6n\e[24;#{columns}R".dup $stdin.stub(:getch, -> { response.slice!(0) || '' }) do assert_output(/xterm(-256color)? #{columns}x24$/) do resize_terminal(require_stdout: false) end end end end |
#test_resize_terminal_timeout ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/resize_terminal.rb', line 154 def test_resize_terminal_timeout # Simulate interactive terminal with timeout $stdin.stub(:tty?, true) do ARGV.replace([]) Timeout.stub(:timeout, ->(_) { raise Timeout::Error }) do error = assert_raises(StandardError) do resize_terminal(require_stdout: false, debug: true) end assert_match /Error: Timeout while reading terminal response/, error. end end end |