retest 0.8.0.pre3 → 1.0.0.pre
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 +22 -2
- data/Gemfile +0 -2
- data/Gemfile.lock +3 -74
- data/README.md +54 -21
- data/bin/debug +26 -0
- data/bin/test/git-ruby +6 -0
- data/bin/test/hanami-app +8 -0
- data/bin/test/rails-app +6 -0
- data/bin/test/rspec-rails +6 -0
- data/bin/test/rspec-ruby +6 -0
- data/bin/test/ruby-app +6 -0
- data/exe/retest +14 -3
- data/lib/retest.rb +30 -10
- data/lib/retest/options.rb +80 -12
- data/lib/retest/repository.rb +17 -4
- data/lib/retest/runner.rb +47 -3
- data/lib/retest/setup.rb +45 -0
- data/lib/retest/version.rb +1 -1
- data/lib/retest/version_control.rb +3 -28
- data/lib/retest/version_control/git.rb +33 -0
- data/lib/retest/version_control/no_version_control.rb +15 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 283264ef544ab1d67927bd21f53d36e3f210570453bf59ca09edf83cef6111d2
|
4
|
+
data.tar.gz: 05304a016fc791d8ea4a21b3a44fd4e74d5ccd1ec659db3f3227cc3c04e17f87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d458a1d91538f3a8bc0b60baff4f399c7cfa495c83a1fa47a1cd054c809239084c640fbd15b89efd15e53ea7110d3291b054567f2d0b599f6541c615a8e985e
|
7
|
+
data.tar.gz: 0d55c10145f7f77c755d66aff6f719731401026444f1c3911ccbee3ffeb089257303e87b80de6edd98a273138b6e481c0af97aaaab395ff9c81f1cdf8659bfcb
|
data/.github/workflows/ci.yml
CHANGED
@@ -14,7 +14,7 @@ on:
|
|
14
14
|
branches: [ main ]
|
15
15
|
|
16
16
|
jobs:
|
17
|
-
|
17
|
+
unit-tests:
|
18
18
|
runs-on: ${{ matrix.os }}
|
19
19
|
strategy:
|
20
20
|
matrix:
|
@@ -36,4 +36,24 @@ jobs:
|
|
36
36
|
bundler-cache: true
|
37
37
|
- run: bundle install
|
38
38
|
- run: bundle exec rake
|
39
|
-
|
39
|
+
|
40
|
+
app-tests:
|
41
|
+
name: ${{ matrix.repo }} feature specs
|
42
|
+
runs-on: ubuntu-latest
|
43
|
+
strategy:
|
44
|
+
matrix:
|
45
|
+
repo:
|
46
|
+
- ruby-app
|
47
|
+
- rails-app
|
48
|
+
- hanami-app
|
49
|
+
- rspec-rails
|
50
|
+
- rspec-ruby
|
51
|
+
- git-ruby
|
52
|
+
steps:
|
53
|
+
- uses: actions/checkout@v2
|
54
|
+
- name: Set up Ruby
|
55
|
+
uses: ruby/setup-ruby@v1
|
56
|
+
with:
|
57
|
+
ruby-version: 2.5
|
58
|
+
bundler-cache: true
|
59
|
+
- run: bin/test/${{ matrix.repo }}
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
retest (0.
|
4
|
+
retest (1.0.0.pre)
|
5
5
|
listen (~> 3.2)
|
6
6
|
string-similarity (~> 2.1)
|
7
7
|
tty-option (~> 0.1)
|
@@ -9,95 +9,24 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (6.0.3.2)
|
13
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>= 0.7, < 2)
|
15
|
-
minitest (~> 5.1)
|
16
|
-
tzinfo (~> 1.1)
|
17
|
-
zeitwerk (~> 2.2, >= 2.2.2)
|
18
|
-
aruba (1.0.3)
|
19
|
-
childprocess (>= 2.0, < 5.0)
|
20
|
-
contracts (~> 0.16.0)
|
21
|
-
cucumber (>= 2.4, < 6.0)
|
22
|
-
ffi (~> 1.9)
|
23
|
-
rspec-expectations (~> 3.4)
|
24
|
-
thor (~> 1.0)
|
25
|
-
builder (3.2.4)
|
26
12
|
byebug (11.1.3)
|
27
|
-
|
28
|
-
|
29
|
-
contracts (0.16.0)
|
30
|
-
cucumber (5.1.0)
|
31
|
-
builder (~> 3.2, >= 3.2.4)
|
32
|
-
cucumber-core (~> 8.0, >= 8.0.1)
|
33
|
-
cucumber-create-meta (~> 2.0, >= 2.0.1)
|
34
|
-
cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
|
35
|
-
cucumber-gherkin (~> 15.0, >= 15.0.2)
|
36
|
-
cucumber-html-formatter (~> 9.0, >= 9.0.0)
|
37
|
-
cucumber-messages (~> 13.0, >= 13.0.1)
|
38
|
-
cucumber-wire (~> 4.0, >= 4.0.1)
|
39
|
-
diff-lcs (~> 1.4, >= 1.4.4)
|
40
|
-
multi_test (~> 0.1, >= 0.1.2)
|
41
|
-
sys-uname (~> 1.2, >= 1.2.1)
|
42
|
-
cucumber-core (8.0.1)
|
43
|
-
cucumber-gherkin (~> 15.0, >= 15.0.2)
|
44
|
-
cucumber-messages (~> 13.0, >= 13.0.1)
|
45
|
-
cucumber-tag-expressions (~> 2.0, >= 2.0.4)
|
46
|
-
cucumber-create-meta (2.0.1)
|
47
|
-
cucumber-messages (~> 13.0, >= 13.0.1)
|
48
|
-
sys-uname (~> 1.2, >= 1.2.1)
|
49
|
-
cucumber-cucumber-expressions (10.3.0)
|
50
|
-
cucumber-gherkin (15.0.2)
|
51
|
-
cucumber-messages (~> 13.0, >= 13.0.1)
|
52
|
-
cucumber-html-formatter (9.0.0)
|
53
|
-
cucumber-messages (~> 13.0, >= 13.0.1)
|
54
|
-
cucumber-messages (13.0.1)
|
55
|
-
protobuf-cucumber (~> 3.10, >= 3.10.8)
|
56
|
-
cucumber-tag-expressions (2.0.4)
|
57
|
-
cucumber-wire (4.0.1)
|
58
|
-
cucumber-core (~> 8.0, >= 8.0.1)
|
59
|
-
cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
|
60
|
-
cucumber-messages (~> 13.0, >= 13.0.1)
|
61
|
-
diff-lcs (1.4.4)
|
62
|
-
ffi (1.13.1)
|
63
|
-
i18n (1.8.5)
|
64
|
-
concurrent-ruby (~> 1.0)
|
65
|
-
listen (3.4.1)
|
13
|
+
ffi (1.15.0)
|
14
|
+
listen (3.5.0)
|
66
15
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
67
16
|
rb-inotify (~> 0.9, >= 0.9.10)
|
68
|
-
middleware (0.1.0)
|
69
17
|
minitest (5.14.1)
|
70
|
-
multi_test (0.1.2)
|
71
|
-
protobuf-cucumber (3.10.8)
|
72
|
-
activesupport (>= 3.2)
|
73
|
-
middleware
|
74
|
-
thor
|
75
|
-
thread_safe
|
76
18
|
rake (12.3.3)
|
77
19
|
rb-fsevent (0.10.4)
|
78
20
|
rb-inotify (0.10.1)
|
79
21
|
ffi (~> 1.0)
|
80
|
-
rspec-expectations (3.9.2)
|
81
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
-
rspec-support (~> 3.9.0)
|
83
|
-
rspec-support (3.9.3)
|
84
22
|
string-similarity (2.1.0)
|
85
|
-
sys-uname (1.2.1)
|
86
|
-
ffi (>= 1.0.0)
|
87
|
-
thor (1.0.1)
|
88
|
-
thread_safe (0.3.6)
|
89
23
|
tty-option (0.1.0)
|
90
|
-
tzinfo (1.2.7)
|
91
|
-
thread_safe (~> 0.1)
|
92
|
-
zeitwerk (2.4.0)
|
93
24
|
|
94
25
|
PLATFORMS
|
95
26
|
ruby
|
96
27
|
|
97
28
|
DEPENDENCIES
|
98
|
-
aruba (~> 1.0)
|
99
29
|
byebug
|
100
|
-
cucumber (~> 5.1)
|
101
30
|
minitest (~> 5.0)
|
102
31
|
rake (~> 12.0)
|
103
32
|
retest!
|
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
|
24
30
|
|
25
|
-
|
31
|
+
Finally let retest automatically find your ruby setup and run the appropriate command using:
|
26
32
|
|
27
|
-
|
33
|
+
$ retest
|
34
|
+
$ retest --auto
|
35
|
+
$ retest --auto --all
|
36
|
+
|
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.
|
43
|
+
|
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
|
|
@@ -104,6 +132,11 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
104
132
|
|
105
133
|
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).
|
106
134
|
|
135
|
+
To run integration tests on one setup (ex: hanami-app): `bin/test/hanami-app`
|
136
|
+
|
137
|
+
To access an app container (ex: ruby-app): `docker-compose -f features/ruby-app/docker-compose.yml run retest sh`
|
138
|
+
|
139
|
+
|
107
140
|
## Contributing
|
108
141
|
|
109
142
|
Bug reports and pull requests are welcome on GitHub at https://github.com/alexb52/retest.
|
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(options.command)
|
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
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
bundle install
|
4
|
+
bundle exec rake build
|
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 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
ADDED
data/bin/test/rspec-ruby
ADDED
data/bin/test/ruby-app
ADDED
data/exe/retest
CHANGED
@@ -6,8 +6,19 @@ $stdout.sync = true
|
|
6
6
|
|
7
7
|
options = Retest::Options.new(ARGV)
|
8
8
|
|
9
|
-
|
9
|
+
if options.help?
|
10
|
+
$stdout.puts options.help
|
11
|
+
return
|
12
|
+
end
|
10
13
|
|
11
|
-
Retest.
|
14
|
+
program = Retest::Program.new(
|
15
|
+
repository: Retest::Repository.new(files: Retest::VersionControl.files),
|
16
|
+
runner: Retest::Runner.for(options.command)
|
17
|
+
)
|
12
18
|
|
13
|
-
|
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,34 +7,54 @@ require "retest/repository"
|
|
7
7
|
require "retest/test_options"
|
8
8
|
require "retest/options"
|
9
9
|
require "retest/version_control"
|
10
|
+
require "retest/setup"
|
10
11
|
|
11
12
|
module Retest
|
12
13
|
class Error < StandardError; end
|
13
14
|
|
14
|
-
class
|
15
|
-
|
15
|
+
class Program
|
16
|
+
attr_accessor :runner, :repository
|
17
|
+
def initialize(runner: nil, repository: nil)
|
18
|
+
@runner = runner
|
19
|
+
@repository = repository
|
20
|
+
end
|
21
|
+
|
22
|
+
def start
|
16
23
|
puts "Launching Retest..."
|
24
|
+
build.start
|
25
|
+
puts "Ready to refactor! You can make file changes now"
|
26
|
+
end
|
17
27
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
).start
|
28
|
+
def diff(branch)
|
29
|
+
raise "Git not installed" unless VersionControl::Git.installed?
|
30
|
+
test_files = repository.find_tests VersionControl::Git.diff_files(branch)
|
22
31
|
|
23
|
-
puts "
|
32
|
+
puts "Tests found:"
|
33
|
+
test_files.each { |test_file| puts " - #{test_file}" }
|
34
|
+
|
35
|
+
puts "Running tests..."
|
36
|
+
test_files.each { |test_file| runner.run test_file }
|
24
37
|
end
|
25
38
|
|
26
|
-
|
39
|
+
private
|
40
|
+
|
41
|
+
def build
|
27
42
|
Listen.to('.', only: /\.rb$/, relative: true) do |modified, added, removed|
|
28
43
|
begin
|
29
|
-
repository.remove(removed)
|
30
44
|
repository.add(added)
|
45
|
+
repository.remove(removed)
|
46
|
+
runner.remove(removed)
|
31
47
|
system('clear 2>/dev/null') || system('cls 2>/dev/null')
|
32
48
|
|
33
|
-
runner.run
|
49
|
+
runner.run test_file_to_run(modified + added)
|
34
50
|
rescue => e
|
35
51
|
puts "Something went wrong: #{e.message}"
|
36
52
|
end
|
37
53
|
end
|
38
54
|
end
|
55
|
+
|
56
|
+
def test_file_to_run(changed_files)
|
57
|
+
repository.find_test changed_files.first if runner.matching?
|
58
|
+
end
|
39
59
|
end
|
40
60
|
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"
|
@@ -84,21 +111,21 @@ module Retest
|
|
84
111
|
new(args).command
|
85
112
|
end
|
86
113
|
|
87
|
-
def initialize(args = [])
|
114
|
+
def initialize(args = [], output_stream: STDOUT, setup: Setup)
|
88
115
|
self.args = args
|
116
|
+
@output_stream = output_stream
|
117
|
+
@setup = setup
|
89
118
|
end
|
90
119
|
|
91
120
|
def command
|
92
|
-
if params[:
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
elsif params[:rails]
|
97
|
-
|
98
|
-
elsif params[:
|
99
|
-
|
100
|
-
else
|
101
|
-
params[:command] || NO_COMMAND
|
121
|
+
return params[:command] if params[:command]
|
122
|
+
|
123
|
+
if params[:rspec] then rspec_command
|
124
|
+
elsif params[:rake] then rake_command
|
125
|
+
elsif params[:rails] then rails_command
|
126
|
+
elsif params[:ruby] then ruby_command
|
127
|
+
elsif params[:auto] then default_command
|
128
|
+
else default_command
|
102
129
|
end
|
103
130
|
end
|
104
131
|
|
@@ -110,5 +137,46 @@ module Retest
|
|
110
137
|
def help?
|
111
138
|
params[:help]
|
112
139
|
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def full_suite?
|
144
|
+
params[:all]
|
145
|
+
end
|
146
|
+
|
147
|
+
def default_command
|
148
|
+
choose_command @setup.type, command_for(@setup.type)
|
149
|
+
end
|
150
|
+
|
151
|
+
def command_for(type)
|
152
|
+
case type
|
153
|
+
when :rspec then rspec_command
|
154
|
+
when :rails then rails_command
|
155
|
+
when :rake then rake_command
|
156
|
+
when :ruby then ruby_command
|
157
|
+
else ruby_command
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def choose_command(type, command)
|
162
|
+
@output_stream.puts "Setup identified: [#{type.upcase}]. Using command: '#{command}'"
|
163
|
+
command
|
164
|
+
end
|
165
|
+
|
166
|
+
def rspec_command
|
167
|
+
full_suite? ? ALL_RSPEC_COMMAND : RSPEC_COMMAND
|
168
|
+
end
|
169
|
+
|
170
|
+
def rails_command
|
171
|
+
full_suite? ? ALL_RAILS_COMMAND : RAILS_COMMAND
|
172
|
+
end
|
173
|
+
|
174
|
+
def rake_command
|
175
|
+
full_suite? ? ALL_RAKE_COMMAND : RAKE_COMMAND
|
176
|
+
end
|
177
|
+
|
178
|
+
def ruby_command
|
179
|
+
RUBY_COMMAND
|
180
|
+
end
|
113
181
|
end
|
114
182
|
end
|
data/lib/retest/repository.rb
CHANGED
@@ -10,18 +10,31 @@ module Retest
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def find_test(path)
|
13
|
-
|
13
|
+
return unless path
|
14
|
+
return if path.empty?
|
15
|
+
|
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
|
14
27
|
end
|
15
28
|
|
16
29
|
def add(added)
|
17
|
-
return if added
|
30
|
+
return if added&.empty?
|
18
31
|
|
19
32
|
files.push(*added)
|
20
33
|
files.sort!
|
21
34
|
end
|
22
35
|
|
23
36
|
def remove(removed)
|
24
|
-
return if removed
|
37
|
+
return if removed&.empty?
|
25
38
|
|
26
39
|
if removed.is_a?(Array)
|
27
40
|
removed.each { |file| files.delete(file) }
|
@@ -44,7 +57,7 @@ module Retest
|
|
44
57
|
|
45
58
|
def ask_question(tests)
|
46
59
|
output_stream.puts <<~QUESTION
|
47
|
-
We found few tests matching:
|
60
|
+
We found few tests matching: #{@path}
|
48
61
|
#{list_options(tests)}
|
49
62
|
|
50
63
|
Which file do you want to use?
|
data/lib/retest/runner.rb
CHANGED
@@ -20,10 +20,20 @@ module Retest
|
|
20
20
|
command == obj.command
|
21
21
|
end
|
22
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
|
+
|
23
31
|
def run(test_file = nil)
|
24
|
-
|
25
|
-
|
26
|
-
|
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)
|
27
37
|
else
|
28
38
|
puts <<~ERROR
|
29
39
|
404 - Test File Not Found
|
@@ -31,12 +41,46 @@ module Retest
|
|
31
41
|
ERROR
|
32
42
|
end
|
33
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
|
34
68
|
end
|
35
69
|
|
36
70
|
HardcodedRunner = Struct.new(:command) do
|
37
71
|
def run(_ = nil)
|
38
72
|
system command
|
39
73
|
end
|
74
|
+
|
75
|
+
def remove(_ = nil); end
|
76
|
+
|
77
|
+
def unmatching?
|
78
|
+
!matching?
|
79
|
+
end
|
80
|
+
|
81
|
+
def matching?
|
82
|
+
false
|
83
|
+
end
|
40
84
|
end
|
41
85
|
end
|
42
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_gemfile?
|
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_gemfile?
|
26
|
+
File.exist? 'Gemfile'
|
27
|
+
end
|
28
|
+
|
29
|
+
def rspec?
|
30
|
+
has_gem? 'rspec'
|
31
|
+
end
|
32
|
+
|
33
|
+
def rails?
|
34
|
+
File.exist? 'bin/rails'
|
35
|
+
end
|
36
|
+
|
37
|
+
def rake?
|
38
|
+
has_gem? 'rake'
|
39
|
+
end
|
40
|
+
|
41
|
+
def has_gem?(gem_name)
|
42
|
+
!`cat Gemfile | 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,33 +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
|
-
`git ls-files`.split("\n")
|
35
|
-
end
|
36
|
-
end
|
37
12
|
end
|
38
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: 0.
|
4
|
+
version: 1.0.0.pre
|
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-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-similarity
|
@@ -70,15 +70,25 @@ 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
|
76
|
+
- bin/test/hanami-app
|
77
|
+
- bin/test/rails-app
|
78
|
+
- bin/test/rspec-rails
|
79
|
+
- bin/test/rspec-ruby
|
80
|
+
- bin/test/ruby-app
|
74
81
|
- exe/retest
|
75
82
|
- lib/retest.rb
|
76
83
|
- lib/retest/options.rb
|
77
84
|
- lib/retest/repository.rb
|
78
85
|
- lib/retest/runner.rb
|
86
|
+
- lib/retest/setup.rb
|
79
87
|
- lib/retest/test_options.rb
|
80
88
|
- lib/retest/version.rb
|
81
89
|
- lib/retest/version_control.rb
|
90
|
+
- lib/retest/version_control/git.rb
|
91
|
+
- lib/retest/version_control/no_version_control.rb
|
82
92
|
- retest.gemspec
|
83
93
|
homepage: https://github.com/AlexB52/retest
|
84
94
|
licenses:
|