0

This is my code:

# 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

I want to check if the message "Err, timeout, ouch" was printed here:

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'
Dennis
  • 2,866
  • 7
  • 32
  • 49

1 Answers1

1

You didn't show your execute_and_log method, but you could just use backticks:

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

For continuously capturing output of a command, there are multiple options. See Running a command from Ruby displaying and capturing the output

Community
  • 1
  • 1
max pleaner
  • 26,189
  • 9
  • 66
  • 118