Exception: SilentAssay
- Inherits:
-
OutputAssay
- Object
- Exception
- Assertion
- OutputAssay
- SilentAssay
- Defined in:
- lib/assay/silent_assay.rb
Overview
Assert that there is no output, either from stdout or stderr.
SilentAssay.pass?{ puts 'foo!' } #=> false
Constant Summary
Constants inherited from Assertion
Constants included from Assay::Assertable
Class Method Summary collapse
- .assert_message ⇒ Object
-
.fail?(&block) ⇒ Boolean
Opposite of ‘SilentAssay.pass?`.
-
.pass?(&block) ⇒ Boolean
Compare
match
against $stdout and $stderr via ‘#===` method. - .refute_message ⇒ Object
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
.assert_message ⇒ Object
47 48 49 |
# File 'lib/assay/silent_assay.rb', line 47 def self.(*) "unexpected output" end |
.fail?(&block) ⇒ Boolean
Opposite of ‘SilentAssay.pass?`.
40 41 42 |
# File 'lib/assay/silent_assay.rb', line 40 def self.fail?(&block) ! pass?(&block) end |
.pass?(&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/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 ⇒ Object
54 55 56 |
# File 'lib/assay/silent_assay.rb', line 54 def self.(*) "expected output" end |