retest 0.4.0 → 0.4.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 +1 -1
- data/README.md +19 -9
- data/lib/retest.rb +1 -0
- data/lib/retest/repository.rb +1 -20
- data/lib/retest/test_options.rb +87 -0
- data/lib/retest/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e6c73bd5706c122dee68acdb92dfca665a74492305529fa99c4d80103c6d168
|
4
|
+
data.tar.gz: 19316bc71ded84cd88a5153cd823d3349ecab93b22c7cf67d4ce2727eaf96f24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcfda7049983085a516331b968a45138079afe95816000eec33f36254737b751557646363b639e73bf1dd7f9078db594082544a0ded74a3817b66245b732846b
|
7
|
+
data.tar.gz: 574eccec94ab742f2fa83123032bfe8214b46a135a86a5d4b56b4186809c90c760c35d378828ee227c1bcb76d163bc8aa0dc788622e58e3d90cb162a686608f8
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Retest
|
2
2
|
|
3
|
-
Retest is a small command
|
3
|
+
Retest is a small command-line tool to help you refactor code by watching a file change and running its matching spec. Designed to be dev-centric and project independent, it can be used on the fly. No Gemfile updates, no commits to a repo or configuration files required to start refactoring. Works with every Ruby projects (at least that is the end goal)
|
4
4
|
|
5
5
|
## Why?
|
6
6
|
It is advised to be one `cmd + z` away from green tests when refactoring. This means running tests after every line change. Let Retest rerun your tests after every file change you make.
|
7
7
|
|
8
|
-
Retest gem is meant to be simple and follow testing conventions encountered in Ruby projects.
|
8
|
+
Retest gem is meant to be simple and follow testing conventions encountered in Ruby projects. Give it a go you can uninstall it easily. If you think the matching pattern could be improved please raise an issue.
|
9
9
|
|
10
|
-
For
|
10
|
+
For fully fledged solutions, some cli tools already exists: [autotest](https://github.com/grosser/autotest), [guard](https://github.com/guard/guard), [zentest](https://github.com/seattlerb/zentest)
|
11
11
|
|
12
12
|

|
13
13
|
|
@@ -21,7 +21,7 @@ Install it on your machine with:
|
|
21
21
|
|
22
22
|
Launch `retest` in your terminal after accessing your ruby project folder.
|
23
23
|
|
24
|
-
Pass the test command surrounded
|
24
|
+
Pass the test command surrounded by quotes. Use the placeholder `<test>` in your command to let `retest` find the matching test and replace the placeholder with the path of the test file.
|
25
25
|
|
26
26
|
```bash
|
27
27
|
# Let retest find the test file and replace the placeholder with the path of the test file
|
@@ -37,14 +37,16 @@ $ retest 'rails test'
|
|
37
37
|
$ retest 'rspec'
|
38
38
|
$ retest 'docker-compose exec web bundle exec rails test'
|
39
39
|
|
40
|
-
# Hardcode a test file to run
|
40
|
+
# Hardcode a test file to run independently from the file you change
|
41
41
|
$ retest 'ruby all_tests.rb'
|
42
42
|
```
|
43
43
|
|
44
44
|
The gem works as follows:
|
45
45
|
|
46
|
-
* When
|
47
|
-
* When a test file is
|
46
|
+
* When a file is changed, retest will run its matching file test.
|
47
|
+
* When a test file is changed, retest will run the file test.
|
48
|
+
* When multiple matching test files are found, retest asks you to confirm the file and save the answer.
|
49
|
+
* When a test file is not found, retest runs the last run command or throw a 404.
|
48
50
|
* Works with RSpec, MiniTest, Rake commands & bash commands (not aliases).
|
49
51
|
* Works when installed and run in a Docker container.
|
50
52
|
|
@@ -64,9 +66,17 @@ $ retest 'bundle exec rails test <test>'
|
|
64
66
|
## Roadmap
|
65
67
|
|
66
68
|
- [x] MVP
|
67
|
-
- [x] When multiple test files are found, ask
|
69
|
+
- [x] When multiple test files are found, ask which file to run and save the answer.
|
68
70
|
- [x] When a test file is not found run the last command again.
|
69
71
|
- [x] Run within Docker.
|
72
|
+
- [ ] Handle main Ruby setups
|
73
|
+
- [x] Bundler Gem
|
74
|
+
- [x] Rails
|
75
|
+
- [x] Ad-hoc scripts
|
76
|
+
- [ ] Hanami
|
77
|
+
- [ ] Sinatra
|
78
|
+
- [ ] Cuba? Padrino?
|
79
|
+
- [ ] Handle other languages: Elixir, Node, Python, PHP
|
70
80
|
- [ ] Aliases from oh-my-zsh and bash profiles?
|
71
81
|
|
72
82
|
## Development
|
@@ -82,4 +92,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/alexb5
|
|
82
92
|
|
83
93
|
## License
|
84
94
|
|
85
|
-
The gem is available as open
|
95
|
+
The gem is available as open-source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/retest.rb
CHANGED
data/lib/retest/repository.rb
CHANGED
@@ -10,7 +10,7 @@ module Retest
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def find_test(path)
|
13
|
-
cache[path] ||= select_from
|
13
|
+
cache[path] ||= select_from TestOptions.for(path, files: files)
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -25,29 +25,10 @@ module Retest
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def test_options(path)
|
29
|
-
return [path] if is_test_file?(path)
|
30
|
-
|
31
|
-
files.select { |file| regex(path) =~ file }
|
32
|
-
.sort_by { |file| String::Similarity.levenshtein(path, file) }
|
33
|
-
.last(5)
|
34
|
-
.reverse
|
35
|
-
end
|
36
|
-
|
37
28
|
def default_files
|
38
29
|
@default_files ||= Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
|
39
30
|
end
|
40
31
|
|
41
|
-
def is_test_file?(path)
|
42
|
-
Regexp.new(".*(?:spec|test)#{File.extname(path)}") =~ path
|
43
|
-
end
|
44
|
-
|
45
|
-
def regex(path)
|
46
|
-
extname = File.extname(path)
|
47
|
-
basename = File.basename(path, extname)
|
48
|
-
Regexp.new(".*#{basename}_(?:spec|test)#{extname}")
|
49
|
-
end
|
50
|
-
|
51
32
|
def ask_question(tests)
|
52
33
|
output_stream.puts <<~QUESTION
|
53
34
|
We found few tests matching:
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Retest
|
4
|
+
class TestOptions
|
5
|
+
def self.for(path, files: [])
|
6
|
+
new(path, files: files).filtered_results
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :path, :files
|
10
|
+
|
11
|
+
def initialize(path, files: [])
|
12
|
+
@path = Path.new(path)
|
13
|
+
@files = files
|
14
|
+
end
|
15
|
+
|
16
|
+
def filtered_results
|
17
|
+
if path.test?
|
18
|
+
[path]
|
19
|
+
elsif namespace_screens.any?
|
20
|
+
namespace_screens
|
21
|
+
else
|
22
|
+
possible_tests
|
23
|
+
end.map(&:to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def possible_tests
|
29
|
+
@possible_tests ||= filter_by_string_similarities(path, files)
|
30
|
+
.last(5)
|
31
|
+
.reverse
|
32
|
+
end
|
33
|
+
|
34
|
+
def filter_by_string_similarities(path, files)
|
35
|
+
files.select { |file| path.possible_test?(file) }
|
36
|
+
.sort_by { |file| [path.similarity_score(file), file] }
|
37
|
+
end
|
38
|
+
|
39
|
+
def namespace_screens
|
40
|
+
@namespace_screens ||= path
|
41
|
+
.reversed_dirnames
|
42
|
+
.each_with_index
|
43
|
+
.with_object(possible_tests.map { |file| Path.new(file) }) do |(reference, index), result|
|
44
|
+
unless [1, 0].include? result.count
|
45
|
+
result.keep_if { |path| path.reversed_dirnames[index] == reference }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Path
|
51
|
+
extend Forwardable
|
52
|
+
|
53
|
+
def_delegators :pathname, :to_s, :basename, :extname, :dirname
|
54
|
+
|
55
|
+
attr_reader :pathname
|
56
|
+
def initialize(path)
|
57
|
+
@pathname = Pathname(path)
|
58
|
+
end
|
59
|
+
|
60
|
+
def reversed_dirnames
|
61
|
+
@reversed_dirnames ||= dirname.each_filename.to_a.reverse
|
62
|
+
end
|
63
|
+
|
64
|
+
def test?
|
65
|
+
test_regex =~ to_s
|
66
|
+
end
|
67
|
+
|
68
|
+
def possible_test?(file)
|
69
|
+
possible_test_regex =~ file
|
70
|
+
end
|
71
|
+
|
72
|
+
def similarity_score(file)
|
73
|
+
String::Similarity.levenshtein(to_s, file)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def test_regex
|
79
|
+
Regexp.new(".*(?:spec|test)#{extname}")
|
80
|
+
end
|
81
|
+
|
82
|
+
def possible_test_regex
|
83
|
+
Regexp.new(".*#{basename(extname)}_(?:spec|test)#{extname}")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
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.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Barret
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description:
|
70
70
|
email:
|
71
71
|
- alex@abletech.nz
|
72
72
|
executables:
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/retest.rb
|
89
89
|
- lib/retest/command.rb
|
90
90
|
- lib/retest/repository.rb
|
91
|
+
- lib/retest/test_options.rb
|
91
92
|
- lib/retest/version.rb
|
92
93
|
- retest.gemspec
|
93
94
|
homepage: https://github.com/AlexB52/retest
|
@@ -96,7 +97,7 @@ licenses:
|
|
96
97
|
metadata:
|
97
98
|
homepage_uri: https://github.com/AlexB52/retest
|
98
99
|
source_code_uri: https://github.com/AlexB52/retest
|
99
|
-
post_install_message:
|
100
|
+
post_install_message:
|
100
101
|
rdoc_options: []
|
101
102
|
require_paths:
|
102
103
|
- lib
|
@@ -111,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
112
|
- !ruby/object:Gem::Version
|
112
113
|
version: '0'
|
113
114
|
requirements: []
|
114
|
-
rubygems_version: 3.
|
115
|
-
signing_key:
|
115
|
+
rubygems_version: 3.1.2
|
116
|
+
signing_key:
|
116
117
|
specification_version: 4
|
117
118
|
summary: A simple command line tool to watch file change and run its matching spec.
|
118
119
|
test_files: []
|