git_spec 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 09a87453296aa306dd921f98a4fd9f24c04a5868
4
+ data.tar.gz: 987ceece10f4d021b43ffaa769103b144a77574a
5
+ SHA512:
6
+ metadata.gz: 5aa843fdb02a3e4676e3d2b75a24980db1b5d14aa7c701e1707aa423964896760245ff4061d6ccd831c057687c6c8f41b974614090fcec90a90ba9363f8aa8c5
7
+ data.tar.gz: 5ef69d87c95fd32108a5e526ad5e7cffa8432b2a8dd1e896353836148ca18217255985268c274e2fe4d905834a9e986b11e21164bc15ae43c05f45346c0e0f9d
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/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ git_spec
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.3
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at bill@billthompson.me. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in git_spec.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Bill Thompson
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,61 @@
1
+ # GitSpec
2
+
3
+ Execute your test runner for files in your git diff.
4
+
5
+ Examples:
6
+
7
+ M lib/git_spec.rb
8
+
9
+ GitSpec will expect the test to be defined at spec/git_spec_spec.rb
10
+
11
+ M lib/git_spec/file.rb
12
+
13
+ GitSpec will expect the test to be defined at spec/git_spec/file_spec.rb
14
+
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'git_spec'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install git_spec
31
+
32
+ ## Usage
33
+
34
+ $ gspec spec [options]
35
+
36
+ Options:
37
+
38
+ --command="bundle exec rspec" - The command to execute your test runner. This command will receive a single argument of space-delimited file paths.
39
+
40
+ --src_root="lib/" - The primary source directory for your application. For Rails, set to "app/".
41
+
42
+ --log_level="Logger::INFO" - The log level.
43
+
44
+ --dry_run="true", Aliases: -d - Should the test runner be executed? When in dry run mode, the list of files that would be sent to the test runner will be output.
45
+
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/billthompson/git_spec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
56
+
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
61
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "git_spec"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/gspec ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Exit cleanly from an early interrupt
4
+ Signal.trap("INT") { exit 1 }
5
+
6
+ # require "lib/git_spec"
7
+ #
8
+ # system "bundle exec #{ARGV.first} #{GitSpec.files}"
9
+ #
10
+ require 'git_spec'
11
+ require 'git_spec/cli'
12
+ GitSpec::CLI.start
data/git_spec.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'git_spec/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "git_spec"
8
+ spec.version = GitSpec::VERSION
9
+ spec.authors = ["Bill Thompson"]
10
+ spec.email = ["bill@billthompson.me"]
11
+
12
+ spec.summary = "Parse your git diff to determine what specs should be ran."
13
+ spec.description = "Finds the specs that should be ran based on model, controller or lib files modified in your git diff."
14
+ spec.homepage = "https://github.com/billthompson/git_spec"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_runtime_dependency 'thor', '~> 0', '>= 0.19.0'
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.13"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ end
@@ -0,0 +1,55 @@
1
+ require 'thor'
2
+
3
+ module GitSpec
4
+ class CLI < Thor
5
+ desc "spec [COMMAND]", "Execute COMMAND with files arg"
6
+ method_option :command, default: 'bundle exec rspec', aliases: ['-c']
7
+ method_option :src_root, default: 'lib/'
8
+ method_option :log_level, type: :numeric, default: Logger::INFO, aliases: ['-l']
9
+ method_option :dry_run, type: :boolean, default: false, aliases: ['-d']
10
+ method_option :project_root, default: Dir.getwd
11
+ def spec
12
+ GitSpec.configure do |config|
13
+ config.git_root = options.project_root
14
+ config.src_root = options.src_root
15
+ config.log_level = options.log_level
16
+ end
17
+
18
+ files, missing_files = GitSpec.changed_files
19
+ missing_files_banner(missing_files) if missing_files.any?
20
+ filtered_to_banner(files) if files.any?
21
+
22
+ if options.dry_run
23
+ say("Dry run enabled. Would have sent the following files to the spec runner:", :yellow)
24
+ say(files.join(' '), :yellow)
25
+ else
26
+ system "#{options.command} #{files.join(' ')}"
27
+ end
28
+
29
+ end
30
+
31
+ private
32
+
33
+ def missing_files_banner(missing_files)
34
+ say("Expected specs at the following locations but they could not be found:", :red)
35
+
36
+ missing_files.each do |filename|
37
+ say(" * #{filename}", :red)
38
+ end
39
+ puts
40
+ puts
41
+ end
42
+
43
+ def filtered_to_banner(files)
44
+ say("Executing the spec runner for:", :green)
45
+
46
+ files.each do |filename|
47
+ say(" * #{filename}", :green)
48
+ end
49
+ puts
50
+ puts
51
+ end
52
+
53
+
54
+ end
55
+ end
@@ -0,0 +1,11 @@
1
+ module GitSpec
2
+ class Configuration
3
+ attr_accessor :src_root, :log_level
4
+
5
+
6
+ def initialize
7
+ @src_root = 'lib/'
8
+ @log_level = ::Logger::INFO
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,60 @@
1
+ module GitSpec
2
+ class File
3
+ # TODO: Move this to the config
4
+ EXCLUDED_FILE_PATTERNS = [/^exe\//, /^spec\//, /^vendor\//, /^config\//, /^regression_tests\//, /^\./]
5
+
6
+ attr_reader :configuration, :path
7
+
8
+ def initialize(filename, configuration = GitSpec.configuration)
9
+ @path = filename.strip
10
+ @configuration = configuration
11
+ end
12
+
13
+ def spec_path
14
+ # TODO: Get test dir from config
15
+ # TODO: Get spec naming convention from config
16
+ @spec_path ||= begin
17
+ filename = path
18
+ filename = "spec/" << filename
19
+ filename.gsub!(".rb", "_spec.rb")
20
+
21
+ filename.gsub!(configuration.src_root, "")
22
+
23
+ filename
24
+ end
25
+ rescue => e
26
+ # TODO: Log helpful info when this happens
27
+ raise
28
+ end
29
+
30
+ def excluded?
31
+ return true, 'Invalid file type' unless is_ruby?
32
+ filtered = should_filter?(path)
33
+
34
+ if filtered
35
+ return filtered, 'Excluded by file pattern match'
36
+ else
37
+ return filtered
38
+ end
39
+ end
40
+
41
+ # TODO: Make this a whitelisted file extension configuration
42
+ def is_ruby?
43
+ ::File.extname(path) == '.rb'
44
+ end
45
+
46
+ def should_filter?(filename)
47
+ should_exclude = false
48
+ EXCLUDED_FILE_PATTERNS.each do |pattern|
49
+ match = filename =~ pattern
50
+
51
+ unless match.nil?
52
+ should_exclude = true
53
+ break
54
+ end
55
+ end
56
+ should_exclude
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ module GitSpec
2
+ class Logger < ::Logger
3
+
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ module GitSpec
2
+ class Status
3
+ def initialize(logger = GitSpec.logger)
4
+ @logger = logger
5
+ end
6
+
7
+ def changed_files
8
+ changed_files = (filenames).each_with_object([]) do |filename, changed|
9
+ file = File.new(filename)
10
+
11
+ excluded, excluded_reason = file.excluded?
12
+ if excluded
13
+ @logger.debug "Excluding #{file.spec_path} with reason: #{excluded_reason}"
14
+ else
15
+ changed << file
16
+ @logger.debug "Including #{file.spec_path}"
17
+ end
18
+ end
19
+
20
+ changed_files.uniq{|f| f.spec_path}
21
+ rescue => e
22
+ # TODO: Log helpful info when this happens
23
+ raise
24
+ end
25
+
26
+ def self.changed_files
27
+ new.changed_files
28
+ end
29
+
30
+ private
31
+
32
+ def filenames
33
+ files = %x[git diff --name-only master..HEAD && git ls-files --exclude-standard --others && git diff --name-only && git diff --name-only --cached]
34
+ files.split("\n")
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module GitSpec
2
+ VERSION = "0.1.0"
3
+ end
data/lib/git_spec.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'logger'
2
+
3
+ require 'git_spec/version'
4
+ require 'git_spec/configuration'
5
+ require 'git_spec/logger'
6
+ require 'git_spec/status'
7
+ require 'git_spec/file'
8
+
9
+ module GitSpec
10
+ class << self
11
+ attr_reader :configuration, :logger
12
+ end
13
+
14
+ def self.configure
15
+ self.configuration ||= Configuration.new
16
+
17
+ yield(configuration)
18
+
19
+ @logger = GitSpec::Logger.new(STDOUT)
20
+ logger.level = configuration.log_level
21
+ end
22
+
23
+
24
+ def self.changed_files
25
+ logger.debug "Gathering changed files..."
26
+ all_spec_paths = GitSpec::Status.changed_files.map(&:spec_path)
27
+ segment_paths(all_spec_paths)
28
+ end
29
+
30
+ private
31
+
32
+ def self.segment_paths(paths)
33
+ exists = paths.select{|f| ::File.exists?(f)}
34
+ dont_exist = paths - exists
35
+
36
+ return exists, dont_exist
37
+ end
38
+
39
+
40
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_spec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bill Thompson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.19.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.19.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.13'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.13'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ description: Finds the specs that should be ran based on model, controller or lib
76
+ files modified in your git diff.
77
+ email:
78
+ - bill@billthompson.me
79
+ executables:
80
+ - gspec
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - ".gitignore"
85
+ - ".rspec"
86
+ - ".ruby-gemset"
87
+ - ".ruby-version"
88
+ - ".travis.yml"
89
+ - CODE_OF_CONDUCT.md
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/setup
96
+ - exe/gspec
97
+ - git_spec.gemspec
98
+ - lib/git_spec.rb
99
+ - lib/git_spec/cli.rb
100
+ - lib/git_spec/configuration.rb
101
+ - lib/git_spec/file.rb
102
+ - lib/git_spec/logger.rb
103
+ - lib/git_spec/status.rb
104
+ - lib/git_spec/version.rb
105
+ homepage: https://github.com/billthompson/git_spec
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ allowed_push_host: https://rubygems.org
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.8
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Parse your git diff to determine what specs should be ran.
130
+ test_files: []