grspec 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/grspec +7 -2
- data/lib/find_changed_files/between_refs.rb +34 -0
- data/lib/find_changed_files/simple_diff.rb +21 -0
- data/lib/find_changed_files/since_ref.rb +27 -0
- data/lib/find_changed_files.rb +27 -29
- data/lib/find_matching_specs.rb +0 -0
- data/lib/spec_runner.rb +0 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4abdcf7f8708b6c96caa5d31a34921ae17a9477eca30a5b690eaf7bcc5a83d60
|
4
|
+
data.tar.gz: c413562adce5015317e3baf2cbce2b54a2b9a4d03ff31f5e59865ed33f56d219
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 230116a9de943ff6081a22cdd188e6cf3b1b897f1a460a4e673785c22c46a1b4f4b041bde0aeb3a7880aa55fcb3df25e3e9da258b2d44fec4ae4d7f0326b7d01
|
7
|
+
data.tar.gz: 2ac42186c768e92bfb4334068968b248197dabc7ee864e2f395ed57780feb44cf0cd11818dd4f8f5853fe7f4fe7411a5d67805748cab721e6bdfb1ed8d3612d7
|
data/bin/grspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require 'active_support/core_ext/array/access'
|
2
3
|
|
3
4
|
require 'find_changed_files'
|
4
5
|
require 'find_matching_specs'
|
@@ -10,8 +11,12 @@ def display_listing(header, listing)
|
|
10
11
|
puts listing
|
11
12
|
end
|
12
13
|
|
13
|
-
git_diff_args = ARGV.
|
14
|
-
|
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
|
15
20
|
|
16
21
|
if changed_files.any?
|
17
22
|
display_listing('Changed files:', changed_files)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class FindChangedFiles::BetweenRefs < FindChangedFiles
|
2
|
+
attr_reader :base_ref, :diff_ref
|
3
|
+
|
4
|
+
GIT_MERGE_BASE_COMMAND = 'git merge-base'.freeze
|
5
|
+
|
6
|
+
def initialize(base_ref:, diff_ref:)
|
7
|
+
@base_ref = base_ref
|
8
|
+
@diff_ref = diff_ref
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
differed_files(merge_base_ref, diff_ref)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def merge_base_ref
|
18
|
+
merge_base = `#{GIT_MERGE_BASE_COMMAND} #{base_ref} #{diff_ref} #{REDIRECT_STDERR_TO_STDOUT}`
|
19
|
+
|
20
|
+
raise ArgumentError.new("Bad git diff arguments; #{base_ref} #{diff_ref}") unless $?.success?
|
21
|
+
|
22
|
+
merge_base.strip
|
23
|
+
end
|
24
|
+
|
25
|
+
def differed_files(from_ref, to_ref)
|
26
|
+
@differed_files ||= begin
|
27
|
+
diff_output = `#{GIT_DIFF_COMMAND} #{from_ref} #{to_ref} #{GIT_DIFF_OPTIONS} #{REDIRECT_STDERR_TO_STDOUT}`
|
28
|
+
|
29
|
+
raise ArgumentError.new("Bad git diff arguments; #{base_ref} #{diff_ref}") unless $?.success?
|
30
|
+
|
31
|
+
diff_output.split("\n")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class FindChangedFiles::SimpleDiff < FindChangedFiles
|
2
|
+
def call
|
3
|
+
differed_files +
|
4
|
+
untracked_files +
|
5
|
+
staged_files
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def differed_files
|
11
|
+
`#{GIT_DIFF_COMMAND} #{GIT_DIFF_OPTIONS} #{REDIRECT_STDERR_TO_STDOUT}`.split("\n")
|
12
|
+
end
|
13
|
+
|
14
|
+
def untracked_files
|
15
|
+
`git ls-files . --exclude-standard --others`.split("\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
def staged_files
|
19
|
+
`#{GIT_DIFF_COMMAND} --staged #{GIT_DIFF_OPTIONS}`.split("\n")
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class FindChangedFiles::SinceRef < FindChangedFiles
|
2
|
+
attr_reader :base_ref
|
3
|
+
|
4
|
+
CURRENT_REF = 'HEAD'
|
5
|
+
|
6
|
+
def initialize(base_ref:)
|
7
|
+
@base_ref = base_ref
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
changed_files_between_commits +
|
12
|
+
changed_files_in_diff
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def changed_files_in_diff
|
18
|
+
SimpleDiff.new.call
|
19
|
+
end
|
20
|
+
|
21
|
+
def changed_files_between_commits
|
22
|
+
BetweenRefs.new(
|
23
|
+
base_ref: base_ref,
|
24
|
+
diff_ref: CURRENT_REF
|
25
|
+
).call
|
26
|
+
end
|
27
|
+
end
|
data/lib/find_changed_files.rb
CHANGED
@@ -1,52 +1,50 @@
|
|
1
1
|
class FindChangedFiles
|
2
|
-
|
2
|
+
require 'active_support/core_ext/object/blank'
|
3
3
|
|
4
|
-
|
4
|
+
require_relative 'find_changed_files/simple_diff'
|
5
|
+
require_relative 'find_changed_files/since_ref'
|
6
|
+
require_relative 'find_changed_files/between_refs'
|
7
|
+
|
8
|
+
attr_reader :base_ref, :diff_ref
|
5
9
|
|
6
10
|
GIT_DIFF_COMMAND = 'git diff'.freeze
|
7
11
|
GIT_DIFF_OPTIONS = '--name-only'.freeze
|
12
|
+
|
8
13
|
REDIRECT_STDERR_TO_STDOUT = '2>&1'.freeze
|
9
14
|
|
10
|
-
def initialize(
|
11
|
-
@
|
15
|
+
def initialize(base_ref: nil, diff_ref: nil)
|
16
|
+
@base_ref = base_ref
|
17
|
+
@diff_ref = diff_ref
|
12
18
|
end
|
13
19
|
|
14
20
|
def call
|
15
|
-
changed_files = differed_files
|
16
|
-
|
17
21
|
if simple_diff?
|
18
|
-
|
19
|
-
|
22
|
+
SimpleDiff.new.call
|
23
|
+
elsif since_ref?
|
24
|
+
SinceRef.new(
|
25
|
+
base_ref: base_ref
|
26
|
+
).call
|
27
|
+
elsif between_refs?
|
28
|
+
BetweenRefs.new(
|
29
|
+
base_ref: base_ref,
|
30
|
+
diff_ref: diff_ref
|
31
|
+
).call
|
32
|
+
else
|
33
|
+
raise ArgumentError.new('A base ref must be supplied with a diff ref')
|
20
34
|
end
|
21
|
-
|
22
|
-
changed_files
|
23
35
|
end
|
24
36
|
|
25
37
|
private
|
26
38
|
|
27
39
|
def simple_diff?
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def stringified_args
|
32
|
-
args.join(' ')
|
33
|
-
end
|
34
|
-
|
35
|
-
def differed_files
|
36
|
-
@differed_files ||= begin
|
37
|
-
diff_output = `#{GIT_DIFF_COMMAND} #{stringified_args} #{GIT_DIFF_OPTIONS} #{REDIRECT_STDERR_TO_STDOUT}`
|
38
|
-
|
39
|
-
raise GitDiffError.new("Bad git diff arguments; #{stringified_args}") unless $?.success?
|
40
|
-
|
41
|
-
diff_output.split("\n")
|
42
|
-
end
|
40
|
+
base_ref.blank? && diff_ref.blank?
|
43
41
|
end
|
44
42
|
|
45
|
-
def
|
46
|
-
|
43
|
+
def since_ref?
|
44
|
+
base_ref.present? && diff_ref.blank?
|
47
45
|
end
|
48
46
|
|
49
|
-
def
|
50
|
-
|
47
|
+
def between_refs?
|
48
|
+
base_ref.present? && diff_ref.present?
|
51
49
|
end
|
52
50
|
end
|
data/lib/find_matching_specs.rb
CHANGED
File without changes
|
data/lib/spec_runner.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordane Lew
|
@@ -21,6 +21,9 @@ extra_rdoc_files: []
|
|
21
21
|
files:
|
22
22
|
- bin/grspec
|
23
23
|
- lib/find_changed_files.rb
|
24
|
+
- lib/find_changed_files/between_refs.rb
|
25
|
+
- lib/find_changed_files/simple_diff.rb
|
26
|
+
- lib/find_changed_files/since_ref.rb
|
24
27
|
- lib/find_matching_specs.rb
|
25
28
|
- lib/spec_runner.rb
|
26
29
|
homepage: https://rubygems.org/gems/grspec
|
@@ -46,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
49
|
version: '0'
|
47
50
|
requirements: []
|
48
51
|
rubyforge_project:
|
49
|
-
rubygems_version: 2.
|
52
|
+
rubygems_version: 2.7.3
|
50
53
|
signing_key:
|
51
54
|
specification_version: 4
|
52
55
|
summary: A simple spec runner for differed files
|