以下场景几乎概括了我的问题:Scenario:problemswithsubprocessesGiventhedateis01/01/201210:31WhenIrun`ruby-e"putsTime.now"`Thentheoutputshouldcontain"10:31"它归结为当我运行ruby-e"putsTime.now"时启动一个子进程,从而使我所有的Timecop.freezestub无效,因为他们只在主要过程中工作。我需要以某种方式将当前上下文“注入(inject)”到运行的命令中,但我似乎无法想出任何东西。我在这里尝试不可能的事情吗?步骤:require'time
我在Rails3.0应用程序中指定一个范围,如下所示:classDrawingList=?',Date.today,Date.today)end在我的规范中,我想做的是:beforedo@list=DrawingList.create#thingsthatincludebeginandenddatesendit"doesn'tfindanactivedrawingiftheyareoutofrange"dopending"reallyneedtofigureouthowtoworktimecopinthepresenceofscopes"Timecop.travel(2.days)pu
为了在单元测试中测试时间敏感的方法,设置Time.now的最佳方法是什么? 最佳答案 我真的很喜欢Timecop图书馆。您可以以block形式进行时间扭曲(就像时间扭曲一样):Timecop.travel(6.days.ago)do@model=TimeSensitiveMode.newendassert@model.times_up!(是的,您可以嵌套block形式的时间旅行。)您还可以进行声明式时间旅行:classMyTest我有一些cucumberTimecop的助手here.他们让你做这样的事情:Givenitiscurre