Class: Overcommit::GitHook::TestHistory
Constant Summary
collapse
- TEST_RESULTS_FILE =
'.spec-results'
Instance Method Summary
collapse
included
friendly_name, #initialize, #name, required!, skippable?, #staged, stealth!, #stealth?
Instance Method Details
#relevant_tests ⇒ Object
5
6
7
8
9
|
# File 'lib/overcommit/plugins/pre_commit/test_history.rb', line 5
def relevant_tests
@relevant_test ||=
`relevant-tests 2> /dev/null -- #{modified_files.join(' ')}`.
split("\n").map { |r| File.expand_path r }
end
|
#run_check ⇒ Object
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
|
# File 'lib/overcommit/plugins/pre_commit/test_history.rb', line 16
def run_check
output = []
unless relevant_tests.any?
return :warn, 'No relevant tests for this change...write some?'
end
begin
good_tests = File.open(TEST_RESULTS_FILE, 'r').readlines.map do |spec_file|
File.expand_path spec_file.strip
end
rescue Errno::ENOENT
good_tests = []
end
unless good_tests.any?
return :bad,
'The relevant tests for this change have not yet been run using `specr`'
end
missed_tests = (relevant_tests - good_tests)
unless missed_tests.empty?
output << 'The following relevant tests have not been run recently:'
output << missed_tests.sort
return :bad, output
end
test_time = File.mtime(TEST_RESULTS_FILE)
untested_files = modified_files.reject do |file|
File.mtime(file) < test_time
end
unless untested_files.empty?
output << 'The following files were modified after `specr` was run.'
output << '(their associated tests may be broken):'
output << untested_files.sort
return :bad, output
end
return :good
end
|
#skip? ⇒ Boolean
11
12
13
|
# File 'lib/overcommit/plugins/pre_commit/test_history.rb', line 11
def skip?
!FileTest.exist?('spec/support/record_results_formatter.rb')
end
|