summaryrefslogtreecommitdiff
path: root/test/test_helper.rb
blob: b4bbd9e911256cb5ffa0334c3e48ec19f994cf3f (plain)
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
require 'rack/test'
require 'stringio'
require 'test/unit'
require 'tmpdir'
require_relative '../lib/dashing'

ENV['RACK_ENV'] = 'test'
WORKING_DIRECTORY = Dir.pwd.freeze
ARGV.clear

def silent
  _stdout = $stdout
  $stdout = mock = StringIO.new
  begin
    yield
  ensure
    $stdout = _stdout
  end
end

def temp
  path = File.expand_path "#{Dir.tmpdir}/#{Time.now.to_i}#{rand(1000)}/"
  FileUtils.mkdir_p path
  Dir.chdir path
  yield path
ensure
  Dir.chdir WORKING_DIRECTORY
  FileUtils.rm_rf(path) if File.exists?(path)
end

module Dashing
  class Test < Test::Unit::TestCase
    include Rack::Test::Methods
  end
end