Exception: OutputAssay
- 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
Constant Summary
Constants inherited from Assertion
Constants included from Assay::Assertable
Class Method Summary collapse
-
.pass?(match, &block) ⇒ Boolean
Compare
match
against $stdout and $stderr via ‘#===` method.
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.
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 |