retest 0.8.2 → 1.1.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 +3 -0
- data/Gemfile.lock +3 -3
- data/README.md +49 -21
- data/bin/debug +26 -0
- data/bin/test/git-ruby +6 -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/exe/retest +10 -2
- data/lib/retest.rb +29 -9
- data/lib/retest/command.rb +77 -0
- data/lib/retest/command/rails.rb +22 -0
- data/lib/retest/command/rake.rb +22 -0
- data/lib/retest/command/rspec.rb +22 -0
- data/lib/retest/command/ruby.rb +13 -0
- data/lib/retest/options.rb +43 -15
- data/lib/retest/repository.rb +14 -4
- data/lib/retest/runner.rb +16 -0
- data/lib/retest/setup.rb +45 -0
- data/lib/retest/version.rb +1 -1
- data/lib/retest/version_control.rb +3 -38
- data/lib/retest/version_control/git.rb +33 -0
- data/lib/retest/version_control/no_version_control.rb +15 -0
- metadata +14 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cec5f35b345630339ca56cfd0c1bc88be03596ca4d8369695f2e87f66e7c608
|
4
|
+
data.tar.gz: db0b1f966bb2ebe14183e17e93003c0d504881dc2a7d8fe2614f5c202b0fcf55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b191a17f73446b41fd5fdf9bc7495f4ea0535c05681e1d14e191cb62f6cadc83d09454ad501fc98ce503db6a169b628b6d205328ca4a236ddf56bbc75d78bff
|
7
|
+
data.tar.gz: e1089b2d8c64c380c2fd08935f8b0ded1dee4ccb2f265ff20c6f12eeea91942ef0e4c9a6a154b48a270a4c3281fa2e3edf981925f50c6767c98a2bbcbd1cd6f3
|
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 (
|
4
|
+
retest (1.1.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.
|
14
|
-
listen (3.
|
13
|
+
ffi (1.15.0)
|
14
|
+
listen (3.5.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)
|
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:
|
20
|
+
|
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:
|
32
|
+
|
33
|
+
$ retest
|
34
|
+
$ retest --auto
|
35
|
+
$ retest --auto --all
|
24
36
|
|
25
|
-
|
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.
|
26
43
|
|
27
|
-
|
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,28 @@ 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
|
85
|
+
|
86
|
+
Run a sanity check on changed files from a branch
|
87
|
+
$ retest --diff origin/main --rails
|
88
|
+
$ retest --diff main --auto
|
59
89
|
```
|
60
90
|
|
61
|
-
|
91
|
+
## Why?
|
92
|
+
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
93
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
* When a test file is not found, retest runs the last run command or throw a 404.
|
94
|
+
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.
|
95
|
+
|
96
|
+
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
97
|
|
68
|
-
|
98
|
+
## Docker
|
69
99
|
|
70
100
|
Retest works in Docker too. You can install the gem and launch retest in your container while refactoring.
|
71
101
|
```bash
|
@@ -74,7 +104,7 @@ $ gem install retest
|
|
74
104
|
$ retest 'bundle exec rails test <test>'
|
75
105
|
```
|
76
106
|
|
77
|
-
|
107
|
+
## Disclaimer
|
78
108
|
* If an error comes in try using `bundle exec` like so: `$ retest 'bundle exec rake test <test>'`
|
79
109
|
* Aliases saved on ~/.bashrc or ~/.zshrc cannot be run that way with the `retest` command
|
80
110
|
|
@@ -93,8 +123,6 @@ Retest supports ruby 2.4 and above.
|
|
93
123
|
- [x] Rails
|
94
124
|
- [x] Ad-hoc scripts
|
95
125
|
- [x] Hanami
|
96
|
-
- [ ] Sinatra
|
97
|
-
- [ ] Cuba? Padrino?
|
98
126
|
- [ ] Handle other languages: Elixir, Node, Python, PHP
|
99
127
|
- [ ] Aliases from oh-my-zsh and bash profiles?
|
100
128
|
|
data/bin/debug
ADDED
@@ -0,0 +1,26 @@
|
|
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
|
+
program = Retest::Program.new(
|
17
|
+
repository: Retest::Repository.new(files: Retest::VersionControl.files),
|
18
|
+
runner: Retest::Runner.for(Retest::Command.for_options(options))
|
19
|
+
)
|
20
|
+
|
21
|
+
if options.params[:diff]
|
22
|
+
program.diff(options.params[:diff])
|
23
|
+
else
|
24
|
+
program.start # not blocking
|
25
|
+
sleep
|
26
|
+
end
|
data/bin/test/git-ruby
ADDED
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/exe/retest
CHANGED
@@ -11,6 +11,14 @@ if options.help?
|
|
11
11
|
return
|
12
12
|
end
|
13
13
|
|
14
|
-
Retest.
|
14
|
+
program = Retest::Program.new(
|
15
|
+
repository: Retest::Repository.new(files: Retest::VersionControl.files),
|
16
|
+
runner: Retest::Runner.for(Retest::Command.for_options(options))
|
17
|
+
)
|
15
18
|
|
16
|
-
|
19
|
+
if options.params[:diff]
|
20
|
+
program.diff(options.params[:diff])
|
21
|
+
else
|
22
|
+
program.start # not blocking
|
23
|
+
sleep
|
24
|
+
end
|
data/lib/retest.rb
CHANGED
@@ -7,23 +7,39 @@ require "retest/repository"
|
|
7
7
|
require "retest/test_options"
|
8
8
|
require "retest/options"
|
9
9
|
require "retest/version_control"
|
10
|
+
require "retest/setup"
|
11
|
+
require "retest/command"
|
10
12
|
|
11
13
|
module Retest
|
12
14
|
class Error < StandardError; end
|
13
15
|
|
14
|
-
class
|
15
|
-
|
16
|
+
class Program
|
17
|
+
attr_accessor :runner, :repository
|
18
|
+
def initialize(runner: nil, repository: nil)
|
19
|
+
@runner = runner
|
20
|
+
@repository = repository
|
21
|
+
end
|
22
|
+
|
23
|
+
def start
|
16
24
|
puts "Launching Retest..."
|
25
|
+
build.start
|
26
|
+
puts "Ready to refactor! You can make file changes now"
|
27
|
+
end
|
17
28
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
).start
|
29
|
+
def diff(branch)
|
30
|
+
raise "Git not installed" unless VersionControl::Git.installed?
|
31
|
+
test_files = repository.find_tests VersionControl::Git.diff_files(branch)
|
22
32
|
|
23
|
-
puts "
|
33
|
+
puts "Tests found:"
|
34
|
+
test_files.each { |test_file| puts " - #{test_file}" }
|
35
|
+
|
36
|
+
puts "Running tests..."
|
37
|
+
test_files.each { |test_file| runner.run test_file }
|
24
38
|
end
|
25
39
|
|
26
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
def build
|
27
43
|
Listen.to('.', only: /\.rb$/, relative: true) do |modified, added, removed|
|
28
44
|
begin
|
29
45
|
repository.add(added)
|
@@ -31,11 +47,15 @@ module Retest
|
|
31
47
|
runner.remove(removed)
|
32
48
|
system('clear 2>/dev/null') || system('cls 2>/dev/null')
|
33
49
|
|
34
|
-
runner.run
|
50
|
+
runner.run test_file_to_run(modified + added)
|
35
51
|
rescue => e
|
36
52
|
puts "Something went wrong: #{e.message}"
|
37
53
|
end
|
38
54
|
end
|
39
55
|
end
|
56
|
+
|
57
|
+
def test_file_to_run(changed_files)
|
58
|
+
repository.find_test changed_files.first if runner.matching?
|
59
|
+
end
|
40
60
|
end
|
41
61
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative 'command/rails'
|
2
|
+
require_relative 'command/rake'
|
3
|
+
require_relative 'command/rspec'
|
4
|
+
require_relative 'command/ruby'
|
5
|
+
|
6
|
+
module Retest
|
7
|
+
class Command
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def self.for_options(options)
|
11
|
+
new(options: options).command
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.for_setup(setup)
|
15
|
+
new(setup: setup).command
|
16
|
+
end
|
17
|
+
|
18
|
+
def_delegator :setup, :type
|
19
|
+
def_delegators :options, :params, :full_suite?, :auto?
|
20
|
+
|
21
|
+
attr_accessor :options, :setup
|
22
|
+
def initialize(options: Options.new, setup: Setup.new, output_stream: STDOUT)
|
23
|
+
@options = options
|
24
|
+
@setup = setup
|
25
|
+
@output_stream = output_stream
|
26
|
+
end
|
27
|
+
|
28
|
+
def command
|
29
|
+
return default_command if auto?
|
30
|
+
options_command || default_command
|
31
|
+
end
|
32
|
+
|
33
|
+
def options_command
|
34
|
+
return params[:command] if params[:command]
|
35
|
+
|
36
|
+
if params[:rspec] then rspec_command
|
37
|
+
elsif params[:rails] then rails_command
|
38
|
+
elsif params[:ruby] then ruby_command
|
39
|
+
elsif params[:rake] then rake_command
|
40
|
+
else
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def setup_command
|
45
|
+
case type
|
46
|
+
when :rake then rake_command
|
47
|
+
when :rspec then rspec_command
|
48
|
+
when :rails then rails_command
|
49
|
+
when :ruby then ruby_command
|
50
|
+
else ruby_command
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def default_command
|
55
|
+
@output_stream.puts "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'"
|
56
|
+
setup_command
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def rspec_command
|
62
|
+
Rspec.command(all: full_suite?)
|
63
|
+
end
|
64
|
+
|
65
|
+
def rails_command
|
66
|
+
Rails.command(all: full_suite?)
|
67
|
+
end
|
68
|
+
|
69
|
+
def rake_command
|
70
|
+
Rake.command(all: full_suite?)
|
71
|
+
end
|
72
|
+
|
73
|
+
def ruby_command
|
74
|
+
Ruby.command(all: full_suite?)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Retest
|
2
|
+
class Command
|
3
|
+
Rails = Struct.new(:all, :bin_file) do
|
4
|
+
def self.command(all:, bin_file: File.exist?('bin/rails'))
|
5
|
+
new(all, bin_file).command
|
6
|
+
end
|
7
|
+
|
8
|
+
def command
|
9
|
+
return "#{root_command} <test>" unless all
|
10
|
+
root_command
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def root_command
|
16
|
+
return 'bin/rails test' if bin_file
|
17
|
+
|
18
|
+
'bundle exec rails test'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Retest
|
2
|
+
class Command
|
3
|
+
Rake = Struct.new(:all, :bin_file) do
|
4
|
+
def self.command(all:, bin_file: File.exist?('bin/rake'))
|
5
|
+
new(all, bin_file).command
|
6
|
+
end
|
7
|
+
|
8
|
+
def command
|
9
|
+
return "#{root_command} TEST=<test>" unless all
|
10
|
+
root_command
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def root_command
|
16
|
+
return 'bin/rake test' if bin_file
|
17
|
+
|
18
|
+
'bundle exec rake test'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Retest
|
2
|
+
class Command
|
3
|
+
Rspec = Struct.new(:all, :bin_file) do
|
4
|
+
def self.command(all:, bin_file: File.exist?('bin/rspec'))
|
5
|
+
new(all, bin_file).command
|
6
|
+
end
|
7
|
+
|
8
|
+
def command
|
9
|
+
return "#{root_command} <test>" unless all
|
10
|
+
root_command
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def root_command
|
16
|
+
return 'bin/rspec' if bin_file
|
17
|
+
|
18
|
+
'bundle exec rspec'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
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,24 @@ 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
|
51
|
+
|
52
|
+
example <<~EOS
|
53
|
+
Run a sanity check on changed files from a branch
|
54
|
+
$ retest --diff origin/main --rails
|
55
|
+
$ retest --diff main --auto
|
56
|
+
EOS
|
40
57
|
end
|
41
58
|
|
42
59
|
argument :command do
|
@@ -47,11 +64,21 @@ module Retest
|
|
47
64
|
EOS
|
48
65
|
end
|
49
66
|
|
67
|
+
option :diff do
|
68
|
+
desc "Pipes all matching tests from diffed branch to test command"
|
69
|
+
long "--diff=git-branch"
|
70
|
+
end
|
71
|
+
|
50
72
|
flag :all do
|
51
73
|
long "--all"
|
52
74
|
desc "Run all the specs of a specificied ruby setup"
|
53
75
|
end
|
54
76
|
|
77
|
+
flag :auto do
|
78
|
+
long "--auto"
|
79
|
+
desc "Indentify repository setup and runs appropriate command"
|
80
|
+
end
|
81
|
+
|
55
82
|
flag :help do
|
56
83
|
short "-h"
|
57
84
|
long "--help"
|
@@ -88,20 +115,6 @@ module Retest
|
|
88
115
|
self.args = args
|
89
116
|
end
|
90
117
|
|
91
|
-
def command
|
92
|
-
if params[:rspec]
|
93
|
-
params[:all] ? ALL_RSPEC_COMMAND : RSPEC_COMMAND
|
94
|
-
elsif params[:rake]
|
95
|
-
params[:all] ? ALL_RAKE_COMMAND : RAKE_COMMAND
|
96
|
-
elsif params[:rails]
|
97
|
-
params[:all] ? ALL_RAILS_COMMAND : RAILS_COMMAND
|
98
|
-
elsif params[:ruby]
|
99
|
-
params[:all] ? NO_COMMAND : RUBY_COMMAND
|
100
|
-
else
|
101
|
-
params[:command] || NO_COMMAND
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
118
|
def args=(args)
|
106
119
|
@args = args
|
107
120
|
parse args
|
@@ -110,5 +123,20 @@ module Retest
|
|
110
123
|
def help?
|
111
124
|
params[:help]
|
112
125
|
end
|
126
|
+
|
127
|
+
def full_suite?
|
128
|
+
params[:all]
|
129
|
+
end
|
130
|
+
|
131
|
+
def auto?
|
132
|
+
return true if no_options_passed?
|
133
|
+
params[:auto]
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def no_options_passed?
|
139
|
+
params.to_h.values.compact.uniq == [false]
|
140
|
+
end
|
113
141
|
end
|
114
142
|
end
|
data/lib/retest/repository.rb
CHANGED
@@ -13,18 +13,28 @@ module Retest
|
|
13
13
|
return unless path
|
14
14
|
return if path.empty?
|
15
15
|
|
16
|
-
|
16
|
+
@path = path
|
17
|
+
cache[@path] ||= select_from TestOptions.for(@path, files: files)
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_tests(paths)
|
21
|
+
paths
|
22
|
+
.select { |path| Regexp.new("\.rb$") =~ path }
|
23
|
+
.map { |path| find_test(path) }
|
24
|
+
.compact
|
25
|
+
.uniq
|
26
|
+
.sort
|
17
27
|
end
|
18
28
|
|
19
29
|
def add(added)
|
20
|
-
return if added
|
30
|
+
return if added&.empty?
|
21
31
|
|
22
32
|
files.push(*added)
|
23
33
|
files.sort!
|
24
34
|
end
|
25
35
|
|
26
36
|
def remove(removed)
|
27
|
-
return if removed
|
37
|
+
return if removed&.empty?
|
28
38
|
|
29
39
|
if removed.is_a?(Array)
|
30
40
|
removed.each { |file| files.delete(file) }
|
@@ -47,7 +57,7 @@ module Retest
|
|
47
57
|
|
48
58
|
def ask_question(tests)
|
49
59
|
output_stream.puts <<~QUESTION
|
50
|
-
We found few tests matching:
|
60
|
+
We found few tests matching: #{@path}
|
51
61
|
#{list_options(tests)}
|
52
62
|
|
53
63
|
Which file do you want to use?
|
data/lib/retest/runner.rb
CHANGED
@@ -52,6 +52,14 @@ module Retest
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
def unmatching?
|
56
|
+
!matching?
|
57
|
+
end
|
58
|
+
|
59
|
+
def matching?
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
55
63
|
private
|
56
64
|
|
57
65
|
def purge_cache
|
@@ -65,6 +73,14 @@ module Retest
|
|
65
73
|
end
|
66
74
|
|
67
75
|
def remove(_ = nil); end
|
76
|
+
|
77
|
+
def unmatching?
|
78
|
+
!matching?
|
79
|
+
end
|
80
|
+
|
81
|
+
def matching?
|
82
|
+
false
|
83
|
+
end
|
68
84
|
end
|
69
85
|
end
|
70
86
|
end
|
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_lock_file?
|
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_lock_file?
|
26
|
+
File.exist? 'Gemfile.lock'
|
27
|
+
end
|
28
|
+
|
29
|
+
def rspec?
|
30
|
+
has_gem? 'rspec'
|
31
|
+
end
|
32
|
+
|
33
|
+
def rails?
|
34
|
+
has_gem? 'rails'
|
35
|
+
end
|
36
|
+
|
37
|
+
def rake?
|
38
|
+
has_gem? 'rake'
|
39
|
+
end
|
40
|
+
|
41
|
+
def has_gem?(gem_name)
|
42
|
+
!`cat Gemfile.lock | grep #{gem_name}`.empty?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/retest/version.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require_relative 'version_control/git'
|
2
|
+
require_relative 'version_control/no_version_control'
|
3
|
+
|
1
4
|
module Retest
|
2
5
|
class VersionControl
|
3
6
|
def self.files
|
@@ -6,43 +9,5 @@ module Retest
|
|
6
9
|
|
7
10
|
def name; end
|
8
11
|
alias :to_s :name
|
9
|
-
|
10
|
-
class NoVersionControl
|
11
|
-
def self.installed?
|
12
|
-
true
|
13
|
-
end
|
14
|
-
|
15
|
-
def name
|
16
|
-
'default'
|
17
|
-
end
|
18
|
-
|
19
|
-
def files
|
20
|
-
Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Git
|
25
|
-
def self.installed?
|
26
|
-
system "git -C . rev-parse 2>/dev/null"
|
27
|
-
end
|
28
|
-
|
29
|
-
def name
|
30
|
-
'git'
|
31
|
-
end
|
32
|
-
|
33
|
-
def files
|
34
|
-
(untracked_files + tracked_files).sort
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def untracked_files
|
40
|
-
`git ls-files --other --exclude-standard -z`.split("\x0")
|
41
|
-
end
|
42
|
-
|
43
|
-
def tracked_files
|
44
|
-
`git ls-files -z`.split("\x0")
|
45
|
-
end
|
46
|
-
end
|
47
12
|
end
|
48
13
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Retest::VersionControl
|
2
|
+
class Git
|
3
|
+
def self.installed?
|
4
|
+
system "git -C . rev-parse 2>/dev/null"
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.diff_files(branch)
|
8
|
+
new.diff_files(branch)
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
'git'
|
13
|
+
end
|
14
|
+
|
15
|
+
def files
|
16
|
+
(untracked_files + tracked_files).sort
|
17
|
+
end
|
18
|
+
|
19
|
+
def diff_files(branch)
|
20
|
+
`git diff #{branch} --name-only --diff-filter=ACMRT -z`.split("\x0")
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def untracked_files
|
26
|
+
`git ls-files --other --exclude-standard -z`.split("\x0")
|
27
|
+
end
|
28
|
+
|
29
|
+
def tracked_files
|
30
|
+
`git ls-files -z`.split("\x0")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
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:
|
4
|
+
version: 1.1.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-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -70,18 +70,30 @@ files:
|
|
70
70
|
- README/demo.gif
|
71
71
|
- Rakefile
|
72
72
|
- bin/console
|
73
|
+
- bin/debug
|
73
74
|
- bin/setup
|
75
|
+
- bin/test/git-ruby
|
74
76
|
- bin/test/hanami-app
|
75
77
|
- bin/test/rails-app
|
78
|
+
- bin/test/rspec-rails
|
79
|
+
- bin/test/rspec-ruby
|
76
80
|
- bin/test/ruby-app
|
77
81
|
- exe/retest
|
78
82
|
- lib/retest.rb
|
83
|
+
- lib/retest/command.rb
|
84
|
+
- lib/retest/command/rails.rb
|
85
|
+
- lib/retest/command/rake.rb
|
86
|
+
- lib/retest/command/rspec.rb
|
87
|
+
- lib/retest/command/ruby.rb
|
79
88
|
- lib/retest/options.rb
|
80
89
|
- lib/retest/repository.rb
|
81
90
|
- lib/retest/runner.rb
|
91
|
+
- lib/retest/setup.rb
|
82
92
|
- lib/retest/test_options.rb
|
83
93
|
- lib/retest/version.rb
|
84
94
|
- lib/retest/version_control.rb
|
95
|
+
- lib/retest/version_control/git.rb
|
96
|
+
- lib/retest/version_control/no_version_control.rb
|
85
97
|
- retest.gemspec
|
86
98
|
homepage: https://github.com/AlexB52/retest
|
87
99
|
licenses:
|