grspec 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/grspec +9 -33
- data/lib/arg_parser.rb +29 -0
- data/lib/find_matching_specs.rb +3 -3
- data/lib/grspec.rb +88 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16610e47bcb0c299bbff11a44ff15b8467014fc9f29047b661db9f9234fdfb5f
|
4
|
+
data.tar.gz: a0eb0ce7a49c84384d916dd259c2af74b1e7afd2d7b82f89a846f3e9bca47fce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19f518d2092c2a7282183aef5e8d6698944c3b0ec1540b7704b271543a7f2daca8d38f547165d1f37cb7a54dd188117e8cf504bf3788133a996a1bbe3e9b7c8f
|
7
|
+
data.tar.gz: 47cf4410ebdebb27d3211640d160790c7ee12cb601f87c55c415d8ca87a537810bfa92f7106241379c20fd48bca44fd4e19ad22d87a04d65e10b3362b1a5bb75
|
data/bin/grspec
CHANGED
@@ -1,36 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/arg_parser'
|
3
|
+
require_relative '../lib/grspec'
|
2
4
|
|
3
|
-
|
5
|
+
options = ArgParser.parse(ARGV)
|
6
|
+
base_ref, diff_ref = ARGV.first(2)
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
puts
|
11
|
-
puts header
|
12
|
-
puts listing
|
13
|
-
end
|
14
|
-
|
15
|
-
git_diff_args = ARGV.first(2)
|
16
|
-
|
17
|
-
changed_files = FindChangedFiles.new(
|
18
|
-
base_ref: git_diff_args.first,
|
19
|
-
diff_ref: git_diff_args.second
|
20
|
-
).call
|
21
|
-
|
22
|
-
if changed_files.any?
|
23
|
-
display_listing('Changed files:', changed_files)
|
24
|
-
|
25
|
-
matching_specs = FindMatchingSpecs.new(changed_files).call
|
26
|
-
|
27
|
-
if matching_specs.any?
|
28
|
-
display_listing('Matching specs:', matching_specs.map {|matching_spec| matching_spec.join(' -> ') })
|
29
|
-
|
30
|
-
SpecRunner.run(matching_specs.map(&:second).uniq)
|
31
|
-
else
|
32
|
-
puts "No matching specs found"
|
33
|
-
end
|
34
|
-
else
|
35
|
-
puts "No changed files found"
|
36
|
-
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
|
data/lib/find_matching_specs.rb
CHANGED
@@ -13,7 +13,7 @@ class FindMatchingSpecs
|
|
13
13
|
ruby_files = files.select { |filename| ruby_file?(filename) }
|
14
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
|
@@ -41,6 +41,6 @@ class FindMatchingSpecs
|
|
41
41
|
file_for_spec == filename
|
42
42
|
end
|
43
43
|
|
44
|
-
[filename, spec_match]
|
44
|
+
[filename, spec_match]
|
45
45
|
end
|
46
|
-
end
|
46
|
+
end
|
data/lib/grspec.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'active_support/core_ext/array/access'
|
2
|
+
|
3
|
+
require_relative '../lib/find_changed_files'
|
4
|
+
require_relative '../lib/find_matching_specs'
|
5
|
+
require_relative '../lib/spec_runner'
|
6
|
+
|
7
|
+
class Grspec
|
8
|
+
attr_reader :base_ref, :diff_ref, :options
|
9
|
+
|
10
|
+
def initialize(base_ref:, diff_ref:, options: OpenStruct.new)
|
11
|
+
@base_ref = base_ref
|
12
|
+
@diff_ref = diff_ref
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
if changed_files.empty?
|
18
|
+
display("No changed files found")
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
display_listing('Changed files:', changed_files)
|
23
|
+
|
24
|
+
display_listing(
|
25
|
+
'Files without specs:',
|
26
|
+
mismatching_files.map(&:first)
|
27
|
+
) if mismatching_files.any?
|
28
|
+
|
29
|
+
if matching_specs.any?
|
30
|
+
display_listing(
|
31
|
+
'Matching specs:',
|
32
|
+
matching_specs.map { |matching_spec| matching_spec.join(' -> ') }
|
33
|
+
)
|
34
|
+
|
35
|
+
if dry_run?
|
36
|
+
puts matching_specs.map(&:second).uniq
|
37
|
+
else
|
38
|
+
SpecRunner.run(matching_specs.map(&:second).uniq)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
display("No matching specs found")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def dry_run?
|
48
|
+
options.dry_run
|
49
|
+
end
|
50
|
+
|
51
|
+
def changed_files
|
52
|
+
@changed_files ||= FindChangedFiles.new(
|
53
|
+
base_ref: base_ref,
|
54
|
+
diff_ref: diff_ref
|
55
|
+
).call
|
56
|
+
end
|
57
|
+
|
58
|
+
def file_spec_pairs
|
59
|
+
@file_spec_pairs ||= FindMatchingSpecs.new(changed_files).call
|
60
|
+
end
|
61
|
+
|
62
|
+
def mismatching_files
|
63
|
+
@mismatching_files ||= file_spec_pairs.select { |_, spec| spec.nil? }
|
64
|
+
end
|
65
|
+
|
66
|
+
def matching_specs
|
67
|
+
@matching_specs ||= file_spec_pairs - mismatching_files
|
68
|
+
end
|
69
|
+
|
70
|
+
def display_output?
|
71
|
+
!dry_run?
|
72
|
+
end
|
73
|
+
|
74
|
+
def display(string)
|
75
|
+
return unless display_output?
|
76
|
+
|
77
|
+
puts
|
78
|
+
puts string
|
79
|
+
end
|
80
|
+
|
81
|
+
def display_listing(header, listing)
|
82
|
+
return unless display_output?
|
83
|
+
|
84
|
+
puts
|
85
|
+
puts header
|
86
|
+
puts listing
|
87
|
+
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: GRSpec is a tiny gem that can quickly and easily run specs for files
|
14
14
|
that git has detected changes for, allowing for quick and easy regression checking
|
@@ -20,11 +20,13 @@ extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
22
|
- bin/grspec
|
23
|
+
- lib/arg_parser.rb
|
23
24
|
- lib/find_changed_files.rb
|
24
25
|
- lib/find_changed_files/between_refs.rb
|
25
26
|
- lib/find_changed_files/simple_diff.rb
|
26
27
|
- lib/find_changed_files/since_ref.rb
|
27
28
|
- lib/find_matching_specs.rb
|
29
|
+
- lib/grspec.rb
|
28
30
|
- lib/spec_runner.rb
|
29
31
|
homepage: https://rubygems.org/gems/grspec
|
30
32
|
licenses:
|