retest 1.3.0 → 1.6.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/.ruby-version +1 -1
- data/Gemfile.lock +5 -5
- data/README.md +62 -66
- data/bin/debug +6 -1
- data/exe/retest +6 -1
- data/lib/retest/command/rails.rb +2 -2
- data/lib/retest/command/rake.rb +2 -2
- data/lib/retest/command/rspec.rb +2 -2
- data/lib/retest/command/ruby.rb +2 -3
- data/lib/retest/options.rb +20 -1
- data/lib/retest/program.rb +8 -12
- data/lib/retest/repository.rb +6 -1
- data/lib/retest/runners/change_runner.rb +17 -0
- data/lib/retest/runners/runner.rb +36 -0
- data/lib/retest/runners/test_runner.rb +47 -0
- data/lib/retest/runners/variable_runner.rb +57 -0
- data/lib/retest/runners.rb +22 -0
- data/lib/retest/sounds.rb +36 -0
- data/lib/retest/version.rb +1 -1
- data/lib/retest.rb +3 -1
- metadata +13 -8
- data/lib/retest/runner.rb +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 357f54e47d0b81d02f32e097cc6a0ed43b850a144bd3d368cd1a29d8d7db9b8a
|
4
|
+
data.tar.gz: e60ae5e97ffb0a75a4c75792d0ff04e8d79a3daab5ad8eaf30a300ce6ad0a858
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c33d9188ecedb9b19b73b9bd0c0f7e88096d94101aa1e213dae692c6e1fe6b431f081fa7da19fcadaef1fc8984e7e7167e7f0ea269fc055a0d773afa228d6c19
|
7
|
+
data.tar.gz: 3901346f228ce16d193407fcd47cabadad28989e5d32c4d89d59bbf3344871021033b340663d634e1b3dc4478dc7e479be7351a7a7b546ba914b7de06add19c3
|
data/.github/workflows/ci.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.5
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
retest (1.
|
4
|
+
retest (1.6.0)
|
5
5
|
listen (~> 3.2)
|
6
6
|
string-similarity (~> 2.1)
|
7
7
|
tty-option (~> 0.1)
|
@@ -10,13 +10,13 @@ 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.5)
|
14
|
+
listen (3.7.1)
|
15
15
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
16
16
|
rb-inotify (~> 0.9, >= 0.9.10)
|
17
|
-
minitest (5.
|
17
|
+
minitest (5.15.0)
|
18
18
|
rake (12.3.3)
|
19
|
-
rb-fsevent (0.11.
|
19
|
+
rb-fsevent (0.11.1)
|
20
20
|
rb-inotify (0.10.1)
|
21
21
|
ffi (~> 1.0)
|
22
22
|
string-similarity (2.1.0)
|
data/README.md
CHANGED
@@ -6,7 +6,8 @@ Retest is a small command-line tool to help you refactor code by watching a file
|
|
6
6
|
|
7
7
|
## Demo
|
8
8
|
|
9
|
-
|
9
|
+
|
10
|
+
https://user-images.githubusercontent.com/7149034/153734043-1d136f27-5c24-4676-868b-0fde76016b13.mp4
|
10
11
|
|
11
12
|
## Installation
|
12
13
|
|
@@ -15,15 +16,52 @@ Install it on your machine without adding it on a Gemfile:
|
|
15
16
|
$ gem install retest
|
16
17
|
|
17
18
|
## Usage
|
18
|
-
### Refactoring
|
19
19
|
|
20
|
-
|
20
|
+
Retest is used in your terminal after accessing your ruby project folder.
|
21
|
+
|
22
|
+
### Help
|
23
|
+
|
24
|
+
Find out what retest can do anytime with
|
25
|
+
|
26
|
+
$ retest -h
|
27
|
+
|
28
|
+
### For Refactoring
|
29
|
+
|
30
|
+
#### 1. Run a hardcoded command
|
31
|
+
|
32
|
+
This the most simple usage of retest: running the same command over and over after each file update.
|
33
|
+
|
34
|
+
Example:
|
21
35
|
|
22
|
-
|
36
|
+
$ retest 'bundle exec rspec spec/features/posts_spec.rb'
|
23
37
|
|
24
|
-
|
38
|
+
In this example, the feature spec `spec/features/posts_spec.rb` will be tested after any ruby file is updated.
|
25
39
|
|
26
|
-
|
40
|
+
#### 2. Run a dynamic command with placeholders
|
41
|
+
|
42
|
+
Retest provides few placeholders to help you run a command after every file change. The placeholders can be used on their own or together.
|
43
|
+
|
44
|
+
1. `<test>` placeholder
|
45
|
+
|
46
|
+
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.
|
47
|
+
|
48
|
+
Example:
|
49
|
+
|
50
|
+
$ retest 'bin/rails test <test>'
|
51
|
+
|
52
|
+
In this example, if `app/models/post.rb` is changed then retest will run `bin/rails test test/models/post_test.rb`
|
53
|
+
|
54
|
+
2. `<changed>` placeholder
|
55
|
+
|
56
|
+
You can use the placeholder `<changed>` to tell the gem where to put the changed file path in your command. When a file is changed, the gem will run the command with it.
|
57
|
+
|
58
|
+
Example:
|
59
|
+
|
60
|
+
$ retest 'rubocop <changed>'
|
61
|
+
|
62
|
+
In this example, if `app/models/post.rb` is changed then retest will run `rubocop app/models/post.rb`
|
63
|
+
|
64
|
+
#### 3. Run a dynamic command with shortcuts
|
27
65
|
|
28
66
|
Few shortcut flags exist to avoid writing the full test command.
|
29
67
|
|
@@ -31,75 +69,29 @@ Few shortcut flags exist to avoid writing the full test command.
|
|
31
69
|
$ retest --rails
|
32
70
|
$ retest --rake --all
|
33
71
|
|
34
|
-
|
72
|
+
#### 4. Let retest figure it all out
|
73
|
+
|
74
|
+
Let retest find your ruby setup and run the appropriate command using:
|
35
75
|
|
36
76
|
$ retest
|
37
77
|
$ retest --all
|
38
78
|
|
79
|
+
#### Running rules
|
80
|
+
|
39
81
|
The gem works as follows:
|
40
82
|
|
41
|
-
* When a file is changed, retest will run its matching test.
|
42
|
-
* When a test
|
83
|
+
* When a **ruby file** is changed, retest will run its matching test.
|
84
|
+
* When a **test file** is changed, retest will run the test file.
|
43
85
|
* When multiple matching test files are found, retest asks you to confirm the file and save the answer.
|
44
86
|
* When a test file is not found, retest runs the last run command or throw a 404.
|
45
87
|
|
46
|
-
###
|
88
|
+
### Pull request scans
|
47
89
|
|
48
|
-
You can diff a branch and test all the relevant test files before pushing your branch and trigger
|
90
|
+
You can diff a branch and test all the relevant test files before pushing your branch and trigger a full CI suite.
|
49
91
|
|
50
92
|
$ retest --diff origin/main
|
51
93
|
|
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
|
70
|
-
command
|
71
|
-
--diff=git-branch Pipes all matching tests from diffed branch to test
|
72
|
-
command
|
73
|
-
-h, --help Print usage
|
74
|
-
--rails Shortcut for a standard Rails setup
|
75
|
-
--rake Shortcut for a standard Rake setup
|
76
|
-
--rspec Shortcut for a standard RSpec setup
|
77
|
-
--ruby Shortcut for a Ruby project
|
78
|
-
|
79
|
-
Examples:
|
80
|
-
Runs a matching rails test after a file change
|
81
|
-
$ retest 'bundle exec rails test <test>'
|
82
|
-
$ retest --rails
|
83
|
-
|
84
|
-
Runs all rails tests after a file change
|
85
|
-
$ retest 'bundle exec rails test'
|
86
|
-
$ retest --rails --all
|
87
|
-
|
88
|
-
Runs a hardcoded command after a file change
|
89
|
-
$ retest 'ruby lib/bottles_test.rb'
|
90
|
-
|
91
|
-
Let retest identify which command to run
|
92
|
-
$ retest
|
93
|
-
$ retest --auto
|
94
|
-
|
95
|
-
Let retest identify which command to run for all tests
|
96
|
-
$ retest --all
|
97
|
-
$ retest --auto --all
|
98
|
-
|
99
|
-
Run a sanity check on changed files from a branch
|
100
|
-
$ retest --diff origin/main --rails
|
101
|
-
$ retest --diff main --auto
|
102
|
-
```
|
94
|
+
In this example, retest lists all the files changed between `HEAD` and `origin/main`, finds all the relevant tests and only run those.
|
103
95
|
|
104
96
|
## Why?
|
105
97
|
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.
|
@@ -111,8 +103,12 @@ For fully fledged solutions, some cli tools already exists: [autotest](https://g
|
|
111
103
|
## Docker
|
112
104
|
|
113
105
|
Retest works in Docker too. You can install the gem and launch retest in your container while refactoring.
|
106
|
+
|
114
107
|
```bash
|
115
|
-
|
108
|
+
# Enter your container. Ex:
|
109
|
+
$ docker-compose run web bash
|
110
|
+
|
111
|
+
# Install the gem and run retest in your container shell
|
116
112
|
$ gem install retest
|
117
113
|
$ retest 'bundle exec rails test <test>'
|
118
114
|
```
|
@@ -131,12 +127,13 @@ Retest supports ruby 2.4 and above.
|
|
131
127
|
- [x] When multiple test files are found, ask which file to run and save the answer.
|
132
128
|
- [x] When a test file is not found run the last command again.
|
133
129
|
- [x] Run within Docker.
|
134
|
-
- [
|
130
|
+
- [x] Handle main Ruby setups
|
135
131
|
- [x] Bundler Gem
|
136
132
|
- [x] Rails
|
137
133
|
- [x] Ad-hoc scripts
|
138
134
|
- [x] Hanami
|
139
|
-
- [ ] Handle other languages: Elixir, Node, Python, PHP
|
135
|
+
- [ ] Handle other languages: Go, Elixir, Node, Python, PHP
|
136
|
+
- [ ] Go (project started)
|
140
137
|
- [ ] Aliases from oh-my-zsh and bash profiles?
|
141
138
|
|
142
139
|
## Development
|
@@ -149,7 +146,6 @@ To run integration tests on one setup (ex: hanami-app): `bin/test/hanami-app`
|
|
149
146
|
|
150
147
|
To access an app container (ex: ruby-app): `docker-compose -f features/ruby-app/docker-compose.yml run retest sh`
|
151
148
|
|
152
|
-
|
153
149
|
## Contributing
|
154
150
|
|
155
151
|
Bug reports and pull requests are welcome on GitHub at https://github.com/alexb52/retest.
|
data/bin/debug
CHANGED
@@ -15,9 +15,14 @@ end
|
|
15
15
|
|
16
16
|
repository = Retest::Repository.new(files: Retest::VersionControl.files)
|
17
17
|
command = Retest::Command.for_options(options)
|
18
|
-
runner = Retest::
|
18
|
+
runner = Retest::Runners.runner_for(command.to_s)
|
19
|
+
sounds = Retest::Sounds.for(options)
|
20
|
+
|
21
|
+
sounds.play(:tests_pass)
|
22
|
+
runner.add_observer(sounds)
|
19
23
|
|
20
24
|
program = Retest::Program.new(
|
25
|
+
extension: options.extension,
|
21
26
|
repository: repository,
|
22
27
|
command: command,
|
23
28
|
runner: runner
|
data/exe/retest
CHANGED
@@ -13,9 +13,14 @@ end
|
|
13
13
|
|
14
14
|
repository = Retest::Repository.new(files: Retest::VersionControl.files)
|
15
15
|
command = Retest::Command.for_options(options)
|
16
|
-
runner = Retest::
|
16
|
+
runner = Retest::Runners.runner_for(command.to_s)
|
17
|
+
sounds = Retest::Sounds.for(options)
|
18
|
+
|
19
|
+
sounds.play(:tests_pass)
|
20
|
+
runner.add_observer(sounds)
|
17
21
|
|
18
22
|
program = Retest::Program.new(
|
23
|
+
extension: options.extension,
|
19
24
|
repository: repository,
|
20
25
|
command: command,
|
21
26
|
runner: runner
|
data/lib/retest/command/rails.rb
CHANGED
data/lib/retest/command/rake.rb
CHANGED
data/lib/retest/command/rspec.rb
CHANGED
data/lib/retest/command/ruby.rb
CHANGED
@@ -8,9 +8,8 @@ module Retest
|
|
8
8
|
@all = all
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
runner.run %Q{-e "#{paths}"}
|
11
|
+
def format_batch(*files)
|
12
|
+
%Q{-e "#{files.map { |file| "require './#{file}';" }.join}"}
|
14
13
|
end
|
15
14
|
|
16
15
|
def to_s
|
data/lib/retest/options.rb
CHANGED
@@ -60,6 +60,12 @@ module Retest
|
|
60
60
|
long "--diff=git-branch"
|
61
61
|
end
|
62
62
|
|
63
|
+
option :ext do
|
64
|
+
desc "Regex of file extensions to listen to"
|
65
|
+
long "--ext=regex"
|
66
|
+
default "\\.rb$"
|
67
|
+
end
|
68
|
+
|
63
69
|
flag :all do
|
64
70
|
long "--all"
|
65
71
|
desc "Run all the specs of a specificied ruby setup"
|
@@ -70,6 +76,11 @@ module Retest
|
|
70
76
|
desc "Indentify repository setup and runs appropriate command"
|
71
77
|
end
|
72
78
|
|
79
|
+
flag :notify do
|
80
|
+
long "--notify"
|
81
|
+
desc "Play a sound when specs pass or fail (macOS only)"
|
82
|
+
end
|
83
|
+
|
73
84
|
flag :help do
|
74
85
|
short "-h"
|
75
86
|
long "--help"
|
@@ -124,10 +135,18 @@ module Retest
|
|
124
135
|
params[:auto]
|
125
136
|
end
|
126
137
|
|
138
|
+
def notify?
|
139
|
+
params[:notify]
|
140
|
+
end
|
141
|
+
|
142
|
+
def extension
|
143
|
+
Regexp.new(params[:ext])
|
144
|
+
end
|
145
|
+
|
127
146
|
private
|
128
147
|
|
129
148
|
def no_options_passed?
|
130
|
-
params.to_h.values.compact.uniq == [false]
|
149
|
+
params.to_h.values.compact.uniq == ["\\.rb$", false]
|
131
150
|
end
|
132
151
|
end
|
133
152
|
end
|
data/lib/retest/program.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module Retest
|
2
2
|
class Program
|
3
|
-
attr_accessor :runner, :repository, :command
|
4
|
-
def initialize(runner: nil, repository: nil, command: nil)
|
3
|
+
attr_accessor :runner, :repository, :command, :extension
|
4
|
+
def initialize(runner: nil, repository: nil, command: nil, extension: /\.rb$/)
|
5
5
|
@runner = runner
|
6
6
|
@repository = repository
|
7
7
|
@command = command
|
8
|
+
@extension = extension
|
8
9
|
end
|
9
10
|
|
10
11
|
def start
|
@@ -21,28 +22,23 @@ module Retest
|
|
21
22
|
test_files.each { |test_file| puts " - #{test_file}" }
|
22
23
|
|
23
24
|
puts "Running tests..."
|
24
|
-
command.
|
25
|
+
runner.run_all_tests command.format_batch(test_files)
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
29
30
|
def build
|
30
|
-
Listen.to('.', only:
|
31
|
+
Listen.to('.', only: extension, relative: true) do |modified, added, removed|
|
31
32
|
begin
|
32
|
-
repository.
|
33
|
-
|
34
|
-
runner.remove(removed)
|
33
|
+
repository.sync(added: added, removed: removed)
|
34
|
+
runner.sync(added: added, removed: removed)
|
35
35
|
system('clear 2>/dev/null') || system('cls 2>/dev/null')
|
36
36
|
|
37
|
-
runner.run
|
37
|
+
runner.run (modified + added).first, repository: repository
|
38
38
|
rescue => e
|
39
39
|
puts "Something went wrong: #{e.message}"
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
44
|
-
def test_file_to_run(changed_files)
|
45
|
-
repository.find_test changed_files.first if runner.matching?
|
46
|
-
end
|
47
43
|
end
|
48
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_run 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,36 @@
|
|
1
|
+
module Retest
|
2
|
+
module Runners
|
3
|
+
class Runner
|
4
|
+
include Observable
|
5
|
+
|
6
|
+
attr_accessor :command
|
7
|
+
def initialize(command)
|
8
|
+
@command = command
|
9
|
+
end
|
10
|
+
|
11
|
+
def ==(obj)
|
12
|
+
command == obj.command && obj.class == self.class
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(changed_file = nil, repository: nil)
|
16
|
+
system_run command
|
17
|
+
end
|
18
|
+
|
19
|
+
def run_all_tests(tests_string)
|
20
|
+
puts "Test File Selected: #{tests_string}"
|
21
|
+
system_run command.gsub('<test>', tests_string)
|
22
|
+
end
|
23
|
+
|
24
|
+
def sync(added:, removed:)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def system_run(command)
|
30
|
+
result = system(command) ? :tests_pass : :tests_fail
|
31
|
+
changed
|
32
|
+
notify_observers(result)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Retest
|
2
|
+
module Runners
|
3
|
+
class TestRunner < 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
|
+
if cached_test_file
|
16
|
+
puts "Test File Selected: #{cached_test_file}"
|
17
|
+
system_run command.gsub('<test>', cached_test_file)
|
18
|
+
else
|
19
|
+
puts <<~ERROR
|
20
|
+
404 - Test File Not Found
|
21
|
+
Retest could not find a matching test file to run.
|
22
|
+
ERROR
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def sync(added:, removed:)
|
27
|
+
remove(removed)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def remove(purged)
|
33
|
+
return if purged.empty?
|
34
|
+
|
35
|
+
if purged.is_a? Array
|
36
|
+
purge_cache if purged.include? cached_test_file
|
37
|
+
elsif purged.is_a? String
|
38
|
+
purge_cache if purged == cached_test_file
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def purge_cache
|
43
|
+
@cached_test_file = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
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_run 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
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Retest
|
2
|
+
module Sounds
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def for(options)
|
6
|
+
options.notify? ? MacOS.new : Mute.new
|
7
|
+
end
|
8
|
+
|
9
|
+
class Mute
|
10
|
+
def play(_)
|
11
|
+
end
|
12
|
+
alias update play
|
13
|
+
end
|
14
|
+
|
15
|
+
class MacOS
|
16
|
+
def initialize(kernel: Kernel, thread: Thread)
|
17
|
+
@kernel = kernel
|
18
|
+
@thread = thread
|
19
|
+
end
|
20
|
+
|
21
|
+
def play(sound)
|
22
|
+
args = case sound
|
23
|
+
when :tests_fail
|
24
|
+
['afplay', '/System/Library/Sounds/Sosumi.aiff']
|
25
|
+
when :tests_pass
|
26
|
+
['afplay', '/System/Library/Sounds/Funk.aiff']
|
27
|
+
else
|
28
|
+
raise ArgumentError.new("No sounds were found for type: #{sound}.")
|
29
|
+
end
|
30
|
+
|
31
|
+
@thread.new { @kernel.system(*args) }
|
32
|
+
end
|
33
|
+
alias update play
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/retest/version.rb
CHANGED
data/lib/retest.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'listen'
|
2
2
|
require 'string/similarity'
|
3
|
+
require 'observer'
|
3
4
|
|
4
5
|
require "retest/version"
|
5
|
-
require "retest/
|
6
|
+
require "retest/runners"
|
6
7
|
require "retest/repository"
|
7
8
|
require "retest/test_options"
|
8
9
|
require "retest/options"
|
@@ -11,6 +12,7 @@ require "retest/setup"
|
|
11
12
|
require "retest/command"
|
12
13
|
require "retest/file_system"
|
13
14
|
require "retest/program"
|
15
|
+
require "retest/sounds"
|
14
16
|
|
15
17
|
module Retest
|
16
18
|
class Error < StandardError; 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.6.0
|
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:
|
11
|
+
date: 2022-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.1'
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- alex@abletech.nz
|
58
58
|
executables:
|
@@ -90,8 +90,13 @@ files:
|
|
90
90
|
- lib/retest/options.rb
|
91
91
|
- lib/retest/program.rb
|
92
92
|
- lib/retest/repository.rb
|
93
|
-
- 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
|
94
98
|
- lib/retest/setup.rb
|
99
|
+
- lib/retest/sounds.rb
|
95
100
|
- lib/retest/test_options.rb
|
96
101
|
- lib/retest/version.rb
|
97
102
|
- lib/retest/version_control.rb
|
@@ -104,7 +109,7 @@ licenses:
|
|
104
109
|
metadata:
|
105
110
|
homepage_uri: https://github.com/AlexB52/retest
|
106
111
|
source_code_uri: https://github.com/AlexB52/retest
|
107
|
-
post_install_message:
|
112
|
+
post_install_message:
|
108
113
|
rdoc_options: []
|
109
114
|
require_paths:
|
110
115
|
- lib
|
@@ -119,8 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
124
|
- !ruby/object:Gem::Version
|
120
125
|
version: '0'
|
121
126
|
requirements: []
|
122
|
-
rubygems_version: 3.
|
123
|
-
signing_key:
|
127
|
+
rubygems_version: 3.1.6
|
128
|
+
signing_key:
|
124
129
|
specification_version: 4
|
125
130
|
summary: A simple command line tool to watch file change and run its matching spec.
|
126
131
|
test_files: []
|
data/lib/retest/runner.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
module Retest
|
2
|
-
class Runner
|
3
|
-
def self.for(test_command)
|
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 && obj.class == self.class
|
21
|
-
end
|
22
|
-
|
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
|
35
|
-
puts "Test File Selected: #{cached_test_file}"
|
36
|
-
system command.gsub('<test>', cached_test_file)
|
37
|
-
else
|
38
|
-
puts <<~ERROR
|
39
|
-
404 - Test File Not Found
|
40
|
-
Retest could not find a matching test file to run.
|
41
|
-
ERROR
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
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
|
-
def unmatching?
|
56
|
-
!matching?
|
57
|
-
end
|
58
|
-
|
59
|
-
def matching?
|
60
|
-
true
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def purge_cache
|
66
|
-
@cached_test_file = nil
|
67
|
-
end
|
68
|
-
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
|
-
end
|
86
|
-
end
|