summaryrefslogtreecommitdiff
path: root/test/test_helper.rb
blob: 9c51b878fd25848ef714d133210f7b33dc2e0a18 (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
36
37
38
39
40
require 'rack/test'
require 'stringio'
require 'tmpdir'

require 'minitest/autorun'
require 'minitest/pride'

require_relative '../lib/dashing'

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

def load_quietly(file)
  Minitest::Test.new(nil).capture_io do
    load file
  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 < Minitest::Test
    include Rack::Test::Methods

    alias_method :silent, :capture_io

    def teardown
      FileUtils.rm_f('history.yml')
    end
  end
end