retest 0.7.0 → 0.8.1
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/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/lib/retest.rb +20 -14
- data/lib/retest/repository.rb +22 -6
- data/lib/retest/runner.rb +32 -8
- data/lib/retest/version.rb +1 -1
- data/lib/retest/version_control.rb +48 -0
- metadata +3 -3
- data/lib/retest/listen_options.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba9ca783c69da878dff89276c488918b06d8436aa2eaeabeaeb292faa27b4ba3
|
4
|
+
data.tar.gz: c4bc3fd1a10673be4dcd32fc51f6d332a08a2e73ba44b3253cc9b857bcc19091
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ae36ae04af283b34823305cc7f15174e65002c01f301262eb573b6dff9ba5a492db3be1891ddcdcb2840a5a404e0f571548853bb4a0215d817fb99d075df2b0
|
7
|
+
data.tar.gz: 911e035acbde5d9d88dd23ad98ab136e1dcbf3adadf6db9a78e60665a304aacc5feeb27903fd87ff2cfb65e490893956a8e70b63c1f454635fbf607dcb6e76de
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
retest (0.
|
4
|
+
retest (0.8.1)
|
5
5
|
listen (~> 3.2)
|
6
6
|
string-similarity (~> 2.1)
|
7
7
|
tty-option (~> 0.1)
|
@@ -62,7 +62,7 @@ GEM
|
|
62
62
|
ffi (1.13.1)
|
63
63
|
i18n (1.8.5)
|
64
64
|
concurrent-ruby (~> 1.0)
|
65
|
-
listen (3.
|
65
|
+
listen (3.4.1)
|
66
66
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
67
67
|
rb-inotify (~> 0.9, >= 0.9.10)
|
68
68
|
middleware (0.1.0)
|
data/README.md
CHANGED
@@ -22,11 +22,11 @@ Install it on your machine with:
|
|
22
22
|
|
23
23
|
Launch `retest` in your terminal after accessing your ruby project folder.
|
24
24
|
|
25
|
-
Pass the test command surrounded by quotes. Use the placeholder `<test>` in your command to
|
25
|
+
Pass the test command surrounded by quotes. Use the placeholder `<test>` in your command to tell `retest` where to put the path of the test file in your command. Example: `retest 'bundle exec rspec <test>'`. When a file is changed `retest` will find its matching test and run it.
|
26
26
|
|
27
27
|
Learn more by running `retest -h`
|
28
28
|
|
29
|
-
```
|
29
|
+
```
|
30
30
|
Usage: retest [OPTIONS] [COMMAND]
|
31
31
|
|
32
32
|
Watch a file change and run it matching spec.
|
data/lib/retest.rb
CHANGED
@@ -5,30 +5,36 @@ require "retest/version"
|
|
5
5
|
require "retest/runner"
|
6
6
|
require "retest/repository"
|
7
7
|
require "retest/test_options"
|
8
|
-
require "retest/listen_options"
|
9
8
|
require "retest/options"
|
9
|
+
require "retest/version_control"
|
10
10
|
|
11
11
|
module Retest
|
12
12
|
class Error < StandardError; end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
class << self
|
15
|
+
def start(command)
|
16
|
+
puts "Launching Retest..."
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
build(
|
19
|
+
runner: Runner.for(command),
|
20
|
+
repository: Repository.new(files: VersionControl.files)
|
21
|
+
).start
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
puts "Ready to refactor! You can make file changes now"
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
def build(runner:, repository:)
|
27
|
+
Listen.to('.', only: /\.rb$/, relative: true) do |modified, added, removed|
|
28
|
+
begin
|
29
|
+
repository.add(added)
|
30
|
+
repository.remove(removed)
|
31
|
+
runner.remove(removed)
|
27
32
|
system('clear 2>/dev/null') || system('cls 2>/dev/null')
|
28
|
-
|
33
|
+
|
34
|
+
runner.run repository.find_test (modified + added).first
|
35
|
+
rescue => e
|
36
|
+
puts "Something went wrong: #{e.message}"
|
29
37
|
end
|
30
|
-
rescue => e
|
31
|
-
puts "Something went wrong: #{e.message}"
|
32
38
|
end
|
33
39
|
end
|
34
40
|
end
|
data/lib/retest/repository.rb
CHANGED
@@ -2,17 +2,37 @@ module Retest
|
|
2
2
|
class Repository
|
3
3
|
attr_accessor :files, :cache, :input_stream, :output_stream
|
4
4
|
|
5
|
-
def initialize(files:
|
5
|
+
def initialize(files: [], cache: {}, input_stream: nil, output_stream: nil)
|
6
6
|
@cache = cache
|
7
|
-
@files = files
|
7
|
+
@files = files
|
8
8
|
@input_stream = input_stream || STDIN
|
9
9
|
@output_stream = output_stream|| STDOUT
|
10
10
|
end
|
11
11
|
|
12
12
|
def find_test(path)
|
13
|
+
return unless path
|
14
|
+
return if path.empty?
|
15
|
+
|
13
16
|
cache[path] ||= select_from TestOptions.for(path, files: files)
|
14
17
|
end
|
15
18
|
|
19
|
+
def add(added)
|
20
|
+
return if added && added.empty?
|
21
|
+
|
22
|
+
files.push(*added)
|
23
|
+
files.sort!
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove(removed)
|
27
|
+
return if removed && removed.empty?
|
28
|
+
|
29
|
+
if removed.is_a?(Array)
|
30
|
+
removed.each { |file| files.delete(file) }
|
31
|
+
else
|
32
|
+
files.delete(removed)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
16
36
|
private
|
17
37
|
|
18
38
|
def select_from(tests)
|
@@ -25,10 +45,6 @@ module Retest
|
|
25
45
|
end
|
26
46
|
end
|
27
47
|
|
28
|
-
def default_files
|
29
|
-
@default_files ||= Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
|
30
|
-
end
|
31
|
-
|
32
48
|
def ask_question(tests)
|
33
49
|
output_stream.puts <<~QUESTION
|
34
50
|
We found few tests matching:
|
data/lib/retest/runner.rb
CHANGED
@@ -9,19 +9,29 @@ module Retest
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class VariableRunner
|
12
|
-
attr_reader :command
|
12
|
+
attr_reader :command
|
13
13
|
|
14
|
-
def initialize(command
|
15
|
-
@repository = repository || Repository.new
|
14
|
+
def initialize(command)
|
16
15
|
@command = command
|
16
|
+
@cached_test_file = nil
|
17
17
|
end
|
18
18
|
|
19
19
|
def ==(obj)
|
20
20
|
command == obj.command
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
|
23
|
+
def cached_test_file
|
24
|
+
@cached_test_file
|
25
|
+
end
|
26
|
+
|
27
|
+
def cached_test_file=(value)
|
28
|
+
@cached_test_file = value || @cached_test_file
|
29
|
+
end
|
30
|
+
|
31
|
+
def run(test_file = nil)
|
32
|
+
self.cached_test_file = test_file
|
33
|
+
|
34
|
+
if cached_test_file
|
25
35
|
puts "Test File Selected: #{cached_test_file}"
|
26
36
|
system command.gsub('<test>', cached_test_file)
|
27
37
|
else
|
@@ -32,15 +42,29 @@ module Retest
|
|
32
42
|
end
|
33
43
|
end
|
34
44
|
|
35
|
-
def
|
36
|
-
|
45
|
+
def remove(purged)
|
46
|
+
return if purged.empty?
|
47
|
+
|
48
|
+
if purged.is_a? Array
|
49
|
+
purge_cache if purged.include? cached_test_file
|
50
|
+
elsif purged.is_a? String
|
51
|
+
purge_cache if purged == cached_test_file
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def purge_cache
|
58
|
+
@cached_test_file = nil
|
37
59
|
end
|
38
60
|
end
|
39
61
|
|
40
62
|
HardcodedRunner = Struct.new(:command) do
|
41
|
-
def run(_)
|
63
|
+
def run(_ = nil)
|
42
64
|
system command
|
43
65
|
end
|
66
|
+
|
67
|
+
def remove(_ = nil); end
|
44
68
|
end
|
45
69
|
end
|
46
70
|
end
|
data/lib/retest/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
module Retest
|
2
|
+
class VersionControl
|
3
|
+
def self.files
|
4
|
+
[Git, NoVersionControl].select(&:installed?).first.new.files
|
5
|
+
end
|
6
|
+
|
7
|
+
def name; end
|
8
|
+
alias :to_s :name
|
9
|
+
|
10
|
+
class NoVersionControl
|
11
|
+
def self.installed?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def name
|
16
|
+
'default'
|
17
|
+
end
|
18
|
+
|
19
|
+
def files
|
20
|
+
Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Git
|
25
|
+
def self.installed?
|
26
|
+
system "git -C . rev-parse 2>/dev/null"
|
27
|
+
end
|
28
|
+
|
29
|
+
def name
|
30
|
+
'git'
|
31
|
+
end
|
32
|
+
|
33
|
+
def files
|
34
|
+
(untracked_files + tracked_files).sort
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def untracked_files
|
40
|
+
`git ls-files --other --exclude-standard -z`.split("\x0")
|
41
|
+
end
|
42
|
+
|
43
|
+
def tracked_files
|
44
|
+
`git ls-files -z`.split("\x0")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
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.8.1
|
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: 2021-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -73,12 +73,12 @@ files:
|
|
73
73
|
- bin/setup
|
74
74
|
- exe/retest
|
75
75
|
- lib/retest.rb
|
76
|
-
- lib/retest/listen_options.rb
|
77
76
|
- lib/retest/options.rb
|
78
77
|
- lib/retest/repository.rb
|
79
78
|
- lib/retest/runner.rb
|
80
79
|
- lib/retest/test_options.rb
|
81
80
|
- lib/retest/version.rb
|
81
|
+
- lib/retest/version_control.rb
|
82
82
|
- retest.gemspec
|
83
83
|
homepage: https://github.com/AlexB52/retest
|
84
84
|
licenses:
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Retest
|
2
|
-
class ListenOptions
|
3
|
-
IGNORE_REGEX = /node_modules|tmp|\.sqlite|\.byebug_history/
|
4
|
-
|
5
|
-
class << self
|
6
|
-
def to_h(tool = GitTool.new)
|
7
|
-
return {ignore: IGNORE_REGEX, relative: true} unless tool.installed?
|
8
|
-
|
9
|
-
{only: regex_for(tool.files), relative: true}
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def regex_for(files)
|
15
|
-
Regexp.new files.split("\n").join('|')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class GitTool
|
21
|
-
attr_reader :name
|
22
|
-
alias :to_s :name
|
23
|
-
|
24
|
-
def initialize
|
25
|
-
@name = 'git'
|
26
|
-
end
|
27
|
-
|
28
|
-
def installed?
|
29
|
-
system "git -C . rev-parse 2>/dev/null"
|
30
|
-
end
|
31
|
-
|
32
|
-
def files
|
33
|
-
`git ls-files`
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|