class OutputAssay

Assert that there is output, either from stdout or stderr.

OutputAssay.pass?(/foo/){ puts 'foo!' }  #=> true

Public Class Methods

pass?(match) { || ... } click to toggle source

Compare match against $stdout and $stderr via ‘#===` method.

Note that $stdout and $stderr are temporarily reouted to StringIO objects and the results have any trailing newline chomped off.

# File lib/assay/output_assay.rb, line 17
def self.pass?(match, &block)
  require 'stringio'

  begin
    stdout, stderr = $stdout, $stderr
    newout, newerr = StringIO.new, StringIO.new
    $stdout, $stderr = newout, newerr
    yield  
  ensure
    $stdout, $stderr = stdout, stderr
  end

  newout, newerr = newout.string.chomp("\n"), newerr.string.chomp("\n")

  match === newout || match === newerr
end