grspec 0.2.0 → 0.4.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 +4 -4
- data/bin/grspec +9 -32
- data/lib/arg_parser.rb +29 -0
- data/lib/find_changed_files/between_refs.rb +4 -2
- data/lib/find_changed_files/simple_diff.rb +0 -0
- data/lib/find_changed_files/since_ref.rb +0 -0
- data/lib/find_changed_files.rb +3 -5
- data/lib/find_matching_specs.rb +7 -5
- data/lib/grspec.rb +107 -0
- data/lib/spec_runner.rb +2 -2
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc337747d9c3b2075d13056a58f61dc3c8bcf14b82aa6ebd37479c0c8f5de31e
|
4
|
+
data.tar.gz: 1a52c3b2e2697eb8e930d418e6360f5aeb640527befa8ebd42eef3b72da18828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef68c66b44a274b4435d119f1e4e75c77f36bc3e19f519a0268043565267c08296f77450675350754c1f906469dc3ddb258d4bd7413e263357877e8e5fe3ca67
|
7
|
+
data.tar.gz: b2cd5ee27d70a7d3b255d78f915cae0a7f5620b22a5e81b3d615bda6046fe1ed8e6879b8dd276a1b8479021a1dfd8ea693d8628fc29167fda8dc09dc6cece131
|
data/bin/grspec
CHANGED
@@ -1,35 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require_relative '../lib/arg_parser'
|
3
|
+
require_relative '../lib/grspec'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
require 'spec_runner'
|
5
|
+
options = ArgParser.parse(ARGV)
|
6
|
+
base_ref, diff_ref = ARGV[0..1]
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
git_diff_args = ARGV.first(2)
|
15
|
-
|
16
|
-
changed_files = FindChangedFiles.new(
|
17
|
-
base_ref: git_diff_args.first,
|
18
|
-
diff_ref: git_diff_args.second
|
19
|
-
).call
|
20
|
-
|
21
|
-
if changed_files.any?
|
22
|
-
display_listing('Changed files:', changed_files)
|
23
|
-
|
24
|
-
matching_specs = FindMatchingSpecs.new(changed_files).call
|
25
|
-
|
26
|
-
if matching_specs.any?
|
27
|
-
display_listing('Matching specs:', matching_specs)
|
28
|
-
|
29
|
-
SpecRunner.run(matching_specs)
|
30
|
-
else
|
31
|
-
puts "No matching specs found"
|
32
|
-
end
|
33
|
-
else
|
34
|
-
puts "No changed files found"
|
35
|
-
end
|
8
|
+
Grspec.new(
|
9
|
+
base_ref: base_ref,
|
10
|
+
diff_ref: diff_ref,
|
11
|
+
options: options
|
12
|
+
).run
|
data/lib/arg_parser.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
class ArgParser
|
5
|
+
def self.parse(options)
|
6
|
+
args = OpenStruct.new
|
7
|
+
|
8
|
+
opt_parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: grspec [git ref] [git ref] [options]"
|
10
|
+
|
11
|
+
opts.on("-rSPEC_REGEX", "--regex=SPEC_REGEX", Regexp, "Regex to filter specs") do |regex|
|
12
|
+
args.spec_regex = regex
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on("-d", "--dry", "Performs a dry run for a listing that would be passed through to RSpec") do
|
16
|
+
args.dry_run = true
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("-h", "--help", "Prints this help") do
|
20
|
+
puts opts
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
opt_parser.parse!(options)
|
26
|
+
|
27
|
+
args
|
28
|
+
end
|
29
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
class FindChangedFiles::BetweenRefs < FindChangedFiles
|
2
|
+
require 'English'
|
3
|
+
|
2
4
|
attr_reader :base_ref, :diff_ref
|
3
5
|
|
4
6
|
GIT_MERGE_BASE_COMMAND = 'git merge-base'.freeze
|
@@ -17,7 +19,7 @@ class FindChangedFiles::BetweenRefs < FindChangedFiles
|
|
17
19
|
def merge_base_ref
|
18
20
|
merge_base = `#{GIT_MERGE_BASE_COMMAND} #{base_ref} #{diff_ref} #{REDIRECT_STDERR_TO_STDOUT}`
|
19
21
|
|
20
|
-
raise ArgumentError.new("Bad git diff arguments; #{base_ref} #{diff_ref}") unless
|
22
|
+
raise ArgumentError.new("Bad git diff arguments; #{base_ref} #{diff_ref}") unless $CHILD_STATUS.success?
|
21
23
|
|
22
24
|
merge_base.strip
|
23
25
|
end
|
@@ -26,7 +28,7 @@ class FindChangedFiles::BetweenRefs < FindChangedFiles
|
|
26
28
|
@differed_files ||= begin
|
27
29
|
diff_output = `#{GIT_DIFF_COMMAND} #{from_ref} #{to_ref} #{GIT_DIFF_OPTIONS} #{REDIRECT_STDERR_TO_STDOUT}`
|
28
30
|
|
29
|
-
raise ArgumentError.new("Bad git diff arguments; #{base_ref} #{diff_ref}") unless
|
31
|
+
raise ArgumentError.new("Bad git diff arguments; #{base_ref} #{diff_ref}") unless $CHILD_STATUS.success?
|
30
32
|
|
31
33
|
diff_output.split("\n")
|
32
34
|
end
|
File without changes
|
File without changes
|
data/lib/find_changed_files.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
class FindChangedFiles
|
2
|
-
require 'active_support/core_ext/object/blank'
|
3
|
-
|
4
2
|
require_relative 'find_changed_files/simple_diff'
|
5
3
|
require_relative 'find_changed_files/since_ref'
|
6
4
|
require_relative 'find_changed_files/between_refs'
|
@@ -37,14 +35,14 @@ class FindChangedFiles
|
|
37
35
|
private
|
38
36
|
|
39
37
|
def simple_diff?
|
40
|
-
base_ref
|
38
|
+
!base_ref && !diff_ref
|
41
39
|
end
|
42
40
|
|
43
41
|
def since_ref?
|
44
|
-
base_ref
|
42
|
+
base_ref && !diff_ref
|
45
43
|
end
|
46
44
|
|
47
45
|
def between_refs?
|
48
|
-
base_ref
|
46
|
+
base_ref && diff_ref
|
49
47
|
end
|
50
48
|
end
|
data/lib/find_matching_specs.rb
CHANGED
@@ -11,9 +11,9 @@ class FindMatchingSpecs
|
|
11
11
|
|
12
12
|
def call
|
13
13
|
ruby_files = files.select { |filename| ruby_file?(filename) }
|
14
|
-
spec_files = ruby_files.map { |filename| specs_for(filename) }
|
14
|
+
spec_files = ruby_files.map { |filename| specs_for(filename) }
|
15
15
|
|
16
|
-
spec_files.
|
16
|
+
spec_files.uniq
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
@@ -31,14 +31,16 @@ class FindMatchingSpecs
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def specs_for(filename)
|
34
|
-
return [filename] if spec_file?(filename)
|
34
|
+
return [filename, filename] if spec_file?(filename)
|
35
35
|
|
36
|
-
spec_file_listing.
|
36
|
+
spec_match = spec_file_listing.detect do |spec_file|
|
37
37
|
file_for_spec = spec_file.gsub(/\/?spec\//, '/')
|
38
38
|
file_for_spec.sub!(SPEC_PREFIX_AND_EXTENSION, RUBY_FILE_EXTENSION)
|
39
39
|
file_for_spec.sub!(/^\//, '')
|
40
40
|
|
41
41
|
file_for_spec == filename
|
42
42
|
end
|
43
|
+
|
44
|
+
[filename, spec_match]
|
43
45
|
end
|
44
|
-
end
|
46
|
+
end
|
data/lib/grspec.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require_relative '../lib/find_changed_files'
|
2
|
+
require_relative '../lib/find_matching_specs'
|
3
|
+
require_relative '../lib/spec_runner'
|
4
|
+
|
5
|
+
class Grspec
|
6
|
+
attr_reader :base_ref, :diff_ref, :options
|
7
|
+
|
8
|
+
def initialize(base_ref:, diff_ref:, options: OpenStruct.new)
|
9
|
+
@base_ref = base_ref
|
10
|
+
@diff_ref = diff_ref
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
if changed_files.empty?
|
16
|
+
display("No changed files found")
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
display_listing('Changed files:', changed_files)
|
21
|
+
|
22
|
+
display_listing(
|
23
|
+
'Files without specs:',
|
24
|
+
mismatching_files.map(&:first)
|
25
|
+
) if mismatching_files.any?
|
26
|
+
|
27
|
+
if spec_matchings.any?
|
28
|
+
display_listing(
|
29
|
+
'Matching specs:',
|
30
|
+
spec_matchings.map { |matching_spec| matching_spec.join(' -> ') }
|
31
|
+
)
|
32
|
+
|
33
|
+
if non_existent_specs.any?
|
34
|
+
display_listing(
|
35
|
+
'Removed specs:',
|
36
|
+
non_existent_specs
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
if specs_to_run.any?
|
41
|
+
if dry_run?
|
42
|
+
puts specs_to_run
|
43
|
+
else
|
44
|
+
SpecRunner.run(specs_to_run)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
display("No matching specs found")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def dry_run?
|
55
|
+
options.dry_run
|
56
|
+
end
|
57
|
+
|
58
|
+
def changed_files
|
59
|
+
@changed_files ||= FindChangedFiles.new(
|
60
|
+
base_ref: base_ref,
|
61
|
+
diff_ref: diff_ref
|
62
|
+
).call
|
63
|
+
end
|
64
|
+
|
65
|
+
def file_spec_pairs
|
66
|
+
@file_spec_pairs ||= FindMatchingSpecs.new(changed_files).call
|
67
|
+
end
|
68
|
+
|
69
|
+
def mismatching_files
|
70
|
+
@mismatching_files ||= file_spec_pairs.select { |_, spec| spec.nil? }
|
71
|
+
end
|
72
|
+
|
73
|
+
def spec_matchings
|
74
|
+
@spec_matchings ||= file_spec_pairs - mismatching_files
|
75
|
+
end
|
76
|
+
|
77
|
+
def matching_specs
|
78
|
+
@matching_specs ||= spec_matchings.map { |match| match[1] }.uniq
|
79
|
+
end
|
80
|
+
|
81
|
+
def non_existent_specs
|
82
|
+
@non_existent_specs ||= matching_specs.reject { |spec_file| File.file?(spec_file) }
|
83
|
+
end
|
84
|
+
|
85
|
+
def specs_to_run
|
86
|
+
@specs_to_run ||= matching_specs - non_existent_specs
|
87
|
+
end
|
88
|
+
|
89
|
+
def display_output?
|
90
|
+
!dry_run?
|
91
|
+
end
|
92
|
+
|
93
|
+
def display(string)
|
94
|
+
return unless display_output?
|
95
|
+
|
96
|
+
puts
|
97
|
+
puts string
|
98
|
+
end
|
99
|
+
|
100
|
+
def display_listing(header, listing)
|
101
|
+
return unless display_output?
|
102
|
+
|
103
|
+
puts
|
104
|
+
puts header
|
105
|
+
puts listing
|
106
|
+
end
|
107
|
+
end
|
data/lib/spec_runner.rb
CHANGED
metadata
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordane Lew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: GRSpec is a
|
14
|
-
|
15
|
-
without full-on test runs before committing and overloading build nodes.
|
13
|
+
description: GRSpec is a tool for quickly and easily running specs for files that
|
14
|
+
git has detected changes for, allowing for efficient regression checks.
|
16
15
|
email: jordane.lew@gmail.com
|
17
16
|
executables:
|
18
17
|
- grspec
|
@@ -20,11 +19,13 @@ extensions: []
|
|
20
19
|
extra_rdoc_files: []
|
21
20
|
files:
|
22
21
|
- bin/grspec
|
22
|
+
- lib/arg_parser.rb
|
23
23
|
- lib/find_changed_files.rb
|
24
24
|
- lib/find_changed_files/between_refs.rb
|
25
25
|
- lib/find_changed_files/simple_diff.rb
|
26
26
|
- lib/find_changed_files/since_ref.rb
|
27
27
|
- lib/find_matching_specs.rb
|
28
|
+
- lib/grspec.rb
|
28
29
|
- lib/spec_runner.rb
|
29
30
|
homepage: https://rubygems.org/gems/grspec
|
30
31
|
licenses:
|
@@ -48,9 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
49
|
- !ruby/object:Gem::Version
|
49
50
|
version: '0'
|
50
51
|
requirements: []
|
51
|
-
|
52
|
-
rubygems_version: 2.7.3
|
52
|
+
rubygems_version: 3.0.3
|
53
53
|
signing_key:
|
54
54
|
specification_version: 4
|
55
|
-
summary: A simple spec runner for
|
55
|
+
summary: A simple spec runner for diff'd files
|
56
56
|
test_files: []
|