Exception: SilentAssay

Inherits:
OutputAssay show all
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

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

.assert_messageObject



47
48
49
# File 'lib/assay/silent_assay.rb', line 47

def self.assert_message(*)
  "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_messageObject



54
55
56
# File 'lib/assay/silent_assay.rb', line 54

def self.refute_message(*)
  "expected output"
end