Exception: OutputAssay

Inherits:
Assertion show all
Defined in:
lib/assay/output_assay.rb

Overview

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

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

Direct Known Subclasses

SilentAssay, StderrAssay, StdoutAssay

Constant Summary

Constants inherited from Assertion

Assertion::SIZE_LIMIT

Constants included from Assay::Assertable

Assay::Assertable::SIZE_LIMIT

Class Method Summary collapse

Methods inherited from Assertion

by_name, by_operator, inherited, register, subclasses

Methods included from Assay::Assertable

#[], #assert!, #assert_message, #assertive_name, #assertor, #fail?, #operator, #pass?, #refute!, #refute_message

Class Method Details

.pass?(match, &block) ⇒ Boolean

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.

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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