下面的場景幾乎總結我的問題:測試與黃瓜/阿魯巴/時空特警一個命令行應用程序:如何注入上下文
Scenario: problems with subprocesses
Given the date is 01/01/2012 10:31
When I run `ruby -e "puts Time.now"`
Then the output should contain "10:31"
它歸結爲When I run ruby -e "puts Time.now"
啓動一個子進程,從而使所有的我的Timecop.freeze
存根無效,因爲它們只在主流程上工作。我需要以某種方式將當前上下文「注入」到正在運行的命令中,但我似乎無法想出任何東西。我在這裏嘗試不可能的事情嗎?
步驟:
require 'timecop'
Given /^the date is (\d+)\/(\d+)\/(\d+) (\d+):(\d+)$/ do |month, day, year, hour, minute|
Timecop.freeze(Time.local(year.to_i, month.to_i, day.to_i, hour.to_i , minute.to_i, 0))
end