retest 1.10.0 → 1.11.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/.github/dependabot.yml +6 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +6 -6
- data/lib/retest/matching_options/path.rb +60 -0
- data/lib/retest/matching_options.rb +53 -0
- data/lib/retest/prompt.rb +47 -0
- data/lib/retest/repository.rb +5 -27
- data/lib/retest/runners/cached_test_file.rb +23 -0
- data/lib/retest/runners/change_runner.rb +13 -9
- data/lib/retest/runners/test_runner.rb +13 -29
- data/lib/retest/runners/variable_runner.rb +6 -24
- data/lib/retest/runners.rb +7 -8
- data/lib/retest/setup.rb +4 -12
- data/lib/retest/version.rb +1 -1
- data/lib/retest/version_control/git.rb +23 -24
- data/lib/retest/version_control/no_version_control.rb +16 -11
- data/lib/retest/version_control.rb +6 -6
- data/lib/retest.rb +2 -1
- metadata +8 -4
- data/lib/retest/test_options.rb +0 -98
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e115f99996becceaa5a11f81f938afa18571c8bdcb3e3fe5e500bb4d2eaa647
|
4
|
+
data.tar.gz: 003bfb6679ddcfc531666fe397121170926248792503834f14e79566022da274
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c71cb0291862bdd2cdda6ca37a7d199b6ad95c48812ff099e26ceef5505bb138cd01ea230fcbf7627c051de1760393850f129c59066f4ca45db21310114bf66
|
7
|
+
data.tar.gz: eac9a20b762eea7d8706d4754f2894659c8aafb4f3930d99d8d5b730fe1e47ae4341538bf1616569e3d01f9a8555b3b1ec5c33be60c4db699d13d639947de285
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
retest (1.
|
4
|
+
retest (1.11.0)
|
5
5
|
listen (~> 3.2)
|
6
6
|
string-similarity (~> 2.1)
|
7
7
|
tty-option (~> 0.1)
|
@@ -11,16 +11,16 @@ GEM
|
|
11
11
|
specs:
|
12
12
|
byebug (11.1.3)
|
13
13
|
ffi (1.15.5)
|
14
|
-
listen (3.
|
14
|
+
listen (3.8.0)
|
15
15
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
16
16
|
rb-inotify (~> 0.9, >= 0.9.10)
|
17
17
|
minitest (5.15.0)
|
18
|
-
rake (
|
18
|
+
rake (13.0.6)
|
19
19
|
rb-fsevent (0.11.2)
|
20
20
|
rb-inotify (0.10.1)
|
21
21
|
ffi (~> 1.0)
|
22
22
|
string-similarity (2.1.0)
|
23
|
-
tty-option (0.
|
23
|
+
tty-option (0.3.0)
|
24
24
|
|
25
25
|
PLATFORMS
|
26
26
|
ruby
|
@@ -28,8 +28,8 @@ PLATFORMS
|
|
28
28
|
DEPENDENCIES
|
29
29
|
byebug
|
30
30
|
minitest (~> 5.0)
|
31
|
-
rake (~>
|
31
|
+
rake (~> 13.0)
|
32
32
|
retest!
|
33
33
|
|
34
34
|
BUNDLED WITH
|
35
|
-
2.
|
35
|
+
2.3.22
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Retest
|
4
|
+
class MatchingOptions
|
5
|
+
class Path
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def_delegators :pathname, :to_s, :basename, :extname, :dirname
|
9
|
+
|
10
|
+
attr_reader :pathname
|
11
|
+
def initialize(path)
|
12
|
+
@pathname = Pathname(path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def reversed_dirnames
|
16
|
+
@reversed_dirnames ||= dirnames.reverse
|
17
|
+
end
|
18
|
+
|
19
|
+
def dirnames
|
20
|
+
@dirnames ||= dirname.each_filename.to_a
|
21
|
+
end
|
22
|
+
|
23
|
+
def test?(test_directories: nil)
|
24
|
+
if test_directories && (test_directories & dirnames).empty?
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
|
28
|
+
test_regexs.any? { |regex| regex =~ to_s }
|
29
|
+
end
|
30
|
+
|
31
|
+
def possible_test?(file)
|
32
|
+
possible_test_regexs.any? { |regex| regex =~ file }
|
33
|
+
end
|
34
|
+
|
35
|
+
def similarity_score(file)
|
36
|
+
String::Similarity.levenshtein(to_s, file)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def test_regexs
|
42
|
+
[
|
43
|
+
Regexp.new("^(.*\/)?.*_(?:spec|test)#{extname}$"),
|
44
|
+
Regexp.new("^(.*\/)?(?:spec|test)_.*#{extname}$"),
|
45
|
+
]
|
46
|
+
end
|
47
|
+
|
48
|
+
def possible_test_regexs
|
49
|
+
[
|
50
|
+
Regexp.new("^(.*\/)?.*#{filename}_(?:spec|test)#{extname}$"),
|
51
|
+
Regexp.new("^(.*\/)?.*(?:spec|test)_#{filename}#{extname}$"),
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
55
|
+
def filename
|
56
|
+
basename(extname)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative 'matching_options/path'
|
2
|
+
|
3
|
+
module Retest
|
4
|
+
class MatchingOptions
|
5
|
+
def self.for(path, files: [], limit: nil)
|
6
|
+
new(path, files: files, limit: limit).filtered_results
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :path, :files, :test_directories
|
10
|
+
|
11
|
+
def initialize(path, files: [], limit: 5, test_directories: nil)
|
12
|
+
@path = Path.new(path)
|
13
|
+
@files = files
|
14
|
+
@limit = limit || 5
|
15
|
+
@test_directories = (test_directories || %w[spec test]) + %w[.] # add root file as a valid test directory
|
16
|
+
end
|
17
|
+
|
18
|
+
def filtered_results
|
19
|
+
if path.test?(test_directories: test_directories)
|
20
|
+
[path]
|
21
|
+
elsif (screened_tests = screen_namespaces(possible_tests)).any?
|
22
|
+
screened_tests
|
23
|
+
else
|
24
|
+
possible_tests
|
25
|
+
end.map(&:to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def possible_tests
|
31
|
+
@possible_tests ||= files
|
32
|
+
.select { |file| path.possible_test?(file) }
|
33
|
+
.sort_by { |file| [-path.similarity_score(file), file] }
|
34
|
+
.first(@limit)
|
35
|
+
end
|
36
|
+
|
37
|
+
def screen_namespaces(files)
|
38
|
+
test_files = files
|
39
|
+
.map { |file| Path.new(file) }
|
40
|
+
.select { |path| (path.reversed_dirnames & test_directories).any? }
|
41
|
+
|
42
|
+
path
|
43
|
+
.reversed_dirnames
|
44
|
+
.each
|
45
|
+
.with_index
|
46
|
+
.with_object(test_files) do |(dirname, index), tests|
|
47
|
+
break tests if tests.count <= 1
|
48
|
+
|
49
|
+
tests.keep_if { |test| test.reversed_dirnames[index] == dirname }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Retest
|
2
|
+
class Prompt
|
3
|
+
def self.ask_which_test_to_use(path, files)
|
4
|
+
new.ask_which_test_to_use(path, files)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.puts(*args)
|
8
|
+
new.puts(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :input, :output
|
12
|
+
def initialize(input: nil, output: nil)
|
13
|
+
@input = input || $stdin
|
14
|
+
@output = output || $stdout
|
15
|
+
end
|
16
|
+
|
17
|
+
def ask_which_test_to_use(path, files)
|
18
|
+
output.puts(<<~QUESTION)
|
19
|
+
We found few tests matching: #{path}
|
20
|
+
|
21
|
+
#{list_options(files)}
|
22
|
+
|
23
|
+
Which file do you want to use?
|
24
|
+
Enter the file number now:
|
25
|
+
QUESTION
|
26
|
+
|
27
|
+
files[input.gets.chomp.to_i]
|
28
|
+
end
|
29
|
+
|
30
|
+
def puts(*args)
|
31
|
+
output.puts(*args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def read_output
|
35
|
+
output.tap(&:rewind).read
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def list_options(files)
|
41
|
+
files
|
42
|
+
.map
|
43
|
+
.with_index { |file, index| "[#{index}] - #{file}" }
|
44
|
+
.join("\n")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/retest/repository.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
module Retest
|
2
2
|
class Repository
|
3
|
-
attr_accessor :files, :cache, :
|
3
|
+
attr_accessor :files, :cache, :prompt
|
4
4
|
|
5
|
-
def initialize(files: [], cache: {},
|
5
|
+
def initialize(files: [], cache: {}, prompt: nil)
|
6
6
|
@cache = cache
|
7
7
|
@files = files
|
8
|
-
@
|
9
|
-
@stdout = stdout
|
8
|
+
@prompt = prompt || Prompt.new
|
10
9
|
end
|
11
10
|
|
12
11
|
def find_test(path)
|
@@ -14,7 +13,7 @@ module Retest
|
|
14
13
|
return if path.empty?
|
15
14
|
|
16
15
|
@path = path
|
17
|
-
cache[@path] ||= select_from
|
16
|
+
cache[@path] ||= select_from MatchingOptions.for(@path, files: files)
|
18
17
|
end
|
19
18
|
|
20
19
|
def find_tests(paths)
|
@@ -55,29 +54,8 @@ module Retest
|
|
55
54
|
when 0, 1
|
56
55
|
tests.first
|
57
56
|
else
|
58
|
-
|
59
|
-
tests[get_input]
|
57
|
+
prompt.ask_which_test_to_use(@path, tests)
|
60
58
|
end
|
61
59
|
end
|
62
|
-
|
63
|
-
def ask_question(tests)
|
64
|
-
stdout.puts(<<~QUESTION)
|
65
|
-
We found few tests matching: #{@path}
|
66
|
-
#{list_options(tests)}
|
67
|
-
|
68
|
-
Which file do you want to use?
|
69
|
-
Enter the file number now:
|
70
|
-
QUESTION
|
71
|
-
end
|
72
|
-
|
73
|
-
def list_options(tests)
|
74
|
-
tests.map.with_index do |file, index|
|
75
|
-
"[#{index}] - #{file}"
|
76
|
-
end.join("\n")
|
77
|
-
end
|
78
|
-
|
79
|
-
def get_input
|
80
|
-
stdin.gets.chomp.to_i
|
81
|
-
end
|
82
60
|
end
|
83
61
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Retest
|
2
|
+
module Runners
|
3
|
+
module CachedTestFile
|
4
|
+
def cached_test_file
|
5
|
+
@cached_test_file
|
6
|
+
end
|
7
|
+
|
8
|
+
def cached_test_file=(value)
|
9
|
+
@cached_test_file = value || @cached_test_file
|
10
|
+
end
|
11
|
+
|
12
|
+
def purge_test_file(purged)
|
13
|
+
return if purged.empty?
|
14
|
+
|
15
|
+
if purged.is_a?(Array) && purged.include?(cached_test_file)
|
16
|
+
@cached_test_file = nil
|
17
|
+
elsif purged.is_a?(String) && purged == cached_test_file
|
18
|
+
@cached_test_file = nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -2,15 +2,19 @@ module Retest
|
|
2
2
|
module Runners
|
3
3
|
class ChangeRunner < Runner
|
4
4
|
def run(changed_file = nil, repository: nil)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
return print_file_not_found unless changed_file
|
6
|
+
|
7
|
+
log("Changed File Selected: #{changed_file}")
|
8
|
+
system_run command.gsub('<changed>', changed_file)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def print_file_not_found
|
14
|
+
log(<<~ERROR)
|
15
|
+
404 - File Not Found
|
16
|
+
Retest could not find a changed file to run.
|
17
|
+
ERROR
|
14
18
|
end
|
15
19
|
end
|
16
20
|
end
|
@@ -1,46 +1,30 @@
|
|
1
|
+
require_relative "cached_test_file"
|
2
|
+
|
1
3
|
module Retest
|
2
4
|
module Runners
|
3
5
|
class TestRunner < Runner
|
4
|
-
|
5
|
-
@cached_test_file
|
6
|
-
end
|
7
|
-
|
8
|
-
def cached_test_file=(value)
|
9
|
-
@cached_test_file = value || @cached_test_file
|
10
|
-
end
|
6
|
+
include CachedTestFile
|
11
7
|
|
12
8
|
def run(changed_file, repository:)
|
13
9
|
self.cached_test_file = repository.find_test(changed_file)
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
log(<<~ERROR)
|
20
|
-
404 - Test File Not Found
|
21
|
-
Retest could not find a matching test file to run.
|
22
|
-
ERROR
|
23
|
-
end
|
11
|
+
return print_file_not_found unless cached_test_file
|
12
|
+
|
13
|
+
log("Test File Selected: #{cached_test_file}")
|
14
|
+
system_run command.gsub('<test>', cached_test_file)
|
24
15
|
end
|
25
16
|
|
26
17
|
def sync(added:, removed:)
|
27
|
-
|
18
|
+
purge_test_file(removed)
|
28
19
|
end
|
29
20
|
|
30
21
|
private
|
31
22
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
elsif purged.is_a? String
|
38
|
-
purge_cache if purged == cached_test_file
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def purge_cache
|
43
|
-
@cached_test_file = nil
|
23
|
+
def print_file_not_found
|
24
|
+
log(<<~ERROR)
|
25
|
+
404 - Test File Not Found
|
26
|
+
Retest could not find a matching test file to run.
|
27
|
+
ERROR
|
44
28
|
end
|
45
29
|
end
|
46
30
|
end
|
@@ -1,18 +1,14 @@
|
|
1
|
+
require_relative "cached_test_file"
|
2
|
+
|
1
3
|
module Retest
|
2
4
|
module Runners
|
3
5
|
class VariableRunner < Runner
|
4
|
-
|
5
|
-
@cached_test_file
|
6
|
-
end
|
7
|
-
|
8
|
-
def cached_test_file=(value)
|
9
|
-
@cached_test_file = value || @cached_test_file
|
10
|
-
end
|
6
|
+
include CachedTestFile
|
11
7
|
|
12
8
|
def run(changed_file, repository:)
|
13
9
|
self.cached_test_file = repository.find_test(changed_file)
|
14
10
|
|
15
|
-
return
|
11
|
+
return print_file_not_found unless cached_test_file
|
16
12
|
|
17
13
|
log(<<~FILES)
|
18
14
|
Files Selected:
|
@@ -27,31 +23,17 @@ module Retest
|
|
27
23
|
end
|
28
24
|
|
29
25
|
def sync(added:, removed:)
|
30
|
-
|
26
|
+
purge_test_file(removed)
|
31
27
|
end
|
32
28
|
|
33
29
|
private
|
34
30
|
|
35
|
-
def
|
31
|
+
def print_file_not_found
|
36
32
|
log(<<~ERROR)
|
37
33
|
404 - Test File Not Found
|
38
34
|
Retest could not find a matching test file to run.
|
39
35
|
ERROR
|
40
36
|
end
|
41
|
-
|
42
|
-
def remove(purged)
|
43
|
-
return if purged.empty?
|
44
|
-
|
45
|
-
if purged.is_a? Array
|
46
|
-
purge_cache if purged.include? cached_test_file
|
47
|
-
elsif purged.is_a? String
|
48
|
-
purge_cache if purged == cached_test_file
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def purge_cache
|
53
|
-
@cached_test_file = nil
|
54
|
-
end
|
55
37
|
end
|
56
38
|
end
|
57
39
|
end
|
data/lib/retest/runners.rb
CHANGED
@@ -8,14 +8,13 @@ module Retest
|
|
8
8
|
module_function
|
9
9
|
|
10
10
|
def runner_for(command)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
elsif
|
16
|
-
|
17
|
-
else
|
18
|
-
Runner
|
11
|
+
for_test = command.include?('<test>')
|
12
|
+
for_change = command.include?('<changed>')
|
13
|
+
|
14
|
+
if for_test && for_change then VariableRunner
|
15
|
+
elsif for_test then TestRunner
|
16
|
+
elsif for_change then ChangeRunner
|
17
|
+
else Runner
|
19
18
|
end.new command
|
20
19
|
end
|
21
20
|
end
|
data/lib/retest/setup.rb
CHANGED
@@ -1,21 +1,13 @@
|
|
1
1
|
module Retest
|
2
2
|
class Setup
|
3
|
-
def self.type
|
4
|
-
new.type
|
5
|
-
end
|
6
|
-
|
7
3
|
def type
|
8
4
|
@type ||= begin
|
9
5
|
return :ruby unless has_lock_file?
|
10
6
|
|
11
|
-
if rspec?
|
12
|
-
|
13
|
-
elsif
|
14
|
-
|
15
|
-
elsif rake?
|
16
|
-
:rake
|
17
|
-
else
|
18
|
-
:ruby
|
7
|
+
if rspec? then :rspec
|
8
|
+
elsif rails? then :rails
|
9
|
+
elsif rake? then :rake
|
10
|
+
else :ruby
|
19
11
|
end
|
20
12
|
end
|
21
13
|
end
|
data/lib/retest/version.rb
CHANGED
@@ -1,33 +1,32 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
system "git -C . rev-parse 2>/dev/null"
|
5
|
-
end
|
1
|
+
module Retest
|
2
|
+
module VersionControl
|
3
|
+
module Git
|
6
4
|
|
7
|
-
|
8
|
-
new.diff_files(branch)
|
9
|
-
end
|
5
|
+
module_function
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
def installed?
|
8
|
+
system "git -C . rev-parse 2>/dev/null"
|
9
|
+
end
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
def name
|
12
|
+
'git'
|
13
|
+
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
def files
|
16
|
+
(untracked_files + tracked_files).sort
|
17
|
+
end
|
22
18
|
|
23
|
-
|
19
|
+
def diff_files(branch)
|
20
|
+
`git diff #{branch} --name-only --diff-filter=ACMRT -z`.split("\x0")
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
def untracked_files
|
24
|
+
`git ls-files --other --exclude-standard -z`.split("\x0")
|
25
|
+
end
|
28
26
|
|
29
|
-
|
30
|
-
|
27
|
+
def tracked_files
|
28
|
+
`git ls-files -z`.split("\x0")
|
29
|
+
end
|
31
30
|
end
|
32
31
|
end
|
33
|
-
end
|
32
|
+
end
|
@@ -1,15 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
true
|
5
|
-
end
|
1
|
+
module Retest
|
2
|
+
module VersionControl
|
3
|
+
module NoVersionControl
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def installed?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
'default'
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
|
15
|
+
def files
|
16
|
+
Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
|
17
|
+
end
|
13
18
|
end
|
14
19
|
end
|
15
|
-
end
|
20
|
+
end
|
@@ -2,12 +2,12 @@ require_relative 'version_control/git'
|
|
2
2
|
require_relative 'version_control/no_version_control'
|
3
3
|
|
4
4
|
module Retest
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
5
|
+
module VersionControl
|
6
|
+
|
7
|
+
module_function
|
9
8
|
|
10
|
-
def
|
11
|
-
|
9
|
+
def files
|
10
|
+
[Git, NoVersionControl].find(&:installed?).files
|
11
|
+
end
|
12
12
|
end
|
13
13
|
end
|
data/lib/retest.rb
CHANGED
@@ -5,13 +5,14 @@ require 'observer'
|
|
5
5
|
require "retest/version"
|
6
6
|
require "retest/runners"
|
7
7
|
require "retest/repository"
|
8
|
-
require "retest/
|
8
|
+
require "retest/matching_options"
|
9
9
|
require "retest/options"
|
10
10
|
require "retest/version_control"
|
11
11
|
require "retest/setup"
|
12
12
|
require "retest/command"
|
13
13
|
require "retest/file_system"
|
14
14
|
require "retest/program"
|
15
|
+
require "retest/prompt"
|
15
16
|
require "retest/sounds"
|
16
17
|
|
17
18
|
module Retest
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Barret
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -60,6 +60,7 @@ executables:
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- ".github/dependabot.yml"
|
63
64
|
- ".github/workflows/ci.yml"
|
64
65
|
- ".gitignore"
|
65
66
|
- Gemfile
|
@@ -87,17 +88,20 @@ files:
|
|
87
88
|
- lib/retest/command/rspec.rb
|
88
89
|
- lib/retest/command/ruby.rb
|
89
90
|
- lib/retest/file_system.rb
|
91
|
+
- lib/retest/matching_options.rb
|
92
|
+
- lib/retest/matching_options/path.rb
|
90
93
|
- lib/retest/options.rb
|
91
94
|
- lib/retest/program.rb
|
95
|
+
- lib/retest/prompt.rb
|
92
96
|
- lib/retest/repository.rb
|
93
97
|
- lib/retest/runners.rb
|
98
|
+
- lib/retest/runners/cached_test_file.rb
|
94
99
|
- lib/retest/runners/change_runner.rb
|
95
100
|
- lib/retest/runners/runner.rb
|
96
101
|
- lib/retest/runners/test_runner.rb
|
97
102
|
- lib/retest/runners/variable_runner.rb
|
98
103
|
- lib/retest/setup.rb
|
99
104
|
- lib/retest/sounds.rb
|
100
|
-
- lib/retest/test_options.rb
|
101
105
|
- lib/retest/version.rb
|
102
106
|
- lib/retest/version_control.rb
|
103
107
|
- lib/retest/version_control/git.rb
|
@@ -124,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
128
|
- !ruby/object:Gem::Version
|
125
129
|
version: '0'
|
126
130
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
131
|
+
rubygems_version: 3.4.6
|
128
132
|
signing_key:
|
129
133
|
specification_version: 4
|
130
134
|
summary: A simple command line tool to watch file change and run its matching spec.
|
data/lib/retest/test_options.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
module Retest
|
4
|
-
class TestOptions
|
5
|
-
def self.for(path, files: [], limit: nil)
|
6
|
-
new(path, files: files, limit: limit).filtered_results
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_reader :path, :files
|
10
|
-
|
11
|
-
def initialize(path, files: [], limit: 5)
|
12
|
-
@path = Path.new(path)
|
13
|
-
@files = files
|
14
|
-
@limit = limit || 5
|
15
|
-
end
|
16
|
-
|
17
|
-
def filtered_results
|
18
|
-
if path.test?
|
19
|
-
[path]
|
20
|
-
elsif namespace_screens.any?
|
21
|
-
namespace_screens
|
22
|
-
else
|
23
|
-
possible_tests
|
24
|
-
end.map(&:to_s)
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def possible_tests
|
30
|
-
@possible_tests ||= filter_by_string_similarities(path, files)
|
31
|
-
.last(@limit)
|
32
|
-
.reverse
|
33
|
-
end
|
34
|
-
|
35
|
-
def filter_by_string_similarities(path, files)
|
36
|
-
files.select { |file| path.possible_test?(file) }
|
37
|
-
.sort_by { |file| [path.similarity_score(file), file] }
|
38
|
-
end
|
39
|
-
|
40
|
-
def namespace_screens
|
41
|
-
@namespace_screens ||= path
|
42
|
-
.reversed_dirnames
|
43
|
-
.each_with_index
|
44
|
-
.with_object(possible_tests.map { |file| Path.new(file) }) do |(reference, index), result|
|
45
|
-
unless [1, 0].include? result.count
|
46
|
-
result.keep_if { |path| path.reversed_dirnames[index] == reference }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class Path
|
52
|
-
extend Forwardable
|
53
|
-
|
54
|
-
def_delegators :pathname, :to_s, :basename, :extname, :dirname
|
55
|
-
|
56
|
-
attr_reader :pathname
|
57
|
-
def initialize(path)
|
58
|
-
@pathname = Pathname(path)
|
59
|
-
end
|
60
|
-
|
61
|
-
def reversed_dirnames
|
62
|
-
@reversed_dirnames ||= dirname.each_filename.to_a.reverse
|
63
|
-
end
|
64
|
-
|
65
|
-
def test?
|
66
|
-
test_regexs.any? { |regex| regex =~ to_s }
|
67
|
-
end
|
68
|
-
|
69
|
-
def possible_test?(file)
|
70
|
-
possible_test_regexs.any? { |regex| regex =~ file }
|
71
|
-
end
|
72
|
-
|
73
|
-
def similarity_score(file)
|
74
|
-
String::Similarity.levenshtein(to_s, file)
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def test_regexs
|
80
|
-
[
|
81
|
-
Regexp.new("^(.*\/)?.*_(?:spec|test)#{extname}$"),
|
82
|
-
Regexp.new("^(.*\/)?(?:spec|test)_.*#{extname}$"),
|
83
|
-
]
|
84
|
-
end
|
85
|
-
|
86
|
-
def possible_test_regexs
|
87
|
-
[
|
88
|
-
Regexp.new("^(.*\/)?.*#{filename}_(?:spec|test)#{extname}$"),
|
89
|
-
Regexp.new("^(.*\/)?.*(?:spec|test)_#{filename}#{extname}$"),
|
90
|
-
]
|
91
|
-
end
|
92
|
-
|
93
|
-
def filename
|
94
|
-
basename(extname)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|