我有一个要求用户输入的代码,如:“在哪里?foobar的”rspec的3错误时,系统会提示用户输入
class Foo
def prompt_for_foobar
puts "where is the foobar?"
gets.chomp
end
end
我想测试我的应用程序要求。我的测试将通过评论'gets.chomp'。但是这是必要的,而我尝试过的其他东西都给了我一个Errno :: ENOENT:错误。
it "should prompt user" do
console = Foo.new
request = "where is the foobar?"
expect { console.prompt_for_foobar }.to output(request).to_stdout
end
测试此方法的最佳方法是什么?
此概念的可能重复:http://stackoverflow.com/questions/16948645/how-do-i-test-a-function-with-gets-chomp-in-it – joelparkerhenderson 2014-12-13 01:11:43