class SilentAssay

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

SilentAssay.pass?{ puts 'foo!' }  #=> false

Public Class Methods

assert_message(*) click to toggle source
# File lib/assay/silent_assay.rb, line 47
def self.assert_message(*)
  "unexpected output"
end
fail?(&block) click to toggle source

Opposite of ‘SilentAssay.pass?`.

# File lib/assay/silent_assay.rb, line 40
def self.fail?(&block)
  ! pass?(&block)
end
pass?() { || ... } 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/silent_assay.rb, line 17
def self.pass?(&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")

  newout.empty? && newerr.empty?
end
refute_message(*) click to toggle source
# File lib/assay/silent_assay.rb, line 54
def self.refute_message(*)
  "expected output"
end