miss_cleo 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d889d4159d13979e2976e1eebe9a73128071d3f
4
- data.tar.gz: 13628125e02da62520de6811604ea8b494787678
3
+ metadata.gz: d7443ba51e59b7d1941d4ee652e26543136da4d1
4
+ data.tar.gz: 5f8c6e24bafa1eafff383a4435fcd25bf45428d6
5
5
  SHA512:
6
- metadata.gz: 97c85e168bdf2907c93ca4efd7232d33697a598e9654003fbdcb98cb57024f23b2ef69732c1eaa144acb7e6f850b2c395c4711f80963c6b258d157f5c4838136
7
- data.tar.gz: 7797c5a2b7de1db2b1874f8b476baeb51641c3493045ea9e9f9d8ece57375b1ade890aa28e26e37c5461cd6bfed7a066ada5904617efc8b22f9e5518e6ad247f
6
+ metadata.gz: 05a3e70338e08f3c3ac99397f15def5b6212e76b0d7dd458fd4fc0715d24288db41a078337336aaad4d6c30cedf97ebcca26cf8d424059c08cbabf1e617a3fcc
7
+ data.tar.gz: f29c165a827f380f548b10fa62fdc24f08c8ef0220a8a5b2cd1f3c8dfa01b33260a0e62d21239187a10015b29e5ce8c7ae96702f5f1473ece4237d9b478400d1
data/README.md CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
25
25
 
26
26
  ## Setup
27
27
 
28
- Right now Miss Cleo only supports Cucumber and RSpec tests. To use Miss Cleo.
28
+ Right now Miss Cleo only supports Cucumber and RSpec tests. To use Miss Cleo:
29
29
 
30
30
  ### Cucumber
31
31
  Before you can use Miss Cleo with your Cucumber tests, add the following line to your `support/env.rb` file:
@@ -43,19 +43,32 @@ MissCleo::TestConfigurations::RspecConfig.setup_hooks(self)
43
43
 
44
44
  ### How to get predictin'
45
45
 
46
- To use Miss Cleo, you'll need to first build a coverage map of your *green* build. Do this by running your tests with the `COVERAGE` environment variable set to true.
46
+ To use Miss Cleo, you'll need to first build a coverage diff of your *green* build. Do this by running your tests with the `COVERAGE` environment variable set to true.
47
47
 
48
48
  Examples:
49
49
 
50
50
  * `COVERAGE=true cucumber features/user.feature`
51
51
  * `COVERAGE=true rspec spec/user_spec.rb`
52
52
 
53
+ With your coverage diffs built, you'll need to generate a coverage map, which we're calling a *deck*. To build your deck, run:
54
+ `miss_cleo build_deck <list of coverage diff files>`
55
+
53
56
  ## Usage
54
57
 
55
- After you've made some code changes, run `miss_cleo` to be shown the relevant tests to run.
58
+ After you've made some code changes, run `miss_cleo predict` to be shown the relevant tests to run.
56
59
 
57
60
  **Note**: Miss Cleo only tries to predict tests failures for uncommitted changes. Make sure your build is green before committing code!
58
61
 
62
+
63
+ ## Known Oversights
64
+
65
+ Like the real Miss Cleo, we can't predict everything. Things we can't predict include:
66
+ - Rails views
67
+ - ActiveRecord methods
68
+ - ActiveRecord concerns
69
+ - Anything that generally runs only through gem code
70
+ - Any external library code
71
+
59
72
  ## Contributing
60
73
 
61
74
  1. Fork it ( https://github.com/[my-github-username]/miss_cleo/fork )
data/bin/miss_cleo CHANGED
@@ -49,53 +49,62 @@ def diff before, after
49
49
  end
50
50
  end
51
51
 
52
- def get_cov_map_for(file_name)
52
+ def build_coverage_map(cov_diffs)
53
53
  cov_map = Hash.new { |h, file| h[file] = Hash.new { |i, line| i[line] = [] } }
54
+ cov_diffs.each do |args|
55
+ if args.length == 4 # for Minitest
56
+ desc = args.first(2).join('#')
57
+ else # for RSpec
58
+ desc = args.first
59
+ end
60
+
61
+ before, after = args.last(2)
62
+
63
+ # calculate the per test coverage
64
+ delta = diff before, after
65
+
66
+ delta.each_pair do |file, lines|
67
+ file_map = cov_map[file]
68
+
69
+ lines.each_with_index do |val, i|
70
+ # skip lines that weren't executed
71
+ next unless val && val > 0
54
72
 
55
- if File.exists?(file_name)
56
- File.open(file_name, "r") do |f|
57
- content = f.read
58
- return if content.empty?
59
- # Read in the coverage info
60
- JSON.parse(content).each do |args|
61
- if args.length == 4 # for Minitest
62
- desc = args.first(2).join('#')
63
- else # for RSpec
64
- desc = args.first
65
- end
66
-
67
- before, after = args.last(2)
68
-
69
- # calculate the per test coverage
70
- delta = diff before, after
71
-
72
- delta.each_pair do |file, lines|
73
- file_map = cov_map[file]
74
-
75
- lines.each_with_index do |val, i|
76
- # skip lines that weren't executed
77
- next unless val && val > 0
78
-
79
- # add the test name to the map. Multiple tests can execute the same
80
- # line, so we need to use an array.
81
- file_map[i + 1] << desc
82
- end
83
- end
73
+ # add the test name to the map. Multiple tests can execute the same
74
+ # line, so we need to use an array.
75
+ file_map[i + 1] << desc
84
76
  end
85
77
  end
86
78
  end
87
79
  cov_map
88
80
  end
89
81
 
90
- cuke_map = get_cov_map_for(MissCleo::TestConfigurations::CucumberConfig::CUCUMBER_MAP)
91
- spec_map = get_cov_map_for(MissCleo::TestConfigurations::RspecConfig::RSPEC_MAP)
82
+ case ARGV.first
83
+ when "build_deck"
84
+ filenames = ARGV[1..-1]
85
+ coverage_diffs = []
86
+ filenames.each do |filename|
87
+ File.open(filename, "r") do |f|
88
+ f.read
89
+ end.tap do |contents|
90
+ coverage_diffs += JSON.parse(contents)
91
+ end
92
+ end
93
+
94
+ coverage_map = build_coverage_map(coverage_diffs)
92
95
 
93
- puts "You need to run"
94
- lines_to_run.each do |file, line|
95
- spec_map && spec_map[File.expand_path(file)].fetch(line, []).uniq.each do |desc|
96
- puts desc
96
+ File.open("total_coverage_map.json", "w") do |f|
97
+ f.write(JSON.dump(coverage_map))
97
98
  end
98
- cuke_map && cuke_map[File.expand_path(file)].fetch(line, []).uniq.each do |desc|
99
- puts desc
99
+ when "predict"
100
+ coverage_map = JSON.parse(File.open("total_coverage_map.json").read)
101
+ puts "You need to run"
102
+ tests_to_run = []
103
+ lines_to_run.each do |file, line|
104
+ coverage_map && coverage_map[File.expand_path(file)] && coverage_map[File.expand_path(file)].fetch(line.to_s, []).uniq.each do |desc|
105
+ tests_to_run << desc
106
+ end
100
107
  end
108
+ puts tests_to_run.uniq.sort
101
109
  end
110
+
@@ -1,3 +1,3 @@
1
1
  module MissCleo
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Hu
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-09 00:00:00.000000000 Z
12
+ date: 2015-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -90,3 +90,4 @@ signing_key:
90
90
  specification_version: 4
91
91
  summary: Predict your test failures
92
92
  test_files: []
93
+ has_rdoc: