retest 0.8.2 → 0.9.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/workflows/ci.yml +2 -0
- data/Gemfile.lock +2 -2
- data/README.md +45 -21
- data/bin/debug +18 -0
- data/bin/test/hanami-app +3 -1
- data/bin/test/rails-app +1 -1
- data/bin/test/rspec-rails +6 -0
- data/bin/test/rspec-ruby +6 -0
- data/bin/test/ruby-app +1 -1
- data/lib/retest.rb +1 -0
- data/lib/retest/options.rb +69 -12
- data/lib/retest/repository.rb +2 -2
- data/lib/retest/setup.rb +45 -0
- data/lib/retest/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8df33036507fe29259ef99ac9fa574fdece9af4e69911f21125a1c4bbad7778c
|
4
|
+
data.tar.gz: a4bb2606b7373fb304638125be08d94c79a5dfb5e324cbf433848730cf08abe6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba3f7823d9789965dbd44d92ac40aeb1f6d3dd9f35f6e634f317949adf72ba672abb231f4603acfe1da2c766d3158da81ca1c538868ab8be8955bfdf443651b0
|
7
|
+
data.tar.gz: 74f1a43fc0b23d48bd9a7cdd53c8a57206cbf9cc3546f1a6d2d0609d7f837744f1f74162ced9f57661f6008237b039f32ba2454289d839314ecfae5bc4ce011f
|
data/.github/workflows/ci.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
retest (0.
|
4
|
+
retest (0.9.0)
|
5
5
|
listen (~> 3.2)
|
6
6
|
string-similarity (~> 2.1)
|
7
7
|
tty-option (~> 0.1)
|
@@ -10,7 +10,7 @@ GEM
|
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
12
|
byebug (11.1.3)
|
13
|
-
ffi (1.
|
13
|
+
ffi (1.15.0)
|
14
14
|
listen (3.4.1)
|
15
15
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
16
16
|
rb-inotify (~> 0.9, >= 0.9.10)
|
data/README.md
CHANGED
@@ -2,29 +2,46 @@
|
|
2
2
|
|
3
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
|
-
##
|
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
|
-
|
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
|
-
|
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)
|
5
|
+
## Demo
|
11
6
|
|
12
7
|

|
13
8
|
|
14
9
|
## Installation
|
15
10
|
|
16
|
-
Install it on your machine
|
11
|
+
Install it on your machine without adding it on a Gemfile:
|
17
12
|
|
18
13
|
$ gem install retest
|
19
|
-
$ retest 'bundle exec rspec <test>'
|
20
14
|
|
21
15
|
## Usage
|
22
16
|
|
23
|
-
Launch `retest` in your terminal after accessing your ruby
|
17
|
+
Launch `retest` in your terminal after accessing your ruby repository.
|
18
|
+
|
19
|
+
You can pass the test command surrounded by quotes and use the placeholder `<test>` to tell `retest` where to put test file in your command. Example:
|
24
20
|
|
25
|
-
|
21
|
+
$ retest 'bundle exec rspec <test>'
|
22
|
+
|
23
|
+
When a file is changed, the gem will find its matching test and run the test command with it.
|
24
|
+
|
25
|
+
Few shortcut flags exist to avoid writing the full test command.
|
26
|
+
|
27
|
+
$ retest --rspec
|
28
|
+
$ retest --rails
|
29
|
+
$ retest --rake --all
|
30
|
+
|
31
|
+
Finally let retest automatically find your ruby setup and run the appropriate command using:
|
26
32
|
|
27
|
-
|
33
|
+
$ retest
|
34
|
+
$ retest --auto
|
35
|
+
$ retest --auto --all
|
36
|
+
|
37
|
+
The gem works as follows:
|
38
|
+
|
39
|
+
* When a file is changed, retest will run its matching test.
|
40
|
+
* When a test files is changed, retest will run the test file.
|
41
|
+
* When multiple matching test files are found, retest asks you to confirm the file and save the answer.
|
42
|
+
* When a test file is not found, retest runs the last run command or throw a 404.
|
43
|
+
|
44
|
+
See more example with `retest -h`
|
28
45
|
|
29
46
|
```
|
30
47
|
Usage: retest [OPTIONS] [COMMAND]
|
@@ -35,10 +52,11 @@ Arguments:
|
|
35
52
|
COMMAND The test command to rerun when a file changes.
|
36
53
|
Use <test> placeholder to tell retest where to put the matching
|
37
54
|
spec.
|
38
|
-
|
55
|
+
|
39
56
|
|
40
57
|
Options:
|
41
58
|
--all Run all the specs of a specificied ruby setup
|
59
|
+
--auto Indentify repository setup and runs appropriate command
|
42
60
|
-h, --help Print usage
|
43
61
|
--rails Shortcut for 'bundle exec rails test <test>'
|
44
62
|
--rake Shortcut for 'bundle exec rake test TEST=<test>'
|
@@ -56,16 +74,24 @@ Examples:
|
|
56
74
|
|
57
75
|
Runs a hardcoded command after a file change
|
58
76
|
$ retest 'ruby lib/bottles_test.rb'
|
77
|
+
|
78
|
+
Let retest identify which command to run
|
79
|
+
$ retest
|
80
|
+
$ retest --auto
|
81
|
+
|
82
|
+
Let retest identify which command to run for all tests
|
83
|
+
$ retest --all
|
84
|
+
$ retest --auto --all
|
59
85
|
```
|
60
86
|
|
61
|
-
|
87
|
+
## Why?
|
88
|
+
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.
|
62
89
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
* When a test file is not found, retest runs the last run command or throw a 404.
|
90
|
+
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.
|
91
|
+
|
92
|
+
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)
|
67
93
|
|
68
|
-
|
94
|
+
## Docker
|
69
95
|
|
70
96
|
Retest works in Docker too. You can install the gem and launch retest in your container while refactoring.
|
71
97
|
```bash
|
@@ -74,7 +100,7 @@ $ gem install retest
|
|
74
100
|
$ retest 'bundle exec rails test <test>'
|
75
101
|
```
|
76
102
|
|
77
|
-
|
103
|
+
## Disclaimer
|
78
104
|
* If an error comes in try using `bundle exec` like so: `$ retest 'bundle exec rake test <test>'`
|
79
105
|
* Aliases saved on ~/.bashrc or ~/.zshrc cannot be run that way with the `retest` command
|
80
106
|
|
@@ -93,8 +119,6 @@ Retest supports ruby 2.4 and above.
|
|
93
119
|
- [x] Rails
|
94
120
|
- [x] Ad-hoc scripts
|
95
121
|
- [x] Hanami
|
96
|
-
- [ ] Sinatra
|
97
|
-
- [ ] Cuba? Padrino?
|
98
122
|
- [ ] Handle other languages: Elixir, Node, Python, PHP
|
99
123
|
- [ ] Aliases from oh-my-zsh and bash profiles?
|
100
124
|
|
data/bin/debug
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "retest"
|
5
|
+
require "byebug"
|
6
|
+
|
7
|
+
$stdout.sync = true
|
8
|
+
|
9
|
+
options = Retest::Options.new(ARGV)
|
10
|
+
|
11
|
+
if options.help?
|
12
|
+
$stdout.puts options.help
|
13
|
+
return
|
14
|
+
end
|
15
|
+
|
16
|
+
Retest.start(options.command) # not blocking
|
17
|
+
|
18
|
+
sleep
|
data/bin/test/hanami-app
CHANGED
@@ -3,4 +3,6 @@
|
|
3
3
|
bundle install
|
4
4
|
bundle exec rake build
|
5
5
|
ls -t pkg | head -n1 | xargs -I {} mv pkg/{} features/hanami-app/retest.gem
|
6
|
-
docker-compose -f features/hanami-app/docker-compose.yml
|
6
|
+
docker-compose -f features/hanami-app/docker-compose.yml build
|
7
|
+
docker-compose -f features/hanami-app/docker-compose.yml run retest sh bin/test_setup
|
8
|
+
docker-compose -f features/hanami-app/docker-compose.yml up --exit-code-from retest
|
data/bin/test/rails-app
CHANGED
@@ -3,4 +3,4 @@
|
|
3
3
|
bundle install
|
4
4
|
bundle exec rake build
|
5
5
|
ls -t pkg | head -n1 | xargs -I {} mv pkg/{} features/rails-app/retest.gem
|
6
|
-
docker-compose -f features/rails-app/docker-compose.yml up --build
|
6
|
+
docker-compose -f features/rails-app/docker-compose.yml up --build --exit-code-from retest
|
data/bin/test/rspec-ruby
ADDED
data/bin/test/ruby-app
CHANGED
@@ -3,4 +3,4 @@
|
|
3
3
|
bundle install
|
4
4
|
bundle exec rake build
|
5
5
|
ls -t pkg | head -n1 | xargs -I {} mv pkg/{} features/ruby-app/retest.gem
|
6
|
-
docker-compose -f features/ruby-app/docker-compose.yml up --build
|
6
|
+
docker-compose -f features/ruby-app/docker-compose.yml up --build --exit-code-from retest
|
data/lib/retest.rb
CHANGED
data/lib/retest/options.rb
CHANGED
@@ -8,7 +8,6 @@ module Retest
|
|
8
8
|
RAILS_COMMAND = "bundle exec rails test <test>"
|
9
9
|
RAKE_COMMAND = "bundle exec rake test TEST=<test>"
|
10
10
|
RUBY_COMMAND = "bundle exec ruby <test>"
|
11
|
-
NO_COMMAND = "echo You have no command assigned"
|
12
11
|
|
13
12
|
ALL_RAKE_COMMAND = "bundle exec rake test"
|
14
13
|
ALL_RAILS_COMMAND = "bundle exec rails test"
|
@@ -37,6 +36,18 @@ module Retest
|
|
37
36
|
Runs a hardcoded command after a file change
|
38
37
|
$ retest 'ruby lib/bottles_test.rb'
|
39
38
|
EOS
|
39
|
+
|
40
|
+
example <<~EOS
|
41
|
+
Let retest identify which command to run
|
42
|
+
$ retest
|
43
|
+
$ retest --auto
|
44
|
+
EOS
|
45
|
+
|
46
|
+
example <<~EOS
|
47
|
+
Let retest identify which command to run for all tests
|
48
|
+
$ retest --all
|
49
|
+
$ retest --auto --all
|
50
|
+
EOS
|
40
51
|
end
|
41
52
|
|
42
53
|
argument :command do
|
@@ -52,6 +63,11 @@ module Retest
|
|
52
63
|
desc "Run all the specs of a specificied ruby setup"
|
53
64
|
end
|
54
65
|
|
66
|
+
flag :auto do
|
67
|
+
long "--auto"
|
68
|
+
desc "Indentify repository setup and runs appropriate command"
|
69
|
+
end
|
70
|
+
|
55
71
|
flag :help do
|
56
72
|
short "-h"
|
57
73
|
long "--help"
|
@@ -84,21 +100,21 @@ module Retest
|
|
84
100
|
new(args).command
|
85
101
|
end
|
86
102
|
|
87
|
-
def initialize(args = [])
|
103
|
+
def initialize(args = [], output_stream: STDOUT, setup: Setup)
|
88
104
|
self.args = args
|
105
|
+
@output_stream = output_stream
|
106
|
+
@setup = setup
|
89
107
|
end
|
90
108
|
|
91
109
|
def command
|
92
|
-
if params[:
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
elsif params[:rails]
|
97
|
-
|
98
|
-
elsif params[:
|
99
|
-
|
100
|
-
else
|
101
|
-
params[:command] || NO_COMMAND
|
110
|
+
return params[:command] if params[:command]
|
111
|
+
|
112
|
+
if params[:rspec] then rspec_command
|
113
|
+
elsif params[:rake] then rake_command
|
114
|
+
elsif params[:rails] then rails_command
|
115
|
+
elsif params[:ruby] then ruby_command
|
116
|
+
elsif params[:auto] then default_command
|
117
|
+
else default_command
|
102
118
|
end
|
103
119
|
end
|
104
120
|
|
@@ -110,5 +126,46 @@ module Retest
|
|
110
126
|
def help?
|
111
127
|
params[:help]
|
112
128
|
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def full_suite?
|
133
|
+
params[:all]
|
134
|
+
end
|
135
|
+
|
136
|
+
def default_command
|
137
|
+
choose_command @setup.type, command_for(@setup.type)
|
138
|
+
end
|
139
|
+
|
140
|
+
def command_for(type)
|
141
|
+
case type
|
142
|
+
when :rspec then rspec_command
|
143
|
+
when :rails then rails_command
|
144
|
+
when :rake then rake_command
|
145
|
+
when :ruby then ruby_command
|
146
|
+
else ruby_command
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def choose_command(type, command)
|
151
|
+
@output_stream.puts "Setup identified: [#{type.upcase}]. Using command: '#{command}'"
|
152
|
+
command
|
153
|
+
end
|
154
|
+
|
155
|
+
def rspec_command
|
156
|
+
full_suite? ? ALL_RSPEC_COMMAND : RSPEC_COMMAND
|
157
|
+
end
|
158
|
+
|
159
|
+
def rails_command
|
160
|
+
full_suite? ? ALL_RAILS_COMMAND : RAILS_COMMAND
|
161
|
+
end
|
162
|
+
|
163
|
+
def rake_command
|
164
|
+
full_suite? ? ALL_RAKE_COMMAND : RAKE_COMMAND
|
165
|
+
end
|
166
|
+
|
167
|
+
def ruby_command
|
168
|
+
RUBY_COMMAND
|
169
|
+
end
|
113
170
|
end
|
114
171
|
end
|
data/lib/retest/repository.rb
CHANGED
@@ -17,14 +17,14 @@ module Retest
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def add(added)
|
20
|
-
return if added
|
20
|
+
return if added&.empty?
|
21
21
|
|
22
22
|
files.push(*added)
|
23
23
|
files.sort!
|
24
24
|
end
|
25
25
|
|
26
26
|
def remove(removed)
|
27
|
-
return if removed
|
27
|
+
return if removed&.empty?
|
28
28
|
|
29
29
|
if removed.is_a?(Array)
|
30
30
|
removed.each { |file| files.delete(file) }
|
data/lib/retest/setup.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Retest
|
2
|
+
class Setup
|
3
|
+
def self.type
|
4
|
+
new.type
|
5
|
+
end
|
6
|
+
|
7
|
+
def type
|
8
|
+
@type ||= begin
|
9
|
+
return :ruby unless has_gemfile?
|
10
|
+
|
11
|
+
if rspec?
|
12
|
+
:rspec
|
13
|
+
elsif rails?
|
14
|
+
:rails
|
15
|
+
elsif rake?
|
16
|
+
:rake
|
17
|
+
else
|
18
|
+
:ruby
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def has_gemfile?
|
26
|
+
File.exist? 'Gemfile'
|
27
|
+
end
|
28
|
+
|
29
|
+
def rspec?
|
30
|
+
has_gem? 'rspec'
|
31
|
+
end
|
32
|
+
|
33
|
+
def rails?
|
34
|
+
File.exist? 'bin/rails'
|
35
|
+
end
|
36
|
+
|
37
|
+
def rake?
|
38
|
+
has_gem? 'rake'
|
39
|
+
end
|
40
|
+
|
41
|
+
def has_gem?(gem_name)
|
42
|
+
!`cat Gemfile | grep #{gem_name}`.empty?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
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.9.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: 2021-03-
|
11
|
+
date: 2021-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -70,15 +70,19 @@ files:
|
|
70
70
|
- README/demo.gif
|
71
71
|
- Rakefile
|
72
72
|
- bin/console
|
73
|
+
- bin/debug
|
73
74
|
- bin/setup
|
74
75
|
- bin/test/hanami-app
|
75
76
|
- bin/test/rails-app
|
77
|
+
- bin/test/rspec-rails
|
78
|
+
- bin/test/rspec-ruby
|
76
79
|
- bin/test/ruby-app
|
77
80
|
- exe/retest
|
78
81
|
- lib/retest.rb
|
79
82
|
- lib/retest/options.rb
|
80
83
|
- lib/retest/repository.rb
|
81
84
|
- lib/retest/runner.rb
|
85
|
+
- lib/retest/setup.rb
|
82
86
|
- lib/retest/test_options.rb
|
83
87
|
- lib/retest/version.rb
|
84
88
|
- lib/retest/version_control.rb
|