私はこのようなgets.chomp使用して、簡単な機能があります。gets.chompで関数をテストするにはどうすればよいですか?
def welcome_user
puts "Welcome! What would you like to do?"
action = gets.chomp
end
を私はこのようなTestCase
スイートに建てruby
年代使用してそれをテストしたいと思います:
class ViewTest < Test::Unit::TestCase
def test_welcome
welcome_user
end
end
を問題があり、そのテストを実行すると、ユーザーが何かを入力する必要があるため、gets.chomp
がテストを停止します。 ruby
を使用してユーザー入力をシミュレートする方法はありますか?
def get_action
gets.chomp
end
def welcome_user
puts "Welcome to Jamaica and have a nice day!"
action = get_action
return "Required action was #{action}."
end
をそして、あなたは別に秒1をテスト:
Thnaksをその 'IO.pipe'のために、あなたはそこに私に何かを教えました。 –
ありがとうございました、アプローチが気に入りました! –