retest 1.2.0 → 1.5.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/Gemfile.lock +4 -4
- data/README.md +46 -62
- data/bin/debug +8 -2
- data/exe/retest +8 -2
- data/lib/retest/command/rails.rb +12 -5
- data/lib/retest/command/rake.rb +12 -5
- data/lib/retest/command/rspec.rb +11 -4
- data/lib/retest/command/ruby.rb +12 -3
- data/lib/retest/command.rb +4 -4
- data/lib/retest/options.rb +15 -14
- data/lib/retest/program.rb +44 -0
- data/lib/retest/repository.rb +6 -1
- data/lib/retest/runners/change_runner.rb +17 -0
- data/lib/retest/runners/runner.rb +26 -0
- data/lib/retest/{runner.rb → runners/test_runner.rb} +11 -50
- data/lib/retest/runners/variable_runner.rb +57 -0
- data/lib/retest/runners.rb +22 -0
- data/lib/retest/version.rb +1 -1
- data/lib/retest.rb +2 -47
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce75120a1212540c1e510e4fd3d28e505f68d79e4e557b48e34cfda769d35613
|
4
|
+
data.tar.gz: ff2a3cc3644ce392adb38d8a87ffea711bbc6baaeb20f70099b2c0771cce3cf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6741101b8345dfcba37002b1265d6ed5170c8b82eccc8a143b20a7fb77d196f05b9c4b4af142a7fed62952aa5251769523243c997884334cc8a3d484f93f3207
|
7
|
+
data.tar.gz: 3c4f2484eb2400a47d35c22a33f6db47ede1e0fc401dccdede644114f90bc2765f1e1e6df5b2fea7e761d77983a863f2c917cfb5afd71ffabd89e884f1ad85c6
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
retest (1.
|
4
|
+
retest (1.5.0)
|
5
5
|
listen (~> 3.2)
|
6
6
|
string-similarity (~> 2.1)
|
7
7
|
tty-option (~> 0.1)
|
@@ -10,8 +10,8 @@ GEM
|
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
12
|
byebug (11.1.3)
|
13
|
-
ffi (1.15.
|
14
|
-
listen (3.
|
13
|
+
ffi (1.15.4)
|
14
|
+
listen (3.7.0)
|
15
15
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
16
16
|
rb-inotify (~> 0.9, >= 0.9.10)
|
17
17
|
minitest (5.14.1)
|
@@ -20,7 +20,7 @@ GEM
|
|
20
20
|
rb-inotify (0.10.1)
|
21
21
|
ffi (~> 1.0)
|
22
22
|
string-similarity (2.1.0)
|
23
|
-
tty-option (0.
|
23
|
+
tty-option (0.2.0)
|
24
24
|
|
25
25
|
PLATFORMS
|
26
26
|
ruby
|
data/README.md
CHANGED
@@ -15,15 +15,38 @@ Install it on your machine without adding it on a Gemfile:
|
|
15
15
|
$ gem install retest
|
16
16
|
|
17
17
|
## Usage
|
18
|
-
### Refactoring
|
19
18
|
|
20
|
-
|
19
|
+
Retest is used in your terminal after accessing your ruby project folder.
|
21
20
|
|
22
|
-
|
21
|
+
### Help
|
22
|
+
|
23
|
+
Find out what retest can do anytime with
|
24
|
+
|
25
|
+
$ retest -h
|
26
|
+
|
27
|
+
### For Refactoring
|
28
|
+
|
29
|
+
#### 1. Run a hardcoded command
|
30
|
+
|
31
|
+
This the most simple usage of retest: running the same command over and over after each file update.
|
32
|
+
|
33
|
+
Example:
|
34
|
+
|
35
|
+
$ retest 'bundle exec rspec spec/features/posts_spec.rb'
|
23
36
|
|
24
|
-
|
37
|
+
In this example, the feature spec `spec/features/posts_spec.rb` will be tested after any ruby file is updated.
|
25
38
|
|
26
|
-
|
39
|
+
#### 2. Run a dynamic command
|
40
|
+
|
41
|
+
You can use the placeholder `<test>` to tell the gem where to put the test file path in your command. When a file is changed, the gem will find its matching test and run the test command with it.
|
42
|
+
|
43
|
+
Example:
|
44
|
+
|
45
|
+
$ retest 'bin/rails test <test>'
|
46
|
+
|
47
|
+
In this example, if `app/models/post.rb` is changed then retest will run `bin/rails test test/models/post_test.rb`
|
48
|
+
|
49
|
+
#### 3. Run a dynamic command with shortcuts
|
27
50
|
|
28
51
|
Few shortcut flags exist to avoid writing the full test command.
|
29
52
|
|
@@ -31,72 +54,29 @@ Few shortcut flags exist to avoid writing the full test command.
|
|
31
54
|
$ retest --rails
|
32
55
|
$ retest --rake --all
|
33
56
|
|
34
|
-
|
57
|
+
#### 4. Let retest figure it all out
|
58
|
+
|
59
|
+
Let retest find your ruby setup and run the appropriate command using:
|
35
60
|
|
36
61
|
$ retest
|
37
62
|
$ retest --all
|
38
63
|
|
64
|
+
#### Running rules
|
65
|
+
|
39
66
|
The gem works as follows:
|
40
67
|
|
41
|
-
* When a file is changed, retest will run its matching test.
|
42
|
-
* When a test
|
68
|
+
* When a **ruby file** is changed, retest will run its matching test.
|
69
|
+
* When a **test file** is changed, retest will run the test file.
|
43
70
|
* When multiple matching test files are found, retest asks you to confirm the file and save the answer.
|
44
71
|
* When a test file is not found, retest runs the last run command or throw a 404.
|
45
72
|
|
46
|
-
###
|
73
|
+
### Pull request scans
|
47
74
|
|
48
|
-
You can diff a branch and test all the relevant test files before pushing your branch and trigger
|
75
|
+
You can diff a branch and test all the relevant test files before pushing your branch and trigger a full CI suite.
|
49
76
|
|
50
77
|
$ retest --diff origin/main
|
51
78
|
|
52
|
-
|
53
|
-
|
54
|
-
See more examples with `retest -h`
|
55
|
-
|
56
|
-
```
|
57
|
-
Usage: retest [OPTIONS] [COMMAND]
|
58
|
-
|
59
|
-
Watch a file change and run it matching spec.
|
60
|
-
|
61
|
-
Arguments:
|
62
|
-
COMMAND The test command to rerun when a file changes.
|
63
|
-
Use <test> placeholder to tell retest where to put the matching
|
64
|
-
spec.
|
65
|
-
|
66
|
-
|
67
|
-
Options:
|
68
|
-
--all Run all the specs of a specificied ruby setup
|
69
|
-
--auto Indentify repository setup and runs appropriate command
|
70
|
-
-h, --help Print usage
|
71
|
-
--rails Shortcut for 'bundle exec rails test <test>'
|
72
|
-
--rake Shortcut for 'bundle exec rake test TEST=<test>'
|
73
|
-
--rspec Shortcut for 'bundle exec rspec <test>'
|
74
|
-
--ruby Shortcut for 'bundle exec ruby <test>'
|
75
|
-
|
76
|
-
Examples:
|
77
|
-
Runs a matching rails test after a file change
|
78
|
-
$ retest 'bundle exec rails test <test>'
|
79
|
-
$ retest --rails
|
80
|
-
|
81
|
-
Runs all rails tests after a file change
|
82
|
-
$ retest 'bundle exec rails test'
|
83
|
-
$ retest --rails --all
|
84
|
-
|
85
|
-
Runs a hardcoded command after a file change
|
86
|
-
$ retest 'ruby lib/bottles_test.rb'
|
87
|
-
|
88
|
-
Let retest identify which command to run
|
89
|
-
$ retest
|
90
|
-
$ retest --auto
|
91
|
-
|
92
|
-
Let retest identify which command to run for all tests
|
93
|
-
$ retest --all
|
94
|
-
$ retest --auto --all
|
95
|
-
|
96
|
-
Run a sanity check on changed files from a branch
|
97
|
-
$ retest --diff origin/main --rails
|
98
|
-
$ retest --diff main --auto
|
99
|
-
```
|
79
|
+
In this example, retest lists all the files changed between `HEAD` and `origin/main`, finds all the relevant tests and only run those.
|
100
80
|
|
101
81
|
## Why?
|
102
82
|
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.
|
@@ -108,8 +88,12 @@ For fully fledged solutions, some cli tools already exists: [autotest](https://g
|
|
108
88
|
## Docker
|
109
89
|
|
110
90
|
Retest works in Docker too. You can install the gem and launch retest in your container while refactoring.
|
91
|
+
|
111
92
|
```bash
|
112
|
-
|
93
|
+
# Enter your container. Ex:
|
94
|
+
$ docker-compose run web bash
|
95
|
+
|
96
|
+
# Install the gem and run retest in your container shell
|
113
97
|
$ gem install retest
|
114
98
|
$ retest 'bundle exec rails test <test>'
|
115
99
|
```
|
@@ -128,12 +112,13 @@ Retest supports ruby 2.4 and above.
|
|
128
112
|
- [x] When multiple test files are found, ask which file to run and save the answer.
|
129
113
|
- [x] When a test file is not found run the last command again.
|
130
114
|
- [x] Run within Docker.
|
131
|
-
- [
|
115
|
+
- [x] Handle main Ruby setups
|
132
116
|
- [x] Bundler Gem
|
133
117
|
- [x] Rails
|
134
118
|
- [x] Ad-hoc scripts
|
135
119
|
- [x] Hanami
|
136
|
-
- [ ] Handle other languages: Elixir, Node, Python, PHP
|
120
|
+
- [ ] Handle other languages: Go, Elixir, Node, Python, PHP
|
121
|
+
- [ ] Go (project started)
|
137
122
|
- [ ] Aliases from oh-my-zsh and bash profiles?
|
138
123
|
|
139
124
|
## Development
|
@@ -146,7 +131,6 @@ To run integration tests on one setup (ex: hanami-app): `bin/test/hanami-app`
|
|
146
131
|
|
147
132
|
To access an app container (ex: ruby-app): `docker-compose -f features/ruby-app/docker-compose.yml run retest sh`
|
148
133
|
|
149
|
-
|
150
134
|
## Contributing
|
151
135
|
|
152
136
|
Bug reports and pull requests are welcome on GitHub at https://github.com/alexb52/retest.
|
data/bin/debug
CHANGED
@@ -13,9 +13,15 @@ if options.help?
|
|
13
13
|
return
|
14
14
|
end
|
15
15
|
|
16
|
+
repository = Retest::Repository.new(files: Retest::VersionControl.files)
|
17
|
+
command = Retest::Command.for_options(options)
|
18
|
+
runner = Retest::Runners.runner_for(command.to_s)
|
19
|
+
|
16
20
|
program = Retest::Program.new(
|
17
|
-
|
18
|
-
|
21
|
+
extension: options.extension,
|
22
|
+
repository: repository,
|
23
|
+
command: command,
|
24
|
+
runner: runner
|
19
25
|
)
|
20
26
|
|
21
27
|
if options.params[:diff]
|
data/exe/retest
CHANGED
@@ -11,9 +11,15 @@ if options.help?
|
|
11
11
|
return
|
12
12
|
end
|
13
13
|
|
14
|
+
repository = Retest::Repository.new(files: Retest::VersionControl.files)
|
15
|
+
command = Retest::Command.for_options(options)
|
16
|
+
runner = Retest::Runners.runner_for(command.to_s)
|
17
|
+
|
14
18
|
program = Retest::Program.new(
|
15
|
-
|
16
|
-
|
19
|
+
extension: options.extension,
|
20
|
+
repository: repository,
|
21
|
+
command: command,
|
22
|
+
runner: runner
|
17
23
|
)
|
18
24
|
|
19
25
|
if options.params[:diff]
|
data/lib/retest/command/rails.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
module Retest
|
2
2
|
class Command
|
3
|
-
Rails
|
4
|
-
|
5
|
-
|
3
|
+
class Rails
|
4
|
+
attr_reader :all, :file_system
|
5
|
+
|
6
|
+
def initialize(all:, file_system: FileSystem)
|
7
|
+
@file_system = file_system
|
8
|
+
@all = all
|
6
9
|
end
|
7
10
|
|
8
|
-
def
|
11
|
+
def to_s
|
9
12
|
return "#{root_command} <test>" unless all
|
10
13
|
root_command
|
11
14
|
end
|
12
15
|
|
16
|
+
def format_batch(*files)
|
17
|
+
files.join(' ')
|
18
|
+
end
|
19
|
+
|
13
20
|
private
|
14
21
|
|
15
22
|
def root_command
|
@@ -19,4 +26,4 @@ module Retest
|
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
22
|
-
end
|
29
|
+
end
|
data/lib/retest/command/rake.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
module Retest
|
2
2
|
class Command
|
3
|
-
Rake
|
4
|
-
|
5
|
-
|
3
|
+
class Rake
|
4
|
+
attr_reader :all, :file_system
|
5
|
+
|
6
|
+
def initialize(all:, file_system: FileSystem)
|
7
|
+
@file_system = file_system
|
8
|
+
@all = all
|
6
9
|
end
|
7
10
|
|
8
|
-
def
|
11
|
+
def to_s
|
9
12
|
return "#{root_command} TEST=<test>" unless all
|
10
13
|
root_command
|
11
14
|
end
|
12
15
|
|
16
|
+
def format_batch(*files)
|
17
|
+
files.size > 1 ? "\"{#{files.join(',')}}\"" : files.first
|
18
|
+
end
|
19
|
+
|
13
20
|
private
|
14
21
|
|
15
22
|
def root_command
|
@@ -19,4 +26,4 @@ module Retest
|
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
22
|
-
end
|
29
|
+
end
|
data/lib/retest/command/rspec.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
module Retest
|
2
2
|
class Command
|
3
|
-
Rspec
|
4
|
-
|
5
|
-
|
3
|
+
class Rspec
|
4
|
+
attr_reader :all, :file_system
|
5
|
+
|
6
|
+
def initialize(all:, file_system: FileSystem)
|
7
|
+
@file_system = file_system
|
8
|
+
@all = all
|
6
9
|
end
|
7
10
|
|
8
|
-
def
|
11
|
+
def to_s
|
9
12
|
return "#{root_command} <test>" unless all
|
10
13
|
root_command
|
11
14
|
end
|
12
15
|
|
16
|
+
def format_batch(*files)
|
17
|
+
files.join(' ')
|
18
|
+
end
|
19
|
+
|
13
20
|
private
|
14
21
|
|
15
22
|
def root_command
|
data/lib/retest/command/ruby.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
module Retest
|
2
2
|
class Command
|
3
|
-
|
4
|
-
|
3
|
+
class Ruby
|
4
|
+
attr_reader :all, :file_system
|
5
5
|
|
6
|
-
def
|
6
|
+
def initialize(all:, file_system: FileSystem)
|
7
|
+
@file_system = file_system
|
8
|
+
@all = all
|
9
|
+
end
|
10
|
+
|
11
|
+
def format_batch(*files)
|
12
|
+
%Q{-e "#{files.map { |file| "require './#{file}';" }.join}"}
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
7
16
|
if file_system.exist? 'Gemfile.lock'
|
8
17
|
'bundle exec ruby <test>'
|
9
18
|
else
|
data/lib/retest/command.rb
CHANGED
@@ -59,19 +59,19 @@ module Retest
|
|
59
59
|
private
|
60
60
|
|
61
61
|
def rspec_command
|
62
|
-
Rspec.
|
62
|
+
Rspec.new(all: full_suite?)
|
63
63
|
end
|
64
64
|
|
65
65
|
def rails_command
|
66
|
-
Rails.
|
66
|
+
Rails.new(all: full_suite?)
|
67
67
|
end
|
68
68
|
|
69
69
|
def rake_command
|
70
|
-
Rake.
|
70
|
+
Rake.new(all: full_suite?)
|
71
71
|
end
|
72
72
|
|
73
73
|
def ruby_command
|
74
|
-
Ruby.
|
74
|
+
Ruby.new(all: full_suite?)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/lib/retest/options.rb
CHANGED
@@ -4,15 +4,6 @@ module Retest
|
|
4
4
|
class Options
|
5
5
|
include TTY::Option
|
6
6
|
|
7
|
-
RSPEC_COMMAND = "bundle exec rspec <test>"
|
8
|
-
RAILS_COMMAND = "bundle exec rails test <test>"
|
9
|
-
RAKE_COMMAND = "bundle exec rake test TEST=<test>"
|
10
|
-
RUBY_COMMAND = "bundle exec ruby <test>"
|
11
|
-
|
12
|
-
ALL_RAKE_COMMAND = "bundle exec rake test"
|
13
|
-
ALL_RAILS_COMMAND = "bundle exec rails test"
|
14
|
-
ALL_RSPEC_COMMAND = "bundle exec rspec"
|
15
|
-
|
16
7
|
usage do
|
17
8
|
program "retest"
|
18
9
|
|
@@ -69,6 +60,12 @@ module Retest
|
|
69
60
|
long "--diff=git-branch"
|
70
61
|
end
|
71
62
|
|
63
|
+
option :ext do
|
64
|
+
desc "Regex of file extensions to listen to"
|
65
|
+
long "--ext=regex"
|
66
|
+
default "\\.rb$"
|
67
|
+
end
|
68
|
+
|
72
69
|
flag :all do
|
73
70
|
long "--all"
|
74
71
|
desc "Run all the specs of a specificied ruby setup"
|
@@ -87,22 +84,22 @@ module Retest
|
|
87
84
|
|
88
85
|
flag :rspec do
|
89
86
|
long "--rspec"
|
90
|
-
desc "Shortcut for
|
87
|
+
desc "Shortcut for a standard RSpec setup"
|
91
88
|
end
|
92
89
|
|
93
90
|
flag :rake do
|
94
91
|
long "--rake"
|
95
|
-
desc "Shortcut for
|
92
|
+
desc "Shortcut for a standard Rake setup"
|
96
93
|
end
|
97
94
|
|
98
95
|
flag :rails do
|
99
96
|
long "--rails"
|
100
|
-
desc "Shortcut for
|
97
|
+
desc "Shortcut for a standard Rails setup"
|
101
98
|
end
|
102
99
|
|
103
100
|
flag :ruby do
|
104
101
|
long "--ruby"
|
105
|
-
desc "Shortcut for
|
102
|
+
desc "Shortcut for a Ruby project"
|
106
103
|
end
|
107
104
|
|
108
105
|
attr_reader :args
|
@@ -133,10 +130,14 @@ module Retest
|
|
133
130
|
params[:auto]
|
134
131
|
end
|
135
132
|
|
133
|
+
def extension
|
134
|
+
Regexp.new(params[:ext])
|
135
|
+
end
|
136
|
+
|
136
137
|
private
|
137
138
|
|
138
139
|
def no_options_passed?
|
139
|
-
params.to_h.values.compact.uniq == [false]
|
140
|
+
params.to_h.values.compact.uniq == ["\\.rb$", false]
|
140
141
|
end
|
141
142
|
end
|
142
143
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Retest
|
2
|
+
class Program
|
3
|
+
attr_accessor :runner, :repository, :command, :extension
|
4
|
+
def initialize(runner: nil, repository: nil, command: nil, extension: /\.rb$/)
|
5
|
+
@runner = runner
|
6
|
+
@repository = repository
|
7
|
+
@command = command
|
8
|
+
@extension = extension
|
9
|
+
end
|
10
|
+
|
11
|
+
def start
|
12
|
+
puts "Launching Retest..."
|
13
|
+
build.start
|
14
|
+
puts "Ready to refactor! You can make file changes now"
|
15
|
+
end
|
16
|
+
|
17
|
+
def diff(branch)
|
18
|
+
raise "Git not installed" unless VersionControl::Git.installed?
|
19
|
+
test_files = repository.find_tests VersionControl::Git.diff_files(branch)
|
20
|
+
|
21
|
+
puts "Tests found:"
|
22
|
+
test_files.each { |test_file| puts " - #{test_file}" }
|
23
|
+
|
24
|
+
puts "Running tests..."
|
25
|
+
runner.run_all_tests command.format_batch(test_files)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def build
|
31
|
+
Listen.to('.', only: extension, relative: true) do |modified, added, removed|
|
32
|
+
begin
|
33
|
+
repository.sync(added: added, removed: removed)
|
34
|
+
runner.sync(added: added, removed: removed)
|
35
|
+
system('clear 2>/dev/null') || system('cls 2>/dev/null')
|
36
|
+
|
37
|
+
runner.run (modified + added).first, repository: repository
|
38
|
+
rescue => e
|
39
|
+
puts "Something went wrong: #{e.message}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/retest/repository.rb
CHANGED
@@ -26,6 +26,11 @@ module Retest
|
|
26
26
|
.sort
|
27
27
|
end
|
28
28
|
|
29
|
+
def sync(added:, removed:)
|
30
|
+
add(added)
|
31
|
+
remove(removed)
|
32
|
+
end
|
33
|
+
|
29
34
|
def add(added)
|
30
35
|
return if added&.empty?
|
31
36
|
|
@@ -56,7 +61,7 @@ module Retest
|
|
56
61
|
end
|
57
62
|
|
58
63
|
def ask_question(tests)
|
59
|
-
output_stream.puts
|
64
|
+
output_stream.puts(<<~QUESTION)
|
60
65
|
We found few tests matching: #{@path}
|
61
66
|
#{list_options(tests)}
|
62
67
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Retest
|
2
|
+
module Runners
|
3
|
+
class ChangeRunner < Runner
|
4
|
+
def run(changed_file = nil, repository: nil)
|
5
|
+
if changed_file
|
6
|
+
puts "Changed File Selected: #{changed_file}"
|
7
|
+
system command.gsub('<changed>', changed_file)
|
8
|
+
else
|
9
|
+
puts <<~ERROR
|
10
|
+
404 - Test File Not Found
|
11
|
+
Retest could not find a changed file to run.
|
12
|
+
ERROR
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Retest
|
2
|
+
module Runners
|
3
|
+
class Runner
|
4
|
+
attr_accessor :command
|
5
|
+
def initialize(command)
|
6
|
+
@command = command
|
7
|
+
end
|
8
|
+
|
9
|
+
def ==(obj)
|
10
|
+
command == obj.command && obj.class == self.class
|
11
|
+
end
|
12
|
+
|
13
|
+
def run(changed_file = nil, repository: nil)
|
14
|
+
system command
|
15
|
+
end
|
16
|
+
|
17
|
+
def run_all_tests(tests_string)
|
18
|
+
puts "Test File Selected: #{tests_string}"
|
19
|
+
system command.gsub('<test>', tests_string)
|
20
|
+
end
|
21
|
+
|
22
|
+
def sync(added:, removed:)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,25 +1,6 @@
|
|
1
1
|
module Retest
|
2
|
-
|
3
|
-
|
4
|
-
if test_command.include? '<test>'
|
5
|
-
VariableRunner
|
6
|
-
else
|
7
|
-
HardcodedRunner
|
8
|
-
end.new test_command
|
9
|
-
end
|
10
|
-
|
11
|
-
class VariableRunner
|
12
|
-
attr_reader :command
|
13
|
-
|
14
|
-
def initialize(command)
|
15
|
-
@command = command
|
16
|
-
@cached_test_file = nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def ==(obj)
|
20
|
-
command == obj.command
|
21
|
-
end
|
22
|
-
|
2
|
+
module Runners
|
3
|
+
class TestRunner < Runner
|
23
4
|
def cached_test_file
|
24
5
|
@cached_test_file
|
25
6
|
end
|
@@ -28,8 +9,8 @@ module Retest
|
|
28
9
|
@cached_test_file = value || @cached_test_file
|
29
10
|
end
|
30
11
|
|
31
|
-
def run(
|
32
|
-
self.cached_test_file =
|
12
|
+
def run(changed_file, repository:)
|
13
|
+
self.cached_test_file = repository.find_test(changed_file)
|
33
14
|
|
34
15
|
if cached_test_file
|
35
16
|
puts "Test File Selected: #{cached_test_file}"
|
@@ -42,6 +23,12 @@ module Retest
|
|
42
23
|
end
|
43
24
|
end
|
44
25
|
|
26
|
+
def sync(added:, removed:)
|
27
|
+
remove(removed)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
45
32
|
def remove(purged)
|
46
33
|
return if purged.empty?
|
47
34
|
|
@@ -52,35 +39,9 @@ module Retest
|
|
52
39
|
end
|
53
40
|
end
|
54
41
|
|
55
|
-
def unmatching?
|
56
|
-
!matching?
|
57
|
-
end
|
58
|
-
|
59
|
-
def matching?
|
60
|
-
true
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
42
|
def purge_cache
|
66
43
|
@cached_test_file = nil
|
67
44
|
end
|
68
45
|
end
|
69
|
-
|
70
|
-
HardcodedRunner = Struct.new(:command) do
|
71
|
-
def run(_ = nil)
|
72
|
-
system command
|
73
|
-
end
|
74
|
-
|
75
|
-
def remove(_ = nil); end
|
76
|
-
|
77
|
-
def unmatching?
|
78
|
-
!matching?
|
79
|
-
end
|
80
|
-
|
81
|
-
def matching?
|
82
|
-
false
|
83
|
-
end
|
84
|
-
end
|
85
46
|
end
|
86
|
-
end
|
47
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Retest
|
2
|
+
module Runners
|
3
|
+
class VariableRunner < Runner
|
4
|
+
def cached_test_file
|
5
|
+
@cached_test_file
|
6
|
+
end
|
7
|
+
|
8
|
+
def cached_test_file=(value)
|
9
|
+
@cached_test_file = value || @cached_test_file
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(changed_file, repository:)
|
13
|
+
self.cached_test_file = repository.find_test(changed_file)
|
14
|
+
|
15
|
+
return print_test_file_not_found unless cached_test_file
|
16
|
+
|
17
|
+
puts(<<~FILES)
|
18
|
+
Files Selected:
|
19
|
+
- file: #{changed_file}
|
20
|
+
- test: #{cached_test_file}
|
21
|
+
|
22
|
+
FILES
|
23
|
+
|
24
|
+
system command
|
25
|
+
.gsub('<test>', cached_test_file)
|
26
|
+
.gsub('<changed>', changed_file)
|
27
|
+
end
|
28
|
+
|
29
|
+
def sync(added:, removed:)
|
30
|
+
remove(removed)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def print_test_file_not_found
|
36
|
+
puts <<~ERROR
|
37
|
+
404 - Test File Not Found
|
38
|
+
Retest could not find a matching test file to run.
|
39
|
+
ERROR
|
40
|
+
end
|
41
|
+
|
42
|
+
def remove(purged)
|
43
|
+
return if purged.empty?
|
44
|
+
|
45
|
+
if purged.is_a? Array
|
46
|
+
purge_cache if purged.include? cached_test_file
|
47
|
+
elsif purged.is_a? String
|
48
|
+
purge_cache if purged == cached_test_file
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def purge_cache
|
53
|
+
@cached_test_file = nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'runners/runner'
|
2
|
+
require_relative 'runners/test_runner'
|
3
|
+
require_relative 'runners/change_runner'
|
4
|
+
require_relative 'runners/variable_runner'
|
5
|
+
|
6
|
+
module Retest
|
7
|
+
module Runners
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def runner_for(command)
|
11
|
+
if command.include?('<test>') && command.include?('<changed>')
|
12
|
+
VariableRunner
|
13
|
+
elsif command.include?('<test>')
|
14
|
+
TestRunner
|
15
|
+
elsif command.include?('<changed>')
|
16
|
+
ChangeRunner
|
17
|
+
else
|
18
|
+
Runner
|
19
|
+
end.new command
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/retest/version.rb
CHANGED
data/lib/retest.rb
CHANGED
@@ -2,7 +2,7 @@ require 'listen'
|
|
2
2
|
require 'string/similarity'
|
3
3
|
|
4
4
|
require "retest/version"
|
5
|
-
require "retest/
|
5
|
+
require "retest/runners"
|
6
6
|
require "retest/repository"
|
7
7
|
require "retest/test_options"
|
8
8
|
require "retest/options"
|
@@ -10,53 +10,8 @@ require "retest/version_control"
|
|
10
10
|
require "retest/setup"
|
11
11
|
require "retest/command"
|
12
12
|
require "retest/file_system"
|
13
|
+
require "retest/program"
|
13
14
|
|
14
15
|
module Retest
|
15
16
|
class Error < StandardError; end
|
16
|
-
|
17
|
-
class Program
|
18
|
-
attr_accessor :runner, :repository
|
19
|
-
def initialize(runner: nil, repository: nil)
|
20
|
-
@runner = runner
|
21
|
-
@repository = repository
|
22
|
-
end
|
23
|
-
|
24
|
-
def start
|
25
|
-
puts "Launching Retest..."
|
26
|
-
build.start
|
27
|
-
puts "Ready to refactor! You can make file changes now"
|
28
|
-
end
|
29
|
-
|
30
|
-
def diff(branch)
|
31
|
-
raise "Git not installed" unless VersionControl::Git.installed?
|
32
|
-
test_files = repository.find_tests VersionControl::Git.diff_files(branch)
|
33
|
-
|
34
|
-
puts "Tests found:"
|
35
|
-
test_files.each { |test_file| puts " - #{test_file}" }
|
36
|
-
|
37
|
-
puts "Running tests..."
|
38
|
-
test_files.each { |test_file| runner.run test_file }
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def build
|
44
|
-
Listen.to('.', only: /\.rb$/, relative: true) do |modified, added, removed|
|
45
|
-
begin
|
46
|
-
repository.add(added)
|
47
|
-
repository.remove(removed)
|
48
|
-
runner.remove(removed)
|
49
|
-
system('clear 2>/dev/null') || system('cls 2>/dev/null')
|
50
|
-
|
51
|
-
runner.run test_file_to_run(modified + added)
|
52
|
-
rescue => e
|
53
|
-
puts "Something went wrong: #{e.message}"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_file_to_run(changed_files)
|
59
|
-
repository.find_test changed_files.first if runner.matching?
|
60
|
-
end
|
61
|
-
end
|
62
17
|
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: 1.
|
4
|
+
version: 1.5.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-
|
11
|
+
date: 2021-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -88,8 +88,13 @@ files:
|
|
88
88
|
- lib/retest/command/ruby.rb
|
89
89
|
- lib/retest/file_system.rb
|
90
90
|
- lib/retest/options.rb
|
91
|
+
- lib/retest/program.rb
|
91
92
|
- lib/retest/repository.rb
|
92
|
-
- lib/retest/
|
93
|
+
- lib/retest/runners.rb
|
94
|
+
- lib/retest/runners/change_runner.rb
|
95
|
+
- lib/retest/runners/runner.rb
|
96
|
+
- lib/retest/runners/test_runner.rb
|
97
|
+
- lib/retest/runners/variable_runner.rb
|
93
98
|
- lib/retest/setup.rb
|
94
99
|
- lib/retest/test_options.rb
|
95
100
|
- lib/retest/version.rb
|