test_file_finder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b01e368369d161afd0766f1ea95a296b16dc8cb5e3f20d5c8e7abf7910e8da0b
4
+ data.tar.gz: 442c058ea7d0ad184d5fe31d697cb9f0f3058b1fe09e03717cf8d12bbadaa5cc
5
+ SHA512:
6
+ metadata.gz: 70f2284e0d24b68b4a426acd9d42c02a4886c64e258282339459ae4df8ae5da73484916f78b3ca774b8619d88666dc40041f6820f306def6fc5f10d70a143033
7
+ data.tar.gz: ccfc5613ed9250411a4e2623ddcf650d2a982e7631d0d3bdb12b820278bfa07c7c0f3595424f925bfc78324c54ba1106dd2180e9bf802756c2dc0037172672dc
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.byebug_history
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
@@ -0,0 +1,9 @@
1
+ rspec:
2
+ script: bundle; bundle exec rspec
3
+ rules:
4
+ - if: $CI
5
+
6
+ check-executable:
7
+ script: bash tff_test.sh
8
+ rules:
9
+ - if: $CI
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in test_file_finder.gemspec
4
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ test_file_finder (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (11.1.3)
10
+ diff-lcs (1.3)
11
+ rake (10.5.0)
12
+ rspec (3.9.0)
13
+ rspec-core (~> 3.9.0)
14
+ rspec-expectations (~> 3.9.0)
15
+ rspec-mocks (~> 3.9.0)
16
+ rspec-core (3.9.2)
17
+ rspec-support (~> 3.9.3)
18
+ rspec-expectations (3.9.2)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.9.0)
21
+ rspec-mocks (3.9.1)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.9.0)
24
+ rspec-support (3.9.3)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.17)
31
+ byebug
32
+ rake (~> 10.0)
33
+ rspec (~> 3.0)
34
+ test_file_finder!
35
+
36
+ BUNDLED WITH
37
+ 1.17.3
@@ -0,0 +1,53 @@
1
+ # TestFileFinder
2
+
3
+ A Ruby gem for deteting test files associated with input files.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'test_file_finder', git: 'https://gitlab.com/gitlab-org/ci-cd/test_file_finder.git'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```shell
16
+ bundle install
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Ruby
22
+
23
+ The FileFinder class has exactly one method (`#test_files`) that returns existing test files likely to be associated with the files you passed into `#initialize`:
24
+
25
+ ```ruby
26
+ TestFileFinder::FileFinder.new(paths: file_paths).test_files
27
+ ```
28
+
29
+ ### Command Line
30
+
31
+ TestFileFinder is packed up into the `tff` executable, which can be used from the command line:
32
+
33
+ ```bash
34
+ $ file_paths="app/models/widget.rb"
35
+ $ tff $file_paths
36
+ spec/models/widget_spec.rb
37
+ ```
38
+
39
+ You can use it in a script, for example:
40
+
41
+ ```bash
42
+ $ rspec $(tff $(git diff --name-only master..head))
43
+ ```
44
+
45
+ ## Development
46
+
47
+ 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.
48
+
49
+ 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).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and merge requests are welcome in GitLab at <https://gitlab.com/gitlab-org/ci-cd/test_file_finder>.
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'test_file_finder'
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(__FILE__)
@@ -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/tff ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test_file_finder'
3
+
4
+ puts TestFileFinder::FileFinder.new(paths: ARGV).test_files
@@ -0,0 +1,6 @@
1
+ require 'test_file_finder/version'
2
+ require 'test_file_finder/file_finder'
3
+
4
+ module TestFileFinder
5
+ class Error < StandardError; end
6
+ end
@@ -0,0 +1,47 @@
1
+ class TestFileFinder::FileFinder
2
+
3
+ def initialize(paths: [])
4
+ @paths = [paths].flatten
5
+ end
6
+
7
+ def test_files
8
+ search
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :paths
14
+
15
+ def search
16
+ file_path_guesses.select { |path| File.exist?(path) }
17
+ end
18
+
19
+ def file_path_guesses
20
+ paths.map do |path|
21
+ guess_test_files_for(path)
22
+ end.compact.uniq
23
+ end
24
+
25
+ def context
26
+ {
27
+ app: %r{^app/(.+)\.rb$},
28
+ lib: %r{^lib/(.+)\.rb$},
29
+ spec: %r{^spec/(.+)_spec.rb$},
30
+ spec_dir: 'spec',
31
+ }
32
+ end
33
+
34
+ def guess_test_files_for(path)
35
+ if (match = context[:app]&.match(path))
36
+ return "#{context[:spec_dir]}/#{match[1]}_spec.rb"
37
+ end
38
+
39
+ if (match = context[:lib]&.match(path))
40
+ return "#{context[:spec_dir]}/lib/#{match[1]}_spec.rb"
41
+ end
42
+
43
+ if context[:spec]&.match(path)
44
+ return path
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module TestFileFinder
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'test_file_finder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'test_file_finder'
8
+ spec.version = TestFileFinder::VERSION
9
+ spec.authors = ['drew cimino']
10
+ spec.email = ['dscimino@gmail.com']
11
+
12
+ spec.summary = %q{Guesses spec file paths given input file paths.}
13
+ spec.description = %q{A command-line tool for guessing which spec files are relavant to a passed-in set of file paths.}
14
+ spec.homepage = 'https://gitlab.com/gitlab-org/ci-cd/test-file-finder'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://gitlab.com/gitlab-org/ci-cd/test-file-finder/-/tree/master'
23
+ spec.metadata['changelog_uri'] = 'https://gitlab.com/gitlab-org/ci-cd/test-file-finder/-/blob/master/CHANGELOG.md'
24
+ else
25
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+
37
+ spec.add_development_dependency 'bundler', '~> 1.17'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'byebug'
41
+ end
@@ -0,0 +1,16 @@
1
+
2
+ expected="spec/models/test_file_finder_gem_executable_widget_spec.rb"
3
+ mkdir -p "spec/models"
4
+ echo "existing specs" >> $expected
5
+
6
+ actual=$( ruby -Ilib exe/tff app/models/test_file_finder_gem_executable_widget.rb)
7
+ rm $expected
8
+
9
+ if [[ -n $actual && $expected = $actual ]]
10
+ then
11
+ echo "Executable verified"
12
+ exit 0
13
+ else
14
+ echo "Could not verify executable"
15
+ exit 1
16
+ fi
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_file_finder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - drew cimino
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-11 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
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: A command-line tool for guessing which spec files are relavant to a passed-in
70
+ set of file paths.
71
+ email:
72
+ - dscimino@gmail.com
73
+ executables:
74
+ - tff
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".gitlab-ci.yml"
80
+ - ".rspec"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - exe/tff
88
+ - lib/test_file_finder.rb
89
+ - lib/test_file_finder/file_finder.rb
90
+ - lib/test_file_finder/version.rb
91
+ - test_file_finder.gemspec
92
+ - tff_test.sh
93
+ homepage: https://gitlab.com/gitlab-org/ci-cd/test-file-finder
94
+ licenses: []
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ homepage_uri: https://gitlab.com/gitlab-org/ci-cd/test-file-finder
98
+ source_code_uri: https://gitlab.com/gitlab-org/ci-cd/test-file-finder/-/tree/master
99
+ changelog_uri: https://gitlab.com/gitlab-org/ci-cd/test-file-finder/-/blob/master/CHANGELOG.md
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubygems_version: 3.0.3
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Guesses spec file paths given input file paths.
119
+ test_files: []