Sha256: 29e01b2bff341899e22f1a39e933dedc26cc31e3c5241e331ede48804ac676f2

Contents?: true

Size: 501 Bytes

Versions: 2

Compression:

Stored size: 501 Bytes

Contents

require_relative 'output_assay'

# Assert that there is output, either from stdout or stderr.
#
#   StdoutAssay.pass?(/foo/){ puts 'foo!' }  #=> true
#
class StdoutAssay < OutputAssay

  register :output

  #
  # Check assertion via `#===` method.
  #
  def self.pass?(match, &block)
    require 'stringio'

    begin
      stdout  = $stdout
      newout  = StringIO.new
      $stdout = newout
      yield
    ensure
      $stdout = stdout
    end

    match === newout.string.chomp("\n")
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
assay-0.4.1 lib/assay/stdout_assay.rb
assay-0.4.0 lib/assay/stdout_assay.rb