miss_cleo 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 04e41f5049ab3702747dd2585b5995d9f76d33a5
4
+ data.tar.gz: a58b4dd402cafc3b5a1d01367515456e1d8aee6c
5
+ SHA512:
6
+ metadata.gz: f05fd1c915fcb06a02c4067fc14674d9f89068f4f32c8a3bb860544e0dbe10af15b585c88c54d391375997ec5a6a2bd8ea1caa6d1f404aa05e3603813b32f3a1
7
+ data.tar.gz: 3be489fbcf2fdff2a47cf54eddb79a055b133481e26743c4a16c703233ea3bbee4e088721b575f82761989333384dda8183361de5a0c86e30518fad4303c8b2f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in miss_cleo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 david rosenbloom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # MissCleo
2
+ ![Miss Cleo](http://i.imgur.com/v4vmFtq.jpg)
3
+
4
+ Miss Cleo is a test failure predictor based on [Tenderlove's idea](http://tenderlovemaking.com/2015/02/13/predicting-test-failues.html). The idea is to give you a reasonable amount of confidence that your code changes are ok without having to run your full CI build.
5
+
6
+ ## Requirements
7
+
8
+ Miss Cleo depends on Ruby 2.3.x (currently trunk Ruby) for its `Coverage.peek_result` functionality.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'miss_cleo'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install miss_cleo
25
+
26
+ ## Setup
27
+
28
+ Right now Miss Cleo only supports Cucumber and RSpec tests. To use Miss Cleo.
29
+
30
+ ### Cucumber
31
+ Before you can use Miss Cleo with your Cucumber tests, add the following line to your `support/env.rb` file:
32
+
33
+ ```ruby
34
+ MissCleo::TestConfigurations::CucumberConfig.setup_hooks(self)
35
+ ```
36
+
37
+ ### Rspec
38
+ Before you can use Miss Cleo with your RSpec tests, add the following line to your `spec/spec_helper.rb` file:
39
+
40
+ ```ruby
41
+ MissCleo::TestConfigurations::RspecConfig.setup_hooks(self)
42
+ ```
43
+
44
+ ### How to get predictin'
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.
47
+
48
+ Examples:
49
+
50
+ * `COVERAGE=true cucumber features/user.feature`
51
+ * `COVERAGE=true rspec spec/user_spec.rb`
52
+
53
+ ## Usage
54
+
55
+ After you've made some code changes, run `miss_cleo` to be shown the relevant tests to run.
56
+
57
+ **Note**: Miss Cleo only tries to predict tests failures for uncommitted changes. Make sure your build is green before committing code!
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( https://github.com/[my-github-username]/miss_cleo/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "miss_cleo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/miss_cleo ADDED
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "miss_cleo"
4
+ require 'pry'
5
+
6
+ repo = Rugged::Repository.new '.'
7
+ lines_to_run = Set.new
8
+
9
+ def exclude_from_map?(file_name)
10
+ # Let's add a configuration for ignored files
11
+ file_name == "db/structure.sql"
12
+ end
13
+
14
+ repo.index.diff.each_patch do |patch|
15
+ file = patch.delta.old_file[:path]
16
+
17
+ patch.each_hunk do |hunk|
18
+ hunk.each_line do |line|
19
+ case line.line_origin
20
+ when :addition
21
+ lines_to_run << [file, line.new_lineno] unless exclude_from_map?(file)
22
+ when :deletion
23
+ lines_to_run << [file, line.old_lineno] unless exclude_from_map?(file)
24
+ when :context
25
+ # do nothing
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def diff before, after
32
+ after.each_with_object({}) do |(file_name,line_cov), res|
33
+ before_line_cov = before[file_name] || []
34
+
35
+ # skip arrays that are exactly the same
36
+ next if before_line_cov == line_cov
37
+
38
+ # subtract the old coverage from the new coverage
39
+ cov = line_cov.zip(before_line_cov).map do |line_after, line_before|
40
+ if line_before
41
+ line_after - line_before
42
+ else
43
+ line_after
44
+ end
45
+ end
46
+
47
+ # add the "diffed" coverage to the hash
48
+ res[file_name] = cov
49
+ end
50
+ end
51
+
52
+ def get_cov_map_for(file_name)
53
+ cov_map = Hash.new { |h, file| h[file] = Hash.new { |i, line| i[line] = [] } }
54
+
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
84
+ end
85
+ end
86
+ end
87
+ cov_map
88
+ end
89
+
90
+ cuke_map = get_cov_map_for(MissCleo::TestConfigurations::CucumberConfig::CUCUMBER_MAP)
91
+ spec_map = get_cov_map_for(MissCleo::TestConfigurations::RspecConfig::RSPEC_MAP)
92
+
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
97
+ end
98
+ cuke_map && cuke_map[File.expand_path(file)].fetch(line, []).uniq.each do |desc|
99
+ puts desc
100
+ end
101
+ end
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/miss_cleo.rb ADDED
@@ -0,0 +1,14 @@
1
+ # Pull these into bundler
2
+ require 'json'
3
+ require 'coverage'
4
+ require 'shellwords'
5
+ require 'rugged'
6
+ require 'set'
7
+
8
+ require "miss_cleo/version"
9
+ require 'miss_cleo/coverage_filter'
10
+ require 'miss_cleo/test_configurations/cucumber_config'
11
+ require 'miss_cleo/test_configurations/rspec_config'
12
+
13
+ module MissCleo
14
+ end
@@ -0,0 +1,15 @@
1
+ module MissCleo
2
+ class CoverageFilter
3
+ GEM_PATHS = ENV["GEM_PATH"].split(":")
4
+ RUBY_PATH = `which ruby`.chomp.gsub("/bin/ruby","")
5
+
6
+ def self.filter_core(result_hash)
7
+
8
+ # Don't include gems in coverage map
9
+ result_hash.reject do |file, line|
10
+ ([RUBY_PATH] + GEM_PATHS).any? { |path| file.include?(path) }
11
+ end
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,26 @@
1
+ module MissCleo
2
+ module TestConfigurations
3
+ class CucumberConfig
4
+ CUCUMBER_MAP = "cucumber_map.json"
5
+ LOGS = []
6
+
7
+ def self.setup_hooks(context)
8
+ if ENV["COVERAGE"]
9
+ Coverage.start
10
+ context.Around do |scenario, execute|
11
+ before = Coverage.peek_result
12
+ execute.call
13
+ after = Coverage.peek_result
14
+ if file_and_line = scenario.try(:file_colon_line)
15
+ LOGS << [ file_and_line, before, after ]
16
+ end
17
+ end
18
+
19
+ at_exit do
20
+ File.open(CUCUMBER_MAP, 'w') { |f| f.write JSON.dump LOGS }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module MissCleo
2
+ module TestConfigurations
3
+ class RspecConfig
4
+ RSPEC_MAP = "rspec_map.json"
5
+ LOGS = []
6
+
7
+ def self.setup_hooks(context)
8
+ if ENV["COVERAGE"]
9
+ Coverage.start
10
+ RSpec.configuration.after(:suite) do
11
+ File.open(RSPEC_MAP, 'w') { |f| f.write JSON.dump LOGS }
12
+ end
13
+
14
+ RSpec.configuration.around(:example) do |example|
15
+ before = Coverage.peek_result
16
+ example.call
17
+ after = Coverage.peek_result
18
+ LOGS << [ example.location, CoverageFilter.filter_core(before),
19
+ CoverageFilter.filter_core(after) ]
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,3 @@
1
+ module MissCleo
2
+ VERSION = "0.1.1"
3
+ end
data/miss_cleo.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'miss_cleo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "miss_cleo"
8
+ spec.version = MissCleo::VERSION
9
+ spec.authors = ["Dean Hu", "Lee Ourand"]
10
+ spec.email = ["devs@gust.com"]
11
+ spec.required_ruby_version = ">= 2.3.0"
12
+
13
+ spec.summary = %q{Predict your test failures}
14
+ spec.description = %q{Miss Cleo frees you from having to run your full test suite to be confident in your recent code changes. Call me now!}
15
+ spec.homepage = "http://github.com/gust/miss_cleo"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.executables = ["miss_cleo"]
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: miss_cleo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dean Hu
8
+ - Lee Ourand
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-10-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.8'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.8'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ description: Miss Cleo frees you from having to run your full test suite to be confident
43
+ in your recent code changes. Call me now!
44
+ email:
45
+ - devs@gust.com
46
+ executables:
47
+ - miss_cleo
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - .gitignore
52
+ - .rspec
53
+ - .travis.yml
54
+ - CODE_OF_CONDUCT.md
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/console
60
+ - bin/miss_cleo
61
+ - bin/setup
62
+ - lib/miss_cleo.rb
63
+ - lib/miss_cleo/coverage_filter.rb
64
+ - lib/miss_cleo/test_configurations/cucumber_config.rb
65
+ - lib/miss_cleo/test_configurations/rspec_config.rb
66
+ - lib/miss_cleo/version.rb
67
+ - miss_cleo.gemspec
68
+ homepage: http://github.com/gust/miss_cleo
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: 2.3.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.2.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Predict your test failures
92
+ test_files: []