-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest_config.rb
executable file
·107 lines (90 loc) · 2.98 KB
/
test_config.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative 'test_helper'
# Unit test the Config class
class TestConfig < MiniTest::Test
# Just copy and paste this in from the README
def readme_instructions(task)
# Name of quality task.
# Defaults to :quality.
task.quality_name = 'quality'
# Name of ratchet task.
# Defaults to :ratchet.
task.ratchet_name = 'ratchet'
#
# Set minimum values to ratchet to.
#
# Defaults to { bigfiles: 300 }
#
task.minimum_threshold = { rubocop: 300 }
# Array of strings describing tools to be skipped--e.g., ["cane"]
#
# Defaults to []
task.skip_tools = []
# Log command executation
#
# Defaults to false
task.verbose = false
# Relative path to output directory where *_high_water_mark
# files will be read/written
#
# Defaults to 'metrics'
task.output_dir = 'metrics'
# Pipe-separated regexp string describing what to look for in
# files as 'todo'-like 'punchlist' comments.
#
# Defaults to 'XXX|TODO|FIXME|OPTIMIZE|HACK|REVIEW|LATER|FIXIT'
task.punchlist_regexp = 'XXX|TODO|FIXME|OPTIMIZE|HACK|REVIEW|LATER|FIXIT'
# Exclude the specified list of files--defaults to ['db/schema.rb']
task.exclude_files = ['lib/whatever/imported_file.rb',
'lib/vendor/someone_else_fault.rb']
# Alternately, express it as a glob:
# Exclude the specified list of files
task.source_files_exclude_glob =
'{lib/whatever/imported_file.rb,lib/vendor/**/*.rb}'
#
# For configuration on classifying files as the correct language,
# see https://github.com/github/linguist
#
end
def test_quality_task_readme_instructions_still_work
config = get_test_object do |_task|
@mocks[:source_file_globber]
.expects(:exclude_files=)
.with(['lib/whatever/imported_file.rb',
'lib/vendor/someone_else_fault.rb'])
end
readme_instructions(config)
end
def test_all_output_files
config = get_test_object do
@mocks[:dir]
.expects(:glob)
.with('metrics/*_high_water_mark')
.returns(['metrics/a_high_water_mark'])
end
assert_equal(['metrics/a_high_water_mark'], config.all_output_files)
end
def test_source_files_exclude_glob_from_array
config = get_test_object do
@mocks[:source_file_globber]
.expects(:exclude_files=)
.with(%w[a b c])
@mocks[:source_file_globber]
.expects(:exclude_files)
.returns(%w[a b c])
end
config.exclude_files = %w[a b c]
assert_equal('{a,b,c}', config.source_files_exclude_glob)
end
def test_source_files_exclude_glob_from_glob
config = get_test_object
config.source_files_exclude_glob = '{d,e,f}'
assert_equal('{d,e,f}', config.source_files_exclude_glob)
end
def get_test_object(&twiddle_mocks)
@mocks = get_initializer_mocks(Quality::Config)
yield @mocks unless twiddle_mocks.nil?
Quality::Config.new(**@mocks)
end
end