retest 2.0.0.pre5 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 754751292557705217a2e6010b5fda60d10fffbdf5a1b66ffe48976841407e09
4
- data.tar.gz: 2156346b0cd5caa0d5dcf329391a0b84a85fc88342a97fe2e3150ba196fdd7c5
3
+ metadata.gz: 772460d70195233b6c33f61abced4021e2f1d106aac1022a3a4514d773b5d32b
4
+ data.tar.gz: 6bfe550e9d14a25683e370bcb0be89f5053f3f0a354e02fe617688c207694c0d
5
5
  SHA512:
6
- metadata.gz: 328df6d6fe4153956230bb4029337f68f20ef8a796337b7c423ce2cd07ddf01ce3c69d531e3daac5babe17dae6c266053919246f6f2e93e69ecf56704cf52cc1
7
- data.tar.gz: ea86b8e02ddced2b484c780ca8ec673098d23a8e86cde6f0f11b15d903e7206bcb88840b61438aa947cbac4b72c34ad8831bc2d2c76f205c6bcf2f73ff75a97f
6
+ metadata.gz: 5eb9b44d3b77b657e00a9c126db20a20c5b63a7ab531e36d7653e29858a7f7a8f150530693c1863a687920e3e1097f6f43417530fe9b0180f6d2e0812929a6c1
7
+ data.tar.gz: '0584210958831b1223f8e068f05f2a6ebae28df0316eeca61900a0f1efdbe7c28ca4af1ca8ec4c777fffbf64aba7a2f2ebd892aaac601ab40ea71200451b37ed'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retest (2.0.0.pre5)
4
+ retest (2.0.0)
5
5
  listen (~> 3.9)
6
6
  observer (~> 0.1)
7
7
  string-similarity (~> 2.1)
data/README.md CHANGED
@@ -1,156 +1,101 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/retest.svg)](https://badge.fury.io/rb/retest)
2
2
 
3
- # Retest
3
+ # Retest: Your Go-To Testing Assistant for Ruby Projects
4
4
 
5
- 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)
5
+ Retest is the ultimate CLI tool for Ruby developers, designed to make your testing workflow seamless and efficient. It monitors file changes and automatically runs relevant tests, ensuring that your code remains solid as you refactor and develop.
6
6
 
7
- ## Demo
7
+ With **zero setup required**, Retest works right out of the box on any Ruby project—no changes to your Gemfile, no unnecessary repo clutter, and no configuration headaches. It's lightweight, dev-centric, and ready to integrate into your workflow instantly.
8
8
 
9
+ ## 🚀 **What Makes Retest Awesome?**
9
10
 
10
- https://user-images.githubusercontent.com/7149034/153734043-1d136f27-5c24-4676-868b-0fde76016b13.mp4
11
+ - **Plug-and-Play:** Start testing immediately—no installation hassles or setup scripts.
12
+ - **Project Independence:** Works with any Ruby project, no Gemfile modifications required.
13
+ - **Time-Saving Automation:** Automatically identifies and runs relevant tests as you code.
14
+ - **Customizable Workflows:** Tailor commands to your needs with placeholders, options, and interactive features.
15
+ - **Sound Notifications:** Get audible feedback for test results.
11
16
 
12
- ## Installation
17
+ ## 💡 **Why Use Retest?**
13
18
 
14
- Install it on your machine without adding it on a Gemfile:
19
+ Testing frequently is the cornerstone of safe refactoring. Retest eliminates the friction of manual test execution by running tests after every file change, helping you stay just one `cmd + z` away from green tests.
15
20
 
16
- $ gem install retest
21
+ ## 🔧 **Quick Installation**
17
22
 
