以下场景几乎总结了我的问题:
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