retest 0.3.1 → 0.6.0.pre2
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/workflows/ci.yml +35 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +4 -4
- data/README.md +26 -10
- data/exe/retest +6 -12
- data/lib/retest.rb +18 -1
- data/lib/retest/command.rb +4 -1
- data/lib/retest/listen_options.rb +36 -0
- data/lib/retest/repository.rb +1 -14
- data/lib/retest/test_options.rb +87 -0
- data/lib/retest/version.rb +1 -1
- data/retest.gemspec +0 -2
- metadata +13 -38
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d55eddf3b57a090756f298ddef8ee56e5fb1fda5cf418eeef09e439ef17735a4
|
4
|
+
data.tar.gz: 0a24792e30b8954c09614460d0bb5a94ff1ae796da17fe66da1a499bfac7422c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 335d9c2089ee743e55d3e2f16494cdb566314f072cfea689c03f2c08f7e8df08d9911eebce490fa621aaa654ebbcac61e9972d69eee24e9d660bb6093a17ef82
|
7
|
+
data.tar.gz: 433796d6539aca269288e5d7923207fbc96f3ab70fdea5ac8464f8f179973c5cf106786cb507c5bc4e6dabba242b201b18197911dc8899a11d3c038dd64f5cf1
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby:
|
22
|
+
- 2.5
|
23
|
+
- 2.6
|
24
|
+
- 2.7
|
25
|
+
name: Ruby ${{ matrix.ruby }} test
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- name: Set up Ruby
|
29
|
+
uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
32
|
+
bundler-cache: true
|
33
|
+
- run: bundle install
|
34
|
+
- run: bundle exec rake
|
35
|
+
- run: CUCUMBER_PUBLISH_QUIET=true bundle exec cucumber
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.6
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
retest (0.
|
4
|
+
retest (0.6.0.pre2)
|
5
5
|
listen (~> 3.2)
|
6
6
|
string-similarity (~> 2.1)
|
7
7
|
|
@@ -61,7 +61,7 @@ GEM
|
|
61
61
|
ffi (1.13.1)
|
62
62
|
i18n (1.8.5)
|
63
63
|
concurrent-ruby (~> 1.0)
|
64
|
-
listen (3.
|
64
|
+
listen (3.3.1)
|
65
65
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
66
66
|
rb-inotify (~> 0.9, >= 0.9.10)
|
67
67
|
middleware (0.1.0)
|
@@ -93,9 +93,9 @@ PLATFORMS
|
|
93
93
|
ruby
|
94
94
|
|
95
95
|
DEPENDENCIES
|
96
|
-
aruba
|
96
|
+
aruba (~> 1.0)
|
97
97
|
byebug
|
98
|
-
cucumber
|
98
|
+
cucumber (~> 5.1)
|
99
99
|
minitest (~> 5.0)
|
100
100
|
rake (~> 12.0)
|
101
101
|
retest!
|
data/README.md
CHANGED
@@ -1,13 +1,15 @@
|
|
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
|
+
|
12
|
+

|
11
13
|
|
12
14
|
## Installation
|
13
15
|
|
@@ -19,7 +21,7 @@ Install it on your machine with:
|
|
19
21
|
|
20
22
|
Launch `retest` in your terminal after accessing your ruby project folder.
|
21
23
|
|
22
|
-
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.
|
23
25
|
|
24
26
|
```bash
|
25
27
|
# Let retest find the test file and replace the placeholder with the path of the test file
|
@@ -35,14 +37,16 @@ $ retest 'rails test'
|
|
35
37
|
$ retest 'rspec'
|
36
38
|
$ retest 'docker-compose exec web bundle exec rails test'
|
37
39
|
|
38
|
-
# Hardcode a test file to run
|
40
|
+
# Hardcode a test file to run independently from the file you change
|
39
41
|
$ retest 'ruby all_tests.rb'
|
40
42
|
```
|
41
43
|
|
42
44
|
The gem works as follows:
|
43
45
|
|
44
|
-
* When
|
45
|
-
* 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.
|
46
50
|
* Works with RSpec, MiniTest, Rake commands & bash commands (not aliases).
|
47
51
|
* Works when installed and run in a Docker container.
|
48
52
|
|
@@ -59,12 +63,24 @@ $ retest 'bundle exec rails test <test>'
|
|
59
63
|
* If an error comes in try using `bundle exec` like so: `$ retest 'bundle exec rake test <test>'`
|
60
64
|
* Aliases saved on ~/.bashrc or ~/.zshrc cannot be run that way with the `retest` command
|
61
65
|
|
66
|
+
## Ruby Support
|
67
|
+
|
68
|
+
Retest supports ruby 2.5 and above.
|
69
|
+
|
62
70
|
## Roadmap
|
63
71
|
|
64
72
|
- [x] MVP
|
65
|
-
- [x] When multiple test files are found, ask
|
73
|
+
- [x] When multiple test files are found, ask which file to run and save the answer.
|
66
74
|
- [x] When a test file is not found run the last command again.
|
67
|
-
- [x] Run
|
75
|
+
- [x] Run within Docker.
|
76
|
+
- [ ] Handle main Ruby setups
|
77
|
+
- [x] Bundler Gem
|
78
|
+
- [x] Rails
|
79
|
+
- [x] Ad-hoc scripts
|
80
|
+
- [x] Hanami
|
81
|
+
- [ ] Sinatra
|
82
|
+
- [ ] Cuba? Padrino?
|
83
|
+
- [ ] Handle other languages: Elixir, Node, Python, PHP
|
68
84
|
- [ ] Aliases from oh-my-zsh and bash profiles?
|
69
85
|
|
70
86
|
## Development
|
@@ -80,4 +96,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/alexb5
|
|
80
96
|
|
81
97
|
## License
|
82
98
|
|
83
|
-
The gem is available as open
|
99
|
+
The gem is available as open-source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/exe/retest
CHANGED
@@ -1,21 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'retest'
|
4
|
-
require 'listen'
|
5
4
|
|
6
|
-
|
5
|
+
$stdout.sync = true
|
7
6
|
|
8
|
-
|
7
|
+
puts "Launching Retest..."
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
command.run(modified.first.strip)
|
14
|
-
end
|
15
|
-
rescue => e
|
16
|
-
puts "Something went wrong: #{e.message}"
|
17
|
-
end
|
9
|
+
Retest
|
10
|
+
.build(command: Retest::Command.for(ARGV.join))
|
11
|
+
.start # not blocking
|
18
12
|
|
19
|
-
listener.start # not blocking
|
20
13
|
puts "Ready to refactor! You can make file changes now"
|
14
|
+
|
21
15
|
sleep
|
data/lib/retest.rb
CHANGED
@@ -1,8 +1,25 @@
|
|
1
|
+
require 'listen'
|
2
|
+
require 'string/similarity'
|
3
|
+
|
1
4
|
require "retest/version"
|
2
5
|
require "retest/command"
|
3
6
|
require "retest/repository"
|
4
|
-
require
|
7
|
+
require "retest/test_options"
|
8
|
+
require "retest/listen_options"
|
5
9
|
|
6
10
|
module Retest
|
7
11
|
class Error < StandardError; end
|
12
|
+
|
13
|
+
def self.build(command:)
|
14
|
+
Listen.to('.', ListenOptions.to_h) do |modified, added, removed|
|
15
|
+
begin
|
16
|
+
if modified.any?
|
17
|
+
`clear 2>&1` || `cls 2>&1`
|
18
|
+
command.run(modified.first.strip)
|
19
|
+
end
|
20
|
+
rescue => e
|
21
|
+
puts "Something went wrong: #{e.message}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
8
25
|
end
|
data/lib/retest/command.rb
CHANGED
@@ -25,7 +25,10 @@ module Retest
|
|
25
25
|
puts "Test File Selected: #{cached_test_file}"
|
26
26
|
system command.gsub('<test>', cached_test_file)
|
27
27
|
else
|
28
|
-
puts
|
28
|
+
puts <<~ERROR
|
29
|
+
404 - Test File Not Found
|
30
|
+
Retest could not find a matching test file to run.
|
31
|
+
ERROR
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -0,0 +1,36 @@
|
|
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>&1"
|
30
|
+
end
|
31
|
+
|
32
|
+
def files
|
33
|
+
`git ls-files`
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
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,23 +25,10 @@ module Retest
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def test_options(path)
|
29
|
-
files.select { |file| regex(path) =~ file }
|
30
|
-
.sort_by { |file| String::Similarity.levenshtein(path, file) }
|
31
|
-
.last(5)
|
32
|
-
.reverse
|
33
|
-
end
|
34
|
-
|
35
28
|
def default_files
|
36
29
|
@default_files ||= Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
|
37
30
|
end
|
38
31
|
|
39
|
-
def regex(path)
|
40
|
-
extname = File.extname(path)
|
41
|
-
basename = File.basename(path, extname)
|
42
|
-
Regexp.new(".*#{basename}_(?:spec|test)#{extname}")
|
43
|
-
end
|
44
|
-
|
45
32
|
def ask_question(tests)
|
46
33
|
output_stream.puts <<~QUESTION
|
47
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
data/retest.gemspec
CHANGED
@@ -27,6 +27,4 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
spec.add_runtime_dependency "string-similarity", ["~> 2.1"]
|
29
29
|
spec.add_runtime_dependency "listen", ["~> 3.2"]
|
30
|
-
spec.add_development_dependency "cucumber"
|
31
|
-
spec.add_development_dependency "aruba"
|
32
30
|
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.6.0.pre2
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -38,35 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.2'
|
41
|
-
|
42
|
-
name: cucumber
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: aruba
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
description:
|
41
|
+
description:
|
70
42
|
email:
|
71
43
|
- alex@abletech.nz
|
72
44
|
executables:
|
@@ -74,8 +46,9 @@ executables:
|
|
74
46
|
extensions: []
|
75
47
|
extra_rdoc_files: []
|
76
48
|
files:
|
49
|
+
- ".github/workflows/ci.yml"
|
77
50
|
- ".gitignore"
|
78
|
-
- ".
|
51
|
+
- ".ruby-version"
|
79
52
|
- Gemfile
|
80
53
|
- Gemfile.lock
|
81
54
|
- LICENSE.txt
|
@@ -87,7 +60,9 @@ files:
|
|
87
60
|
- exe/retest
|
88
61
|
- lib/retest.rb
|
89
62
|
- lib/retest/command.rb
|
63
|
+
- lib/retest/listen_options.rb
|
90
64
|
- lib/retest/repository.rb
|
65
|
+
- lib/retest/test_options.rb
|
91
66
|
- lib/retest/version.rb
|
92
67
|
- retest.gemspec
|
93
68
|
homepage: https://github.com/AlexB52/retest
|
@@ -96,7 +71,7 @@ licenses:
|
|
96
71
|
metadata:
|
97
72
|
homepage_uri: https://github.com/AlexB52/retest
|
98
73
|
source_code_uri: https://github.com/AlexB52/retest
|
99
|
-
post_install_message:
|
74
|
+
post_install_message:
|
100
75
|
rdoc_options: []
|
101
76
|
require_paths:
|
102
77
|
- lib
|
@@ -107,12 +82,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
82
|
version: 2.3.0
|
108
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
84
|
requirements:
|
110
|
-
- - "
|
85
|
+
- - ">"
|
111
86
|
- !ruby/object:Gem::Version
|
112
|
-
version:
|
87
|
+
version: 1.3.1
|
113
88
|
requirements: []
|
114
|
-
rubygems_version: 3.
|
115
|
-
signing_key:
|
89
|
+
rubygems_version: 3.0.3
|
90
|
+
signing_key:
|
116
91
|
specification_version: 4
|
117
92
|
summary: A simple command line tool to watch file change and run its matching spec.
|
118
93
|
test_files: []
|