18
- ## Usage
23
+ Install Retest globally in seconds:
19
24
 
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:
35
-
36
- $ retest 'bundle exec rspec spec/features/posts_spec.rb'
37
-
38
- In this example, the feature spec `spec/features/posts_spec.rb` will be tested after any ruby file is updated.
39
-
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
65
-
66
- Few shortcut flags exist to avoid writing the full test command.
67
-
68
- $ retest --rspec
69
- $ retest --rails
70
- $ retest --rake --all
71
-
72
- #### 4. Let retest figure it all out
73
-
74
- Let retest find your ruby setup and run the appropriate command using:
75
-
76
- $ retest
77
- $ retest --all
78
-
79
- #### Running rules
80
-
81
- The gem works as follows:
82
-
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.
85
- * When multiple matching test files are found, retest asks you to confirm the file and save the answer.
86
- * When a test file is not found, retest runs the last run command or throw a 404.
87
-
88
- ### Pull request scans
89
-
90
- You can diff a branch and test all the relevant test files before pushing your branch and trigger a full CI suite.
91
-
92
- $ retest --diff origin/main
93
-
94
- In this example, retest lists all the files changed between `HEAD` and `origin/main`, finds all the relevant tests and only run those.
95
-
96
- ## Why?
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.
98
-
99
- 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.
100
-
101
- 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)
25
+ ```bash
26
+ gem install retest
27
+ ```
102
28
 
103
- ## Docker
29
+ No need to add it to your Gemfile—just install and go!
104
30
 
105
- Retest works in Docker too. You can install the gem and launch retest in your container while refactoring.
31
+ ## 🛠️ **Key Features**
106
32
 
33
+ ### **Flexible Commands**
34
+ Run tests with your preferred commands, placeholders, or patterns:
107
35
  ```bash
108
- # Enter your container. Ex:
109
- $ docker-compose run web bash
110
-
111
- # Install the gem and run retest in your container shell
112
- $ gem install retest
113
- $ retest 'bundle exec rails test <test>'
36
+ retest 'bin/rails test <test> && rubocop <changed>' # Flexible placeholders
37
+ retest --all # Run all tests on every file change
38
+ retest --diff origin/main # Test changes from a branch
114
39
  ```
115
40
 
116
- ## Disclaimer
117
- * If an error comes in try using `bundle exec` like so: `$ retest 'bundle exec rake test <test>'`
118
- * Aliases saved on ~/.bashrc or ~/.zshrc cannot be run that way with the `retest` command
41
+ ### **Interactive Companion**
42
+ Stay in control with an interactive shell for test management. Start Retest and enter `h` to explore available commands.
119
43
 
