require 'test/unit'
class Test_First < Test::Unit::TestCase
def test_gets
line = ""
while 1
line = gets
puts line
if line[/exit/]
puts line
break
end
end
assert_equal line,"exit"
end
end
gets输入的字符串带有回车符号,及"\n",所以要判读可以使用[/exit/]或者就用 line.strip 去掉后面的回车符号。