2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative 'helper'
|
2011-03-01 04:41:32 -05:00
|
|
|
require 'rubygems/user_interaction'
|
|
|
|
require 'timeout'
|
|
|
|
|
|
|
|
class TestGemSilentUI < Gem::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@sui = Gem::SilentUI.new
|
|
|
|
end
|
|
|
|
|
2014-07-25 02:53:31 -04:00
|
|
|
def teardown
|
|
|
|
@sui.close
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2011-03-01 04:41:32 -05:00
|
|
|
def test_ask
|
|
|
|
value = nil
|
2019-06-29 07:16:49 -04:00
|
|
|
out, err = capture_output do
|
2011-03-01 04:41:32 -05:00
|
|
|
use_ui @sui do
|
|
|
|
value = @sui.ask 'Problem?'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty out, 'No output'
|
|
|
|
assert_empty err, 'No output'
|
|
|
|
|
|
|
|
assert_nil value, 'No value'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_ask_for_password
|
|
|
|
value = nil
|
2019-06-29 07:16:49 -04:00
|
|
|
out, err = capture_output do
|
2011-03-01 04:41:32 -05:00
|
|
|
use_ui @sui do
|
|
|
|
value = @sui.ask_for_password 'Problem?'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty out, 'No output'
|
|
|
|
assert_empty err, 'No output'
|
|
|
|
|
|
|
|
assert_nil value, 'No value'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_ask_yes_no
|
|
|
|
value = nil
|
2019-06-29 07:16:49 -04:00
|
|
|
out, err = capture_output do
|
2011-03-01 04:41:32 -05:00
|
|
|
use_ui @sui do
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise(Gem::OperationNotSupportedError) do
|
2011-03-01 04:41:32 -05:00
|
|
|
@sui.ask_yes_no 'Problem?'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty out, 'No output'
|
|
|
|
assert_empty err, 'No output'
|
2012-08-21 00:50:18 -04:00
|
|
|
|
2019-06-29 07:16:49 -04:00
|
|
|
out, err = capture_output do
|
2011-03-01 04:41:32 -05:00
|
|
|
use_ui @sui do
|
|
|
|
value = @sui.ask_yes_no 'Problem?', true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty out, 'No output'
|
|
|
|
assert_empty err, 'No output'
|
|
|
|
|
|
|
|
assert value, 'Value is true'
|
2012-08-21 00:50:18 -04:00
|
|
|
|
2019-06-29 07:16:49 -04:00
|
|
|
out, err = capture_output do
|
2011-03-01 04:41:32 -05:00
|
|
|
use_ui @sui do
|
|
|
|
value = @sui.ask_yes_no 'Problem?', false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty out, 'No output'
|
|
|
|
assert_empty err, 'No output'
|
|
|
|
|
|
|
|
assert_equal value, false, 'Value is false'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_choose_from_list
|
|
|
|
value = nil
|
2019-06-29 07:16:49 -04:00
|
|
|
out, err = capture_output do
|
2011-03-01 04:41:32 -05:00
|
|
|
use_ui @sui do
|
|
|
|
value = @sui.choose_from_list 'Problem?', %w[yes no]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty out, 'No output'
|
|
|
|
assert_empty err, 'No output'
|
|
|
|
|
|
|
|
assert_equal [nil, nil], value, 'Value is nil!'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_progress_reporter
|
2019-06-29 07:16:49 -04:00
|
|
|
out, err = capture_output do
|
2011-03-01 04:41:32 -05:00
|
|
|
use_ui @sui do
|
|
|
|
@sui.progress_reporter 10, 'hi'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty out, 'No output'
|
|
|
|
assert_empty err, 'No output'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_download_reporter
|
2019-06-29 07:16:49 -04:00
|
|
|
out, err = capture_output do
|
2011-03-01 04:41:32 -05:00
|
|
|
use_ui @sui do
|
|
|
|
@sui.download_reporter.fetch 'a.gem', 1024
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty out, 'No output'
|
|
|
|
assert_empty err, 'No output'
|
|
|
|
end
|
|
|
|
end
|