120
- ## Ruby Support
44
+ ```
45
+ Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=<test>'
46
+ Watcher: [WATCHEXEC]
47
+ Launching Retest...
48
+ Ready to refactor! You can make file changes now
49
+
50
+ Type interactive command and press enter. Enter 'h' for help.
51
+ > h
52
+
53
+ * 'h', 'help' # Prints help.
54
+ * 'p', 'pause' # Pauses Retest. Tests aren't run on file change events until unpaused.
55
+ * 'u', 'unpause' # Unpauses Retest.
56
+ * <ENTER> # Runs last changed triggered command.
57
+ * 'ra, 'run all' # Runs all tests.
58
+ * 'f', 'force' # Forces a selection of test to run on every file change.
59
+ * 'r', 'reset' # Disables forced selection.
60
+ * 'd', 'diff' [GIT BRANCH] # Runs matching specs that changed from a target branch.
61
+ * 'c' # Clears window.
62
+ * 'e', 'exit' # Exits Retest.
121
63
 
122
- Retest supports ruby 2.5 and above.
64
+ ```
65
+ ### **Supports Multiple Watchers**
66
+ Retest ships with [Listen](https://github.com/guard/listen) for file monitoring but can use the more performant [Watchexec](https://github.com/watchexec/watchexec) if installed.
123
67
 
124
- ## Roadmap
68
+ To force a specific watcher:
69
+ ```bash
70
+ retest -w watchexec
71
+ ```
125
72
 
126
- - [x] MVP
127
- - [x] When multiple test files are found, ask which file to run and save the answer.
128
- - [x] When a test file is not found run the last command again.
129
- - [x] Run within Docker.
130
- - [x] Handle main Ruby setups
131
- - [x] Bundler Gem
132
- - [x] Rails
133
- - [x] Ad-hoc scripts
134
- - [x] Hanami
135
- - [ ] Handle other languages: Go, Elixir, Node, Python, PHP
136
- - [ ] Go (project started)
137
- - [ ] Aliases from oh-my-zsh and bash profiles?
73
+ ## 🐳 **Works with Docker**
138
74
 
139
- ## Development
75
+ Retest can run inside Docker containers, ensuring your testing workflow stays consistent across environments.
140
76
 
141
- 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.
77
+ ```bash
78
+ # Inside your container shell
79
+ gem install retest
80
+ retest 'bundle exec rails test <test>'
81
+ ```
142
82
 
143
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
83
+ ## ❤️ **Contributing**
144
84
 
145
- To run integration tests on one setup (ex: hanami-app): `bin/test/hanami-app`
85
+ Got feedback or ideas? Join the discussion for Retest 2.0 and share your thoughts:
86
+ [Discussion - Retest V2.0 - Interactive Panel](https://github.com/AlexB52/retest/discussions/216)
146
87
 
147
- To access an app container (ex: ruby-app): `docker-compose -f features/ruby-app/docker-compose.yml run retest sh`
88
+ Bug reports and pull requests are welcome at [GitHub](https://github.com/alexb52/retest).
148
89
 
149
- ## Contributing
90
+ ## 🛠️ **Development**
150
91
 
151
- Bug reports and pull requests are welcome on GitHub at https://github.com/alexb52/retest.
92
+ Want to contribute to Retest? Follow these steps to set up your environment
152
93
 
94
+ 1. Clone the repo and install dependencies: `bin/setup`
95
+ 2. Run tests to ensure everything is working: `rake test`
96
+ 3. Experiment with an interactive console: `bin/console`
97
+ 4. To run integration tests (e.g., for a Hanami app): `bin/test/hanami-app`
153
98
 
154
- ## License
99
+ ## 📜 **License**
155
100
 
156
- The gem is available as open-source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
101
+ Retest is open-source and available under the [MIT License](https://opensource.org/licenses/MIT).
data/bin/test/bundler-app CHANGED
@@ -1,7 +1,14 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
+ FOLDER="features/bundler-app"
4
+
3
5
  bundle install
4
6
  bundle exec rake build
5
7
  cp -R features/support features/bundler-app/retest
6
- ls -t pkg | head -n1 | xargs -I {} mv pkg/{} features/bundler-app/retest.gem
7
- docker compose -f features/bundler-app/docker-compose.yml up --build --exit-code-from retest
8
+ ls -t pkg | head -n1 | xargs -I {} mv pkg/{} "$FOLDER/retest.gem"
9
+
10
+ if [[ "$1" == "--no-build" ]]; then
11
+ docker compose -f "$FOLDER/docker-compose.yml" up --exit-code-from retest
12
+ else
13
+ docker compose -f "$FOLDER/docker-compose.yml" up --build --exit-code-from retest
14
+ fi
data/bin/test/ruby-app CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  bundle install
4
4
  bundle exec rake build
5
- # cp -R features/support features/ruby-app/retest
5
+ cp -R features/support features/ruby-app/retest
6
6
  ls -t pkg | head -n1 | xargs -I {} mv pkg/{} features/ruby-app/retest.gem
7
7
  docker compose -f features/ruby-app/docker-compose.yml up --build --exit-code-from retest
data/exe/retest CHANGED
@@ -46,7 +46,7 @@ end
46
46
 
47
47
  if watcher == Retest::Watcher::Watchexec
48
48
  puts "Watcher: [WATCHEXEC]"
49
- else Retest::Watcher::Default
49
+ else
50
50
  puts "Watcher: [LISTEN]"
51
51
  end
52
52
 
@@ -71,7 +71,6 @@ end
71
71
  puts "Ready to refactor! You can make file changes now"
72
72
 
73
73
  def run_command(input:, program:)
74
- program.clear_terminal
75
74
  case input.strip
76
75
  when /^file changed:\s(.*)$/
77
76
  puts "File changed: #{$1}"
@@ -104,6 +103,8 @@ def run_command(input:, program:)
104
103
  program.run_all
105
104
  when /^di?f?f?\s(.*)$/
106
105
  program.diff($1)
106
+ when 'c'
107
+ program.clear_terminal
107
108
  when 'h', 'help'
108
109
  puts <<~HELP
109
110
 
@@ -115,6 +116,7 @@ def run_command(input:, program:)
115
116
  * 'f', 'force' # Forces a selection of test to run on every file change.
116
117
  * 'r', 'reset' # Disables forced selection.
117
118
  * 'd', 'diff' [GIT BRANCH] # Runs matching specs that changed from a target branch.
119
+ * 'c' # Clears window.
118
120
  * 'e', 'exit' # Exits Retest.
119
121
  HELP
120
122
  else
@@ -21,22 +21,6 @@ module Retest
21
21
  to_s.include?('<test>')
22
22
  end
23
23
 
24
- def changed_type?
25
- !has_test? && has_changed?
26
- end
27
-
28
- def test_type?
29
- has_test? && !has_changed?
30
- end
31
-
32
- def variable_type?
33
- has_test? && has_changed?
34
- end
35
-
36
- def hardcoded_type?
37
- !has_test? && !has_changed?
38
- end
39
-
40
24
  def to_s
41
25
  @command
42
26
  end
@@ -27,17 +27,20 @@ module Retest
27
27
  options_command || default_command
28
28
  end
29
29
 
30
+ private
31
+
30
32
  def options_command
31
- if params[:command]
32
- return hardcoded_command(params[:command])
33
+ if params[:command] then hardcoded_command(params[:command])
34
+ elsif params[:rspec] then rspec_command
35
+ elsif params[:rails] then rails_command
36
+ elsif params[:ruby] then ruby_command
37
+ elsif params[:rake] then rake_command
33
38
  end
39
+ end
34
40
 
35
- if params[:rspec] then rspec_command
36
- elsif params[:rails] then rails_command
37
- elsif params[:ruby] then ruby_command
38
- elsif params[:rake] then rake_command
39
- else
40
- end
41
+ def default_command
42
+ log "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'"
43
+ setup_command
41
44
  end
42
45
 
43
46
  def setup_command
@@ -50,13 +53,6 @@ module Retest
50
53
  end
51
54
  end
52
55
 
53
- def default_command
54
- log "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'"
55
- setup_command
56
- end
57
-
58
- private
59
-
60
56
  def log(message)
61
57
  @stdout&.puts(message)
62
58
  end
@@ -12,10 +12,9 @@ module Retest
12
12
  def_delegators :runner,
13
13
  :run_last_command, :last_command
14
14
 
15
- def initialize(runner: nil, repository: nil, clear_window: true, stdout: $stdout)
15
+ def initialize(runner: nil, repository: nil, stdout: $stdout)
16
16
  @runner = runner
17
17
  @repository = repository
18
- @clear_window = clear_window
19
18
  @stdout = stdout
20
19
  initialize_pause(false)
21
20
  initialize_forced_selection([])
@@ -61,8 +60,6 @@ module Retest
61
60
  end
62
61
 
63
62
  def clear_terminal
64
- return unless @clear_window
65
-
66
63
  system('clear 2>/dev/null') || system('cls 2>/dev/null')
67
64
  end
68
65
  end
data/lib/retest/prompt.rb CHANGED
@@ -9,27 +9,21 @@ module Retest
9
9
  @question_asked = false
10
10
  end
11
11
 
12
- def question_asked?
13
- @question_asked
14
- end
15
-
16
12
  def ask_which_test_to_use(path, files)
17
- ask_question do
18
- changed
19
- notify_observers(:question)
20
- options = options(files)
13
+ changed
14
+ notify_observers(:question)
15
+ options = options(files)
21
16
 
22
- output.puts(<<~QUESTION)
23
- We found few tests matching: #{path}
17
+ output.puts(<<~QUESTION)
18
+ We found few tests matching: #{path}
24
19
 
25
- #{list_options(options.keys)}
20
+ #{list_options(options.keys)}
26
21
 
27
- Which file do you want to use?
28
- Enter the file number now:
29
- QUESTION
30
- output.print("> ")
31
- options.values[input.gets.to_s.chomp.to_i]
32
- end
22
+ Which file do you want to use?
23
+ Enter the file number now:
24
+ QUESTION
25
+ output.print("> ")
26
+ options.values[input.gets.to_s.chomp.to_i]
33
27
  end
34
28
 
35
29
  def puts(*args)
@@ -40,14 +34,6 @@ module Retest
40
34
  output.tap(&:rewind).read
41
35
  end
42
36
 
43
- def ask_question
44
- old_question_asked = @question_asked
45
- @question_asked = true
46
- yield
47
- ensure
48
- @question_asked = old_question_asked
49
- end
50
-
51
37
  private
52
38
 
53
39
  def options(files, blank_option: 'none')
data/lib/retest/runner.rb CHANGED
@@ -6,9 +6,7 @@ module Retest
6
6
  include Observable
7
7
  include CachedTestFile
8
8
 
9
- def_delegators :command,
10
- :has_changed?, :has_test?,
11
- :changed_type?, :test_type?, :variable_type?, :harcoded_type?
9
+ def_delegators :command, :has_changed?, :has_test?
12
10
 
13
11
  attr_accessor :command, :stdout, :last_command
14
12
  def initialize(command, stdout: $stdout)
@@ -30,7 +28,8 @@ module Retest
30
28
  end
31
29
 
32
30
  def run_all
33
- system_run command.clone(all: true).to_s
31
+ self.last_command = command.clone(all: true).to_s
32
+ system_run last_command
34
33
  end
35
34
 
36
35
  def format_instruction(changed_files: [], test_files: [])
data/lib/retest/setup.rb CHANGED
@@ -4,7 +4,7 @@ module Retest
4
4
  @type ||= begin
5
5
  return :ruby unless has_lock_file?
6
6
 
7
- if rspec? then :rspec
7
+ if rspec? then :rspec
8
8
  elsif rails? then :rails
9
9
  elsif rake? then :rake
10
10
  else :ruby
@@ -1,3 +1,3 @@
1
1
  module Retest
2
- VERSION = "2.0.0.pre5"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -5,7 +5,7 @@ module Retest
5
5
  when 'listen' then Default
6
6
  when 'watchexec' then Watchexec
7
7
  when '', 'installed' then installed
8
- else raise ArgumentError, "Unknown #{watcher}"
8
+ else raise ArgumentError, "Unknown #{watcher}"
9
9
  end
10
10
 
11
11
  unless tool.installed?
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: 2.0.0.pre5
4
+ version: 2.0.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: 2024-12-05 00:00:00.000000000 Z
11
+ date: 2024-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-similarity
@@ -156,11 +156,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
156
  version: 2.5.0
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - ">"
159
+ - - ">="
160
160
  - !ruby/object:Gem::Version
161
- version: 1.3.1
161
+ version: '0'
162
162
  requirements: []
163
- rubygems_version: 3.0.3.1
163
+ rubygems_version: 3.1.6
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: A simple command line tool to watch file change and run its matching spec.