You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Retest 2.0 is now available as a pre-release! You can try it out with `gem install retest --pre`.
3
+
### Retest 2.0 is now available!
4
4
5
5
Feedback is welcome in this [Discussion - Retest V2.0 - Interactive Panel (proof of concept)](https://github.com/AlexB52/retest/discussions/216)
6
6
7
7
# Retest
8
8
9
-
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)
9
+
A trusty CLI companion to monitor file changes and automatically run the corresponding Ruby specs. Ready to assist on any Ruby project, no setup needed! 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)
In this example, the feature spec `spec/features/posts_spec.rb` will be tested after any ruby file is updated.
25
+
## Watching tools: Watchexec & Listen
43
26
44
-
#### 2. Run a dynamic command with placeholders
27
+
By default retest ships with [Listen](https://github.com/guard/listen) which is used to listen to file changes.
45
28
46
-
Retest provides few placeholders to help you run a command after every file change. The placeholders can be used on their own or together.
29
+
Retest will use [watchexec](https://github.com/watchexec/watchexec) a more performant file watcher when installed on the matchine. watchexec will only work with a version >= 2.2.0
47
30
48
-
1.`<test>` placeholder
31
+
To force the usage of a watcher you can use the `-w` option as `retest -w watchexec`
49
32
50
-
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.
33
+
## Usage
51
34
52
-
Example:
35
+
Retest is used in your terminal after accessing your ruby project folder.
53
36
54
-
$ retest 'bin/rails test <test>'
55
-
56
-
In this example, if `app/models/post.rb` is changed then retest will run `bin/rails test test/models/post_test.rb`
57
-
58
-
2.`<changed>` placeholder
59
-
60
-
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.
37
+
### Help
61
38
62
-
Example:
39
+
Find out what retest can do anytime with
63
40
64
-
$ retest 'rubocop <changed>'
65
-
66
-
In this example, if `app/models/post.rb` is changed then retest will run `rubocop app/models/post.rb`
41
+
$ retest -h
67
42
68
-
#### 3. Run a dynamic command with shortcuts
43
+
Here is a quick summary:
69
44
70
-
Few shortcut flags exist to avoid writing the full test command.
45
+
* run a hardcoded command: `retest 'bin/rails test test/models/post_test.rb'`
46
+
* use placeholders: `retest 'bin/rails test <test> && rubocop <changed>`
47
+
* play a sound for feedback: `retest --notify`
48
+
* run all specs when a file change: `retest --all`
49
+
* run all matching specs from a diffed branch: `retest --diff origin/main`
71
50
72
-
$ retest --rspec
73
-
$ retest --rails
74
-
$ retest --rake --all
51
+
### Interactive companion
75
52
76
-
#### 4. Let retest figure it all out
53
+
An interactive shell will start when launching retest to help your testing workflow. Enter 'h' to see all the options.
77
54
78
-
Let retest find your ruby setup and run the appropriate command using:
55
+
```
56
+
Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=<test>'
57
+
Watcher: [WATCHEXEC]
58
+
Launching Retest...
59
+
Ready to refactor! You can make file changes now
60
+
61
+
Type interactive command and press enter. Enter 'h' for help.
62
+
> h
63
+
64
+
* 'h', 'help' # Prints help.
65
+
* 'p', 'pause' # Pauses Retest. Tests aren't run on file change events until unpaused.
66
+
* 'u', 'unpause' # Unpauses Retest.
67
+
* <ENTER> # Runs last changed triggered command.
68
+
* 'ra, 'run all' # Runs all tests.
69
+
* 'f', 'force' # Forces a selection of test to run on every file change.
70
+
* 'r', 'reset' # Disables forced selection.
71
+
* 'd', 'diff' [GIT BRANCH] # Runs matching specs that changed from a target branch.
72
+
* 'c' # Clears window.
73
+
* 'e', 'exit' # Exits Retest.
79
74
80
-
$ retest
81
-
$ retest --all
75
+
```
76
+
### Running rules
82
77
83
-
#### Running rules
78
+
When on a forced selection, retest will run the forced selection regardless of the file changed.
84
79
85
-
The gem works as follows:
80
+
Otherwise, the gem works as follows:
86
81
87
82
* When a **ruby file** is changed, retest will run its matching test.
88
83
* When a **test file** is changed, retest will run the test file.
89
84
* When multiple matching test files are found, retest asks you to confirm the file and save the answer.
90
85
* When a test file is not found, retest runs the last run command or throw a 404.
91
86
92
-
### Pull request scans
93
-
94
-
You can diff a branch and test all the relevant test files before pushing your branch and trigger a full CI suite.
95
-
96
-
$ retest --diff origin/main
97
-
98
-
In this example, retest lists all the files changed between `HEAD` and `origin/main`, finds all the relevant tests and only run those.
99
-
100
87
## Why?
101
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.
* If an error comes in try using `bundle exec` like so: `$ retest 'bundle exec rake test <test>'`
122
109
* Aliases saved on ~/.bashrc or ~/.zshrc cannot be run that way with the `retest` command
123
110
124
-
## Ruby Support
125
-
126
-
Retest supports ruby 2.5 and above.
127
-
128
-
## Roadmap
129
-
130
-
-[x] MVP
131
-
-[x] When multiple test files are found, ask which file to run and save the answer.
132
-
-[x] When a test file is not found run the last command again.
133
-
-[x] Run within Docker.
134
-
-[x] Handle main Ruby setups
135
-
-[x] Bundler Gem
136
-
-[x] Rails
137
-
-[x] Ad-hoc scripts
138
-
-[x] Hanami
139
-
-[ ] Handle other languages: Go, Elixir, Node, Python, PHP
140
-
-[ ] Go (project started)
141
-
-[ ] Aliases from oh-my-zsh and bash profiles?
142
-
143
111
## Development
144
112
145
113
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
0 commit comments