miss_cleo 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/miss_cleo +56 -48
- data/lib/miss_cleo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca0559ed443b3ea335c68d740f9968bf08280993
|
4
|
+
data.tar.gz: db76dd62cdada7d6da85c8f8c45799c4773515ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b2573361d83d35b2220c8cdd7c95c5a520156f69378e592fb58c76a49a1829571ba3808fbeb97466a35b96f82f189cf92bbdf59c6d8e2c36a601b5e31ed7904
|
7
|
+
data.tar.gz: a703da817837bedc711e7b58d0204ec6c128ff27452d52afd562b0332f20911327e5698670f7435ea16dc1f0693d61c2992f15dc9382dc23b4dc4f8db93105da
|
data/bin/miss_cleo
CHANGED
@@ -3,29 +3,64 @@
|
|
3
3
|
require "miss_cleo"
|
4
4
|
require 'pry'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
case ARGV.first
|
7
|
+
when "build_deck"
|
8
|
+
filenames = ARGV[1..-1]
|
9
|
+
cov_map = Hash.new { |h, file| h[file] = Hash.new { |i, line| i[line] = [] } }
|
10
|
+
filenames.each do |filename|
|
11
|
+
File.open(filename, "r") do |f|
|
12
|
+
f.read
|
13
|
+
end.tap do |contents|
|
14
|
+
build_coverage_map(cov_map, JSON.parse(contents))
|
15
|
+
end
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
File.open("total_coverage_map.json", "w") do |f|
|
19
|
+
f.write(JSON.dump(cov_map))
|
20
|
+
end
|
21
|
+
when "predict"
|
22
|
+
repo = Rugged::Repository.new '.'
|
23
|
+
lines_changed = Set.new
|
24
|
+
|
25
|
+
repo.index.diff.each_patch do |patch|
|
26
|
+
file = patch.delta.old_file[:path]
|
27
|
+
|
28
|
+
patch.each_hunk do |hunk|
|
29
|
+
hunk.each_line do |line|
|
30
|
+
case line.line_origin
|
31
|
+
when :addition
|
32
|
+
lines_changed << [file, line.new_lineno] unless exclude_from_map?(file)
|
33
|
+
when :deletion
|
34
|
+
lines_changed << [file, line.old_lineno] unless exclude_from_map?(file)
|
35
|
+
when :context
|
36
|
+
# do nothing
|
37
|
+
end
|
26
38
|
end
|
27
39
|
end
|
28
40
|
end
|
41
|
+
|
42
|
+
coverage_map = JSON.parse(File.open("total_coverage_map.json").read)
|
43
|
+
tests_to_run = []
|
44
|
+
lines_changed.each do |file, line|
|
45
|
+
coverage_map && coverage_map[File.expand_path(file)] && coverage_map[File.expand_path(file)].fetch(line.to_s, []).uniq.each do |desc|
|
46
|
+
tests_to_run << desc
|
47
|
+
end
|
48
|
+
end
|
49
|
+
if lines_changed.empty?
|
50
|
+
puts "No line changes detected."
|
51
|
+
elsif tests_to_run.empty?
|
52
|
+
puts "No tests found. May be due to blind spot, new tests you've just written, or the changes may be untested."
|
53
|
+
else
|
54
|
+
puts "Run these tests:"
|
55
|
+
puts tests_to_run.uniq.sort
|
56
|
+
end
|
57
|
+
else
|
58
|
+
puts "Please run miss_cleo with 'build_deck' or 'predict'."
|
59
|
+
end
|
60
|
+
|
61
|
+
def exclude_from_map?(file_name)
|
62
|
+
# Let's add a configuration for ignored files
|
63
|
+
file_name == "db/structure.sql"
|
29
64
|
end
|
30
65
|
|
31
66
|
def diff before, after
|
@@ -54,7 +89,7 @@ def build_coverage_map(cov_map, cov_diffs)
|
|
54
89
|
if test_to_code_map.length == 4 # for Minitest
|
55
90
|
test_file_and_line = test_to_code_map.first(2).join('#')
|
56
91
|
else # for RSpec
|
57
|
-
|
92
|
+
test_file_and_line = test_to_code_map.first
|
58
93
|
end
|
59
94
|
before, after = test_to_code_map.last(2)
|
60
95
|
|
@@ -70,36 +105,9 @@ def build_coverage_map(cov_map, cov_diffs)
|
|
70
105
|
|
71
106
|
# add the test name to the map. Multiple tests can execute the same
|
72
107
|
# line, so we need to use an array.
|
73
|
-
file_map[i + 1] <<
|
108
|
+
file_map[i + 1] << test_file_and_line
|
74
109
|
end
|
75
110
|
end
|
76
111
|
end
|
77
112
|
end
|
78
113
|
|
79
|
-
case ARGV.first
|
80
|
-
when "build_deck"
|
81
|
-
filenames = ARGV[1..-1]
|
82
|
-
cov_map = Hash.new { |h, file| h[file] = Hash.new { |i, line| i[line] = [] } }
|
83
|
-
filenames.each do |filename|
|
84
|
-
File.open(filename, "r") do |f|
|
85
|
-
f.read
|
86
|
-
end.tap do |contents|
|
87
|
-
build_coverage_map(cov_map, JSON.parse(contents))
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
File.open("total_coverage_map.json", "w") do |f|
|
92
|
-
f.write(JSON.dump(coverage_map))
|
93
|
-
end
|
94
|
-
when "predict"
|
95
|
-
coverage_map = JSON.parse(File.open("total_coverage_map.json").read)
|
96
|
-
puts "You need to run"
|
97
|
-
tests_to_run = []
|
98
|
-
lines_to_run.each do |file, line|
|
99
|
-
coverage_map && coverage_map[File.expand_path(file)] && coverage_map[File.expand_path(file)].fetch(line.to_s, []).uniq.each do |desc|
|
100
|
-
tests_to_run << desc
|
101
|
-
end
|
102
|
-
end
|
103
|
-
puts tests_to_run.uniq.sort
|
104
|
-
end
|
105
|
-
|
data/lib/miss_cleo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miss_cleo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Hu
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-11-
|
13
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|