File: abstract_unit.rb

package info (click to toggle)
ruby-mkrf 0.2.3+dfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,752 kB
  • ctags: 4,291
  • sloc: ansic: 12,494; ruby: 6,984; sh: 790; yacc: 374; makefile: 57; cpp: 10
file content (45 lines) | stat: -rw-r--r-- 963 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#$:.unshift(File.dirname(__FILE__) + '/../lib')

require 'test/unit'
#require File.dirname(__FILE__) + '/../lib/mkrf'
require 'mkrf'

$debug = false

class Test::Unit::TestCase
  def silence_command_line
    yield and return if $debug
    silence_stream(STDERR) do
      silence_stream(STDOUT) do
        yield
      end
    end
  end
  
  # silence_stream taken from Rails ActiveSupport reporting.rb
  
  # Silences any stream for the duration of the block.
  #
  #   silence_stream(STDOUT) do
  #     puts 'This will never be seen'
  #   end
  #
  #   puts 'But this will'
  def silence_stream(stream)
    old_stream = stream.dup
    stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
    stream.sync = true
    yield
  ensure
    stream.reopen(old_stream)
  end
  
  protected
  
  def assert_creates_file(file)
    assert !File.exist?(file), "#{file} already exists!"
    yield
    assert File.exist?(file), "#{file} wasn't created!"
  end
  
end