Sha256: 35296e79a3f887a4f26a8b42817536bb1629f81ffe97a62b199f49aa912ad93b

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

require 'rubygems'
require 'tempfile'
require 'minitest/autorun'
require 'mocha'
$:.unshift File.expand_path("../../lib")
require 'dante'

## Kernel Extensions
require 'stringio'

module Kernel
  # Redirect standard out, standard error and the buffered logger for sprinkle to StringIO
  # capture_stdout { any_commands; you_want } => "all output from the commands"
  def capture_stdout
    return yield if ENV['DEBUG'] # Skip if debug mode

    out = StringIO.new
    $stdout = out
    $stderr = out
    yield
    return out.string
  ensure
    $stdout = STDOUT
    $stderr = STDERR
  end
end

# Process fixture
class TestingProcess
  attr_reader :tmp_path

  def initialize(name)
    @tmp_path = "/tmp/dante-#{name}.log"
  end # initialize

  def run_a!(data=nil)
    @tmp = File.new(@tmp_path, 'w')
    @tmp.puts("Started")
    @tmp.puts "Data is: #{data}" if data
    @tmp.close
  end # run_a!

  def run_b!(port=9090)
    begin
      @tmp = File.new(@tmp_path, 'w')
      @tmp.print "Started on #{port}!!"
      sleep(100)
    rescue Interrupt
      @tmp.print "Interrupt!!"
      exit
    ensure
      @tmp.print "Closing!!"
      @tmp.close
    end
  end # run_b!

  # For logging test
  def run_c!(port=9091)
    puts "Started on #{port}!!"
    sleep(100)
  rescue Interrupt
    puts "Interrupt!!"
    exit
  ensure
    puts "Closing!!"
  end
end # TestingProcess

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dante-0.2.0 test/test_helper.rb
dante-0.1.5 test/test_helper.rb
dante-0.1.4 test/test_helper.rb
dante-0.1.3 test/test_helper.rb