如何让Gherkin检查是否打印了log.info消息?

时间:2016-04-19 14:14:10

标签: ruby gherkin

这是我的代码:

# Execute the constructed command, logging out each line
log.info "Executing '#{command.join(' ')}'"
begin
    timeout(config['deploy-timeout'].to_i) do
        execute_and_log command
    end
rescue Exception => e
    log.info 'Err, timeout, ouch'
    raise Timeout::Error
end

我想查看消息" Err,timeout,ouch"印在这里:

Scenario: Normal deploy that times out because it takes too long

Given the event handler is configured to handle events for '^bla$'
...
And the deploy script will take '10' seconds
...
And I expect 'DEPLOY' Serf event '1' to contain data 'status' is 'running'

1 个答案:

答案 0 :(得分:1)

您没有显示execute_and_log方法,但您可以使用反引号:

result = `#{cmd}`
result =~  "Err, timeout, ouch"

为了连续捕获命令的输出,有多个选项。 见Running a command from Ruby displaying and capturing the output