test/unit/helper.rb in thinreports-0.7.6 vs test/unit/helper.rb in thinreports-0.7.7
- old
+ new
@@ -1,36 +1,54 @@
# coding: utf-8
require 'rubygems'
require 'minitest/spec'
require 'minitest/unit'
-require 'turn'
+require 'turn/autorun'
require 'flexmock'
-require 'simplecov'
-SimpleCov.start do
- add_filter 'test/'
- add_group 'Core', 'lib/thinreports/core'
- add_group 'Generator', 'lib/thinreports/generator'
- add_group 'Layout', 'lib/thinreports/layout'
- add_group 'Report', 'lib/thinreports/report'
+if ENV['COVERAGE']
+ require 'simplecov'
+ SimpleCov.start do
+ add_filter 'test/'
+ add_group 'Core', 'lib/thinreports/core'
+ add_group 'Generator', 'lib/thinreports/generator'
+ add_group 'Layout', 'lib/thinreports/layout'
+ add_group 'Report', 'lib/thinreports/report'
+ end
end
-Turn.config.format = :progress
-
# Load ThinReports.
require 'thinreports'
# Load misc.
+require 'fileutils'
require 'digest/sha1'
# Run the test.
MiniTest::Unit.autorun
module ThinReports::TestHelpers
include FlexMock::TestCase
-
+
+ ROOT_DIR = File.expand_path(File.dirname(__FILE__))
+ TEMP_DIR = ROOT_DIR + '/tmp'
+
+ def self.included(klass)
+ klass.class_eval do
+ alias_method :_teardown, :teardown
+ def teardown
+ _teardown
+ clear_outputs
+ end
+ end
+ end
+
+ def clear_outputs
+ FileUtils.rm Dir.glob(TEMP_DIR + '/*')
+ end
+
def clean_whitespaces(str)
str.gsub(/^\s*|\n\s*/, '')
end
def skip_if_ruby19
@@ -59,7 +77,11 @@
ThinReports::Layout::Format.build(data_file(file))
end
def data_file(filename)
File.join(File.dirname(__FILE__), 'data', filename)
+ end
+
+ def temp_file(extname = 'pdf')
+ File.join(TEMP_DIR, (('a'..'z').to_a + (0..9).to_a).shuffle[0, 8].join + ".#{extname}")
end
end