-
Notifications
You must be signed in to change notification settings - Fork 48
/
test_helper.rb
59 lines (44 loc) · 1.1 KB
/
test_helper.rb
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# coding: utf-8
require 'minitest/autorun'
require 'minitest/spec'
require 'minitest/unit'
require 'flexmock/test_unit'
require 'fileutils'
require 'digest/sha1'
require 'pathname'
require 'thinreports'
module ThinReports::TestHelper
include FlexMock::TestCase
ROOT = Pathname.new(File.expand_path('..', __FILE__))
def teardown
super
clear_output
end
def create_basic_report(file, &block)
report = ThinReports::Report.new layout: data_file(file)
block.call(report) if block_given?
report
end
def create_basic_layout(file)
ThinReports::Layout.new(data_file(file))
end
def create_basic_layout_format(file)
ThinReports::Layout::Format.build(data_file(file))
end
def clear_output
FileUtils.rm Dir.glob(temp_path.join('*'))
end
def clean_whitespaces(s)
s.gsub(/^\s*|\n\s*/, '')
end
def data_file(filename)
ROOT.join('data', filename).to_s
end
def temp_file(extname = 'pdf')
filename = (('a'..'z').to_a + (0..9).to_a).shuffle[0, 8].join + ".#{extname}"
temp_path.join(filename).to_s
end
def temp_path
ROOT.join('tmp')
end
end