retest 0.2.0 → 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/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/exe/retest +6 -2
- data/lib/retest.rb +1 -14
- data/lib/retest/command.rb +9 -23
- data/lib/retest/repository.rb +62 -0
- data/lib/retest/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b785b5164606d944a470b42899d1a7c6d4fa77f3d0d3a3850e4adc1e81d61db6
|
4
|
+
data.tar.gz: d722fe7580cc3f24587322ee9d0dcc47efc4bded149d59461eb7408398f78b73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e7ebd3a5dd1eb6d1a09bcae184d749ac59b49cd928f845c3fcbf5d47e067e9623388167ffad4e7dc186e0aec22178444409e0da3978083107e57e7b7abcd453
|
7
|
+
data.tar.gz: f0cd1516119abcc62c4dfb73d317097dc5f57d3ed741bc7ff44455c0518646c6c4ffcf44686e6ee939053a7bd435acd72fc8d4f6653123fa2816634e7abbb5a5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Pass the test command surrounded with quotes. Use the placeholder `<test>` in yo
|
|
25
25
|
|
26
26
|
```bash
|
27
27
|
# Let retest find the test file and replace the placeholder with the path of the test file
|
28
|
-
$ retest 'bundle exec rake test
|
28
|
+
$ retest 'bundle exec rake test TEST=<test>'
|
29
29
|
$ retest 'rails test <test>'
|
30
30
|
$ retest 'rspec <test>'
|
31
31
|
$ retest 'ruby <test>'
|
@@ -46,7 +46,7 @@ $ retest 'ruby all_tests.rb'
|
|
46
46
|
Installing & launching the gem in the Docker container seem to work
|
47
47
|
```bash
|
48
48
|
$ docker-compose run web bash
|
49
|
-
$ gem install
|
49
|
+
$ gem install retest
|
50
50
|
$ retest 'bundle exec rails test <test>'
|
51
51
|
```
|
52
52
|
|
data/exe/retest
CHANGED
@@ -8,8 +8,12 @@ puts "Launching Retest..."
|
|
8
8
|
command = Retest::Command.for(ARGV.join)
|
9
9
|
|
10
10
|
listener = Listen.to('.', ignore: /node_modules|tmp/, relative: true) do |modified, added, removed|
|
11
|
-
|
12
|
-
|
11
|
+
if modified.any?
|
12
|
+
system("clear") || system("cls")
|
13
|
+
command.run(modified.first.strip)
|
14
|
+
end
|
15
|
+
rescue => e
|
16
|
+
puts "Something went wrong: #{e.message}"
|
13
17
|
end
|
14
18
|
|
15
19
|
listener.start # not blocking
|
data/lib/retest.rb
CHANGED
@@ -1,21 +1,8 @@
|
|
1
1
|
require "retest/version"
|
2
2
|
require "retest/command"
|
3
|
+
require "retest/repository"
|
3
4
|
require 'string/similarity'
|
4
5
|
|
5
6
|
module Retest
|
6
7
|
class Error < StandardError; end
|
7
|
-
|
8
|
-
def find_test(path, files: nil)
|
9
|
-
files
|
10
|
-
.select { |file| regex(path) =~ file }
|
11
|
-
.max_by { |file| String::Similarity.cosine(path, file) }
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def regex(path)
|
17
|
-
extname = File.extname(path)
|
18
|
-
basename = File.basename(path, extname)
|
19
|
-
Regexp.new(".*#{basename}_(?:spec|test)#{extname}")
|
20
|
-
end
|
21
8
|
end
|
data/lib/retest/command.rb
CHANGED
@@ -11,12 +11,11 @@ module Retest
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class VariableCommand
|
14
|
-
attr_reader :command, :
|
14
|
+
attr_reader :command, :repository, :cached_test_file
|
15
15
|
|
16
|
-
def initialize(command,
|
16
|
+
def initialize(command, repository: nil)
|
17
|
+
@repository = repository || Repository.new
|
17
18
|
@command = command
|
18
|
-
@cache = cache
|
19
|
-
@files = files || default_files
|
20
19
|
end
|
21
20
|
|
22
21
|
def ==(obj)
|
@@ -24,34 +23,21 @@ module Retest
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def run(file_changed)
|
27
|
-
if
|
28
|
-
|
26
|
+
if @cached_test_file = test_file(file_changed)
|
27
|
+
puts "Test File Selected: #{cached_test_file}"
|
28
|
+
system command.gsub('<test>', cached_test_file)
|
29
29
|
else
|
30
30
|
puts 'Could not find a file test matching'
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
def find_test(path)
|
37
|
-
cache[path] ||= files
|
38
|
-
.select { |file| regex(path) =~ file }
|
39
|
-
.max_by { |file| String::Similarity.cosine(path, file) }
|
40
|
-
end
|
41
|
-
|
42
|
-
def regex(path)
|
43
|
-
extname = File.extname(path)
|
44
|
-
basename = File.basename(path, extname)
|
45
|
-
Regexp.new(".*#{basename}_(?:spec|test)#{extname}")
|
46
|
-
end
|
47
|
-
|
48
|
-
def default_files
|
49
|
-
@default_files ||= Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
|
34
|
+
def test_file(file_changed)
|
35
|
+
repository.find_test(file_changed) || cached_test_file
|
50
36
|
end
|
51
37
|
end
|
52
38
|
|
53
39
|
HardcodedCommand = Struct.new(:command) do
|
54
|
-
def run(
|
40
|
+
def run(_)
|
55
41
|
system command
|
56
42
|
end
|
57
43
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Retest
|
2
|
+
class Repository
|
3
|
+
attr_accessor :files, :cache, :input_stream, :output_stream
|
4
|
+
|
5
|
+
def initialize(files: nil, cache: {}, input_stream: nil, output_stream: nil)
|
6
|
+
@cache = cache
|
7
|
+
@files = files || default_files
|
8
|
+
@input_stream = input_stream || STDIN
|
9
|
+
@output_stream = output_stream|| STDOUT
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_test(path)
|
13
|
+
cache[path] ||= select_test(path)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def select_test(path)
|
19
|
+
tests = files.select { |file| regex(path) =~ file }
|
20
|
+
.sort_by { |file| String::Similarity.levenshtein(path, file) }
|
21
|
+
.reverse
|
22
|
+
|
23
|
+
case tests.count
|
24
|
+
when 0, 1
|
25
|
+
tests.first
|
26
|
+
else
|
27
|
+
ask_question tests.first(5)
|
28
|
+
tests[get_input]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def default_files
|
33
|
+
@default_files ||= Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
|
34
|
+
end
|
35
|
+
|
36
|
+
def regex(path)
|
37
|
+
extname = File.extname(path)
|
38
|
+
basename = File.basename(path, extname)
|
39
|
+
Regexp.new(".*#{basename}_(?:spec|test)#{extname}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def ask_question(tests)
|
43
|
+
output_stream.puts <<~QUESTION
|
44
|
+
We found few tests matching:
|
45
|
+
#{list_options(tests)}
|
46
|
+
|
47
|
+
Which file do you want to use?
|
48
|
+
Enter the file number now:
|
49
|
+
QUESTION
|
50
|
+
end
|
51
|
+
|
52
|
+
def list_options(tests)
|
53
|
+
tests.map.with_index do |file, index|
|
54
|
+
"[#{index}] - #{file}"
|
55
|
+
end.join("\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_input
|
59
|
+
input_stream.gets.chomp.to_i
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/retest/version.rb
CHANGED
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: 0.
|
4
|
+
version: 0.3.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: 2020-09-
|
11
|
+
date: 2020-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- exe/retest
|
87
87
|
- lib/retest.rb
|
88
88
|
- lib/retest/command.rb
|
89
|
+
- lib/retest/repository.rb
|
89
90
|
- lib/retest/version.rb
|
90
91
|
- retest.gemspec
|
91
92
|
homepage: https://github.com/AlexB52/retest
|