test_changes 0.1.0

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: a999841b6f326deba13cc4be0bf981f008cc5140
4
+ data.tar.gz: 8e114720be8c3ce34f4b923625b6241d746ff8fe
5
+ SHA512:
6
+ metadata.gz: 6925132e8fff59a6f81998fbf9b641bcc99de788f8ee21dd67bdda53a0343cb6f6af6c71f5cd6660483ffe55280414012190dc737f5a1104ce9b435075427e10
7
+ data.tar.gz: cc6b4a0ba1c303c8aedb531c4cb25dd970d35146ba87230564f2e86e2e39df84c9eb28781b01419b05c8a6e3a453809bc8e5c8367d9496f3f2ef62c69bb2797f
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/.overcommit.yml ADDED
@@ -0,0 +1,33 @@
1
+ # Use this file to configure the Overcommit hooks you wish to use. This will
2
+ # extend the default configuration defined in:
3
+ # https://github.com/brigade/overcommit/blob/master/config/default.yml
4
+ #
5
+ # At the topmost level of this YAML file is a key representing type of hook
6
+ # being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
7
+ # customize each hook, such as whether to only run it on certain files (via
8
+ # `include`), whether to only display output if it fails (via `quiet`), etc.
9
+ #
10
+ # For a complete list of hooks, see:
11
+ # https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
12
+ #
13
+ # For a complete list of options that you can use to customize hooks, see:
14
+ # https://github.com/brigade/overcommit#configuration
15
+ #
16
+ # Uncomment the following lines to make the configuration take effect.
17
+
18
+ PreCommit:
19
+ RuboCop:
20
+ enabled: true
21
+ on_warn: fail # Treat all warnings as failures
22
+
23
+ TrailingWhitespace:
24
+ enabled: true
25
+ exclude:
26
+ - '**/db/structure.sql' # Ignore trailing whitespace in generated files
27
+ #
28
+ #PostCheckout:
29
+ # ALL: # Special hook name that customizes all hooks of this type
30
+ # quiet: true # Change all post-checkout hooks to only display output on failure
31
+ #
32
+ # IndexTags:
33
+ # enabled: true # Generate a tags file with `ctags` each time HEAD changes
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ # Refer to https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+ # for the default rubocop configuration.
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ Metrics/LineLength:
8
+ Max: 89
9
+
10
+ StringLiterals:
11
+ Enabled: false
12
+
13
+ Style/AlignParameters:
14
+ Enabled: false
@@ -0,0 +1,7 @@
1
+ ---
2
+ test_tool_command: rspec
3
+ finding_patterns:
4
+ ^lib/(.+)\.rb: spec/\1_spec.rb
5
+ ^spec/(.+)_spec.rb: spec/\1_spec.rb
6
+
7
+ verbose: true
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 test_changes.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 George Mendoza
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,91 @@
1
+ # Test Changes
2
+
3
+ Test files that have changed since a given commit.
4
+
5
+ ## Requirements
6
+
7
+ * [Git](https://git-scm.com)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'test_changes', require: false
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install test_changes
24
+
25
+ ## Configuration
26
+
27
+ Add a `.test_changes.yaml` configuration file to your repo. Example:
28
+
29
+ ```yaml
30
+ ---
31
+ test_tool_command: rspec
32
+
33
+ finding_patterns:
34
+ ^lib/(.+)\.rb: spec/\1_spec.rb
35
+ ^spec/(.+)_spec.rb: spec/\1_spec.rb
36
+
37
+ verbose: true
38
+ ```
39
+
40
+ The options
41
+
42
+ * `test_tool_command` - The command for running the tests.
43
+ Example: `rspec`, `zeus rspec`.
44
+
45
+ * `finding_patterns` - If the name of a changed file matches the regular expression,
46
+ `test_changes` will test the file's matching tests. Can accept an array
47
+ of tests:
48
+
49
+ ```yaml
50
+ finding_patterns:
51
+ ^lib/test_changes\.rb:
52
+ - spec/test_changes_spec.rb
53
+ - spec/test_changes/client_spec.rb
54
+ ```
55
+
56
+ * `verbose` - Set the verbose level of output.
57
+
58
+ ## Usage
59
+
60
+ `test_changes [test_tool_arguments] [commit]`
61
+
62
+ * `test_tool_arguments` - Arguments that can be passed to the test tool.
63
+
64
+ * `commit` - Test change from this commit. Defaults to HEAD.
65
+
66
+ Examples:
67
+
68
+ ```
69
+ test_changes
70
+ test_changes master
71
+ test_changes --format=documentation HEAD^
72
+ ```
73
+
74
+ ## Known to work on
75
+
76
+ * Ruby 2.0.0
77
+ * Git 2.3.5
78
+
79
+ ## Development
80
+
81
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
82
+
83
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
84
+
85
+ ## Contributing
86
+
87
+ 1. Fork it ( https://github.com/gsmendoza/test_changes/fork )
88
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
89
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
90
+ 4. Push to the branch (`git push origin my-new-feature`)
91
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "test_changes"
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/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/exe/test_changes ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test_changes/argv_wrapper'
4
+ require 'test_changes/client'
5
+ require 'test_changes/config'
6
+
7
+ argv_wrapper = TestChanges::ARGVWrapper.new(ARGV)
8
+ config = TestChanges::Config.new('.test_changes.yaml')
9
+
10
+ client = TestChanges::Client.new(
11
+ test_tool_command: config.test_tool_command,
12
+ finding_patterns: config.finding_patterns,
13
+ commit: argv_wrapper.commit,
14
+ test_tool_call_options: argv_wrapper.test_tool_call_options,
15
+ verbose: config.verbose)
16
+
17
+ client.call
@@ -0,0 +1,19 @@
1
+ module TestChanges
2
+ class ARGVWrapper
3
+ def initialize(argv)
4
+ @argv = argv
5
+ end
6
+
7
+ def commit
8
+ argv.last || 'HEAD'
9
+ end
10
+
11
+ def test_tool_call_options
12
+ argv[0, argv.size - 1] || []
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :argv
18
+ end
19
+ end
@@ -0,0 +1,78 @@
1
+ require 'test_changes/finding_pattern'
2
+
3
+ module TestChanges
4
+ class Client
5
+ def initialize(options)
6
+ @test_tool_command = options[:test_tool_command]
7
+ @finding_patterns = options[:finding_patterns]
8
+ @commit = options[:commit]
9
+ @test_tool_call_options = options[:test_tool_call_options]
10
+ @verbose = options[:verbose]
11
+ end
12
+
13
+ # rubocop:disable Metrics/AbcSize
14
+ def call
15
+ log "paths_changed_since_commit #{commit}:",
16
+ paths_changed_since_commit.inspect
17
+
18
+ log "matches:", matches.inspect
19
+
20
+ log "existing_matches:", existing_matches.inspect
21
+
22
+ return if existing_matches.empty?
23
+
24
+ log "test_tool_call:", test_tool_call
25
+ system(test_tool_call)
26
+ end
27
+ # rubocop:enable Metrics/AbcSize
28
+
29
+ private
30
+
31
+ attr_reader :commit,
32
+ :finding_patterns,
33
+ :test_tool_command,
34
+ :test_tool_call_options,
35
+ :verbose
36
+
37
+ def log(header, message)
38
+ return unless verbose?
39
+
40
+ puts "\n#{header}"
41
+ puts message
42
+ end
43
+
44
+ def verbose?
45
+ verbose
46
+ end
47
+
48
+ def paths_changed_since_commit
49
+ @paths_changed_since_commit ||=
50
+ `git diff --name-only --diff-filter=AMR #{commit}`.split("\n")
51
+ end
52
+
53
+ def test_tool_call
54
+ @test_tool_call ||= [
55
+ test_tool_command,
56
+ test_tool_call_options,
57
+ existing_matches
58
+ ].flatten.compact.join(' ')
59
+ end
60
+
61
+ def existing_matches
62
+ @existing_matches ||= matches.select { |match| File.exist?(match) }
63
+ end
64
+
65
+ def matches
66
+ return @matches if @matches
67
+
68
+ paths = paths_changed_since_commit
69
+
70
+ @matches =
71
+ paths.product(finding_patterns).map do |path, finding_pattern|
72
+ finding_pattern.matching_paths(path)
73
+ end
74
+
75
+ @matches = @matches.flatten.uniq
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,34 @@
1
+ require 'yaml'
2
+
3
+ module TestChanges
4
+ class Config
5
+ def initialize(config_path)
6
+ @config_path = config_path
7
+ end
8
+
9
+ def finding_patterns
10
+ config['finding_patterns'].map do |pattern, substitution_patterns|
11
+ FindingPattern.new(
12
+ matching_pattern: /#{pattern}/,
13
+ substitution_patterns: [substitution_patterns].flatten
14
+ )
15
+ end
16
+ end
17
+
18
+ def test_tool_command
19
+ config['test_tool_command']
20
+ end
21
+
22
+ def verbose
23
+ config['verbose']
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :config_path
29
+
30
+ def config
31
+ @config ||= YAML.load_file(config_path)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,24 @@
1
+ module TestChanges
2
+ class FindingPattern
3
+ attr_reader :matching_pattern, :substitution_patterns
4
+
5
+ def initialize(options = {})
6
+ @matching_pattern = options[:matching_pattern]
7
+ @substitution_patterns = options[:substitution_patterns]
8
+ end
9
+
10
+ def matching_paths(path)
11
+ results = substitution_patterns.map do |substitution_pattern|
12
+ path.sub(matching_pattern, substitution_pattern) if matches?(path)
13
+ end
14
+
15
+ results.compact
16
+ end
17
+
18
+ private
19
+
20
+ def matches?(path)
21
+ path =~ matching_pattern
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module TestChanges
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "test_changes/version"
2
+
3
+ module TestChanges
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'test_changes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "test_changes"
8
+ spec.version = TestChanges::VERSION
9
+ spec.authors = ["George Mendoza"]
10
+ spec.email = ["gsmendoza@gmail.com"]
11
+
12
+ spec.summary = %(Test Changes)
13
+
14
+ spec.description =
15
+ %(Run only the tests affected by files changed since a given commit.)
16
+
17
+ spec.homepage = "https://github.com/gsmendoza/test_changes"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
+ f.match(%r{^(test|spec|features)/})
22
+ end
23
+
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.8"
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec"
32
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_changes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - George Mendoza
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Run only the tests affected by files changed since a given commit.
70
+ email:
71
+ - gsmendoza@gmail.com
72
+ executables:
73
+ - test_changes
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".overcommit.yml"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - ".test_changes.yaml"
82
+ - ".travis.yml"
83
+ - CODE_OF_CONDUCT.md
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - exe/test_changes
91
+ - lib/test_changes.rb
92
+ - lib/test_changes/argv_wrapper.rb
93
+ - lib/test_changes/client.rb
94
+ - lib/test_changes/config.rb
95
+ - lib/test_changes/finding_pattern.rb
96
+ - lib/test_changes/version.rb
97
+ - test_changes.gemspec
98
+ homepage: https://github.com/gsmendoza/test_changes
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.1.11
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Test Changes
122
+ test_files: []