| | 37 | def match(command, expect, options={}) |
|---|
| | 38 | expect = Regexp.new(Regexp.escape(expect.to_s)) unless expect.is_a?(Regexp) |
|---|
| | 39 | |
|---|
| | 40 | output_per_server = {} |
|---|
| | 41 | try("#{command} ", options) do |ch, stream, out| |
|---|
| | 42 | output_per_server[ch[:server]] ||= '' |
|---|
| | 43 | output_per_server[ch[:server]] += out |
|---|
| | 44 | end |
|---|
| | 45 | |
|---|
| | 46 | # It is possible for some of these commands to return a status != 0 |
|---|
| | 47 | # (for example, rake --version exits with a 1). For this check we |
|---|
| | 48 | # just care if the output matches, so we reset the success flag. |
|---|
| | 49 | @success = true |
|---|
| | 50 | |
|---|
| | 51 | errored_hosts = [] |
|---|
| | 52 | output_per_server.each_pair do |server, output| |
|---|
| | 53 | next if output =~ expect |
|---|
| | 54 | errored_hosts << server |
|---|
| | 55 | end |
|---|
| | 56 | |
|---|
| | 57 | if errored_hosts.any? |
|---|
| | 58 | @hosts = errored_hosts.join(', ') |
|---|
| | 59 | output = output_per_server[errored_hosts.first] |
|---|
| | 60 | @message = "the output #{output.inspect} from #{command.inspect} did not match #{expect.inspect}" |
|---|
| | 61 | @success = false |
|---|
| | 62 | end |
|---|
| | 63 | |
|---|
| | 64 | self |
|---|
| | 65 | end |
|---|
| | 66 | |
|---|