retest 1.1.0 → 1.4.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: 7cec5f35b345630339ca56cfd0c1bc88be03596ca4d8369695f2e87f66e7c608
4
- data.tar.gz: db0b1f966bb2ebe14183e17e93003c0d504881dc2a7d8fe2614f5c202b0fcf55
3
+ metadata.gz: 5c5dc87b26d27197158d859e17e179f9dc0b00ec2280dfefff165da388c77eb6
4
+ data.tar.gz: cffbfbf72ea1b51e7f63e288fba08727498ec582192536a54ad9d2b47f04d1d2
5
5
  SHA512:
6
- metadata.gz: 2b191a17f73446b41fd5fdf9bc7495f4ea0535c05681e1d14e191cb62f6cadc83d09454ad501fc98ce503db6a169b628b6d205328ca4a236ddf56bbc75d78bff
7
- data.tar.gz: e1089b2d8c64c380c2fd08935f8b0ded1dee4ccb2f265ff20c6f12eeea91942ef0e4c9a6a154b48a270a4c3281fa2e3edf981925f50c6767c98a2bbcbd1cd6f3
6
+ metadata.gz: ad4051278ba14ff9f7284de5f8f643bdec7512864bb330aac803f6e3c672cc24f5584eb4b26be9f4a2b533a229fd5366a0eece8b4aa53eb816ff3e9c6575f200
7
+ data.tar.gz: 3b52308adcef24e6098f40ee07d55848f39104838c4db404394ee33a8ffe38466478cd18f347aa73b3a0072fc0c263592a9eecf1ed98e459345be160c02ed30f
@@ -44,11 +44,12 @@ jobs:
44
44
  matrix:
45
45
  repo:
46
46
  - ruby-app
47
- - rails-app
47
+ - ruby-bare
48
+ - git-ruby
48
49
  - hanami-app
50
+ - rails-app
49
51
  - rspec-rails
50
52
  - rspec-ruby
51
- - git-ruby
52
53
  steps:
53
54
  - uses: actions/checkout@v2
54
55
  - name: Set up Ruby
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retest (1.1.0)
4
+ retest (1.4.0)
5
5
  listen (~> 3.2)
6
6
  string-similarity (~> 2.1)
7
7
  tty-option (~> 0.1)
@@ -10,17 +10,17 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  byebug (11.1.3)
13
- ffi (1.15.0)
14
- listen (3.5.0)
13
+ ffi (1.15.4)
14
+ listen (3.7.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)
18
18
  rake (12.3.3)
19
- rb-fsevent (0.10.4)
19
+ rb-fsevent (0.11.0)
20
20
  rb-inotify (0.10.1)
21
21
  ffi (~> 1.0)
22
22
  string-similarity (2.1.0)
23
- tty-option (0.1.0)
23
+ tty-option (0.2.0)
24
24
 
25
25
  PLATFORMS
26
26
  ruby
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/retest.svg)](https://badge.fury.io/rb/retest)
2
+
1
3
  # Retest
2
4
 
3
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)
@@ -14,13 +16,37 @@ Install it on your machine without adding it on a Gemfile:
14
16
 
15
17
  ## Usage
16
18
 
17
- Launch `retest` in your terminal after accessing your ruby repository.
19
+ Retest is used in your terminal after accessing your ruby project folder.
20
+
21
+ ### Help
22
+
23
+ Find out what retest can do anytime with
24
+
25
+ $ retest -h
26
+
27
+ ### For Refactoring
28
+
29
+ #### 1. Run a hardcoded command
30
+
31
+ This the most simple usage of retest: running the same command over and over after each file update.
18
32
 
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:
33
+ Example:
20
34
 
21
- $ retest 'bundle exec rspec <test>'
35
+ $ retest 'bundle exec rspec spec/features/posts_spec.rb'
22
36
 
23
- When a file is changed, the gem will find its matching test and run the test command with it.
37
+ In this example, the feature spec `spec/features/posts_spec.rb` will be tested after any ruby file is updated.
38
+
39
+ #### 2. Run a dynamic command
40
+
41
+ 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.
42
+
43
+ Example:
44
+
45
+ $ retest 'bin/rails test <test>'
46
+
47
+ In this example, if `app/models/post.rb` is changed then retest will run `bin/rails test test/models/post_test.rb`
48
+
49
+ #### 3. Run a dynamic command with shortcuts
24
50
 
25
51
  Few shortcut flags exist to avoid writing the full test command.
26
52
 
@@ -28,65 +54,29 @@ Few shortcut flags exist to avoid writing the full test command.
28
54
  $ retest --rails
29
55
  $ retest --rake --all
30
56
 
31
- Finally let retest automatically find your ruby setup and run the appropriate command using:
57
+ #### 4. Let retest figure it all out
58
+
59
+ Let retest find your ruby setup and run the appropriate command using:
32
60
 
33
61
  $ retest
34
- $ retest --auto
35
- $ retest --auto --all
62
+ $ retest --all
63
+
64
+ #### Running rules
36
65
 
37
66
  The gem works as follows:
38
67
 
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.
68
+ * When a **ruby file** is changed, retest will run its matching test.
69
+ * When a **test file** is changed, retest will run the test file.
41
70
  * When multiple matching test files are found, retest asks you to confirm the file and save the answer.
42
71
  * When a test file is not found, retest runs the last run command or throw a 404.
43
72
 
44
- See more example with `retest -h`
73
+ ### Pull request scans
45
74
 
46
- ```
47
- Usage: retest [OPTIONS] [COMMAND]
48
-
49
- Watch a file change and run it matching spec.
50
-
51
- Arguments:
52
- COMMAND The test command to rerun when a file changes.
53
- Use <test> placeholder to tell retest where to put the matching
54
- spec.
55
-
56
-
57
- Options:
58
- --all Run all the specs of a specificied ruby setup
59
- --auto Indentify repository setup and runs appropriate command
60
- -h, --help Print usage
61
- --rails Shortcut for 'bundle exec rails test <test>'
62
- --rake Shortcut for 'bundle exec rake test TEST=<test>'
63
- --rspec Shortcut for 'bundle exec rspec <test>'
64
- --ruby Shortcut for 'bundle exec ruby <test>'
65
-
66
- Examples:
67
- Runs a matching rails test after a file change
68
- $ retest 'bundle exec rails test <test>'
69
- $ retest --rails
75
+ You can diff a branch and test all the relevant test files before pushing your branch and trigger a full CI suite.
70
76
 
71
- Runs all rails tests after a file change
72
- $ retest 'bundle exec rails test'
73
- $ retest --rails --all
77
+ $ retest --diff origin/main
74
78
 
75
- Runs a hardcoded command after a file change
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
89
- ```
79
+ In this example, retest lists all the files changed between `HEAD` and `origin/main`, finds all the relevant tests and only run those.
90
80
 
91
81
  ## Why?
92
82
  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,8 +88,12 @@ For fully fledged solutions, some cli tools already exists: [autotest](https://g
98
88
  ## Docker
99
89
 
100
90
  Retest works in Docker too. You can install the gem and launch retest in your container while refactoring.
91
+
101
92
  ```bash
102
- $ docker-compose run web bash # enter your container
93
+ # Enter your container. Ex:
94
+ $ docker-compose run web bash
95
+
96
+ # Install the gem and run retest in your container shell
103
97
  $ gem install retest
104
98
  $ retest 'bundle exec rails test <test>'
105
99
  ```
@@ -118,12 +112,13 @@ Retest supports ruby 2.4 and above.
118
112
  - [x] When multiple test files are found, ask which file to run and save the answer.
119
113
  - [x] When a test file is not found run the last command again.
120
114
  - [x] Run within Docker.
121
- - [ ] Handle main Ruby setups
115
+ - [x] Handle main Ruby setups
122
116
  - [x] Bundler Gem
123
117
  - [x] Rails
124
118
  - [x] Ad-hoc scripts
125
119
  - [x] Hanami
126
- - [ ] Handle other languages: Elixir, Node, Python, PHP
120
+ - [ ] Handle other languages: Go, Elixir, Node, Python, PHP
121
+ - [ ] Go (project started)
127
122
  - [ ] Aliases from oh-my-zsh and bash profiles?
128
123
 
129
124
  ## Development
@@ -136,7 +131,6 @@ To run integration tests on one setup (ex: hanami-app): `bin/test/hanami-app`
136
131
 
137
132
  To access an app container (ex: ruby-app): `docker-compose -f features/ruby-app/docker-compose.yml run retest sh`
138
133
 
139
-
140
134
  ## Contributing
141
135
 
142
136
  Bug reports and pull requests are welcome on GitHub at https://github.com/alexb52/retest.
data/bin/debug CHANGED
@@ -13,9 +13,15 @@ if options.help?
13
13
  return
14
14
  end
15
15
 
16
+ repository = Retest::Repository.new(files: Retest::VersionControl.files)
17
+ command = Retest::Command.for_options(options)
18
+ runner = Retest::Runner.for(command.to_s)
19
+
16
20
  program = Retest::Program.new(
17
- repository: Retest::Repository.new(files: Retest::VersionControl.files),
18
- runner: Retest::Runner.for(Retest::Command.for_options(options))
21
+ extension: options.extension,
22
+ repository: repository,
23
+ command: command,
24
+ runner: runner
19
25
  )
20
26
 
21
27
  if options.params[:diff]
@@ -0,0 +1,6 @@
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/ruby-bare/retest.gem
6
+ docker-compose -f features/ruby-bare/docker-compose.yml up --build --exit-code-from retest
data/exe/retest CHANGED
@@ -11,9 +11,15 @@ if options.help?
11
11
  return
12
12
  end
13
13
 
14
+ repository = Retest::Repository.new(files: Retest::VersionControl.files)
15
+ command = Retest::Command.for_options(options)
16
+ runner = Retest::Runner.for(command.to_s)
17
+
14
18
  program = Retest::Program.new(
15
- repository: Retest::Repository.new(files: Retest::VersionControl.files),
16
- runner: Retest::Runner.for(Retest::Command.for_options(options))
19
+ extension: options.extension,
20
+ repository: repository,
21
+ command: command,
22
+ runner: runner
17
23
  )
18
24
 
19
25
  if options.params[:diff]
@@ -1,22 +1,29 @@
1
1
  module Retest
2
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
3
+ class Rails
4
+ attr_reader :all, :file_system
5
+
6
+ def initialize(all:, file_system: FileSystem)
7
+ @file_system = file_system
8
+ @all = all
6
9
  end
7
10
 
8
- def command
11
+ def to_s
9
12
  return "#{root_command} <test>" unless all
10
13
  root_command
11
14
  end
12
15
 
16
+ def run_all(*files, runner:)
17
+ runner.run files.join(' ')
18
+ end
19
+
13
20
  private
14
21
 
15
22
  def root_command
16
- return 'bin/rails test' if bin_file
23
+ return 'bin/rails test' if file_system.exist? 'bin/rails'
17
24
 
18
25
  'bundle exec rails test'
19
26
  end
20
27
  end
21
28
  end
22
- end
29
+ end
@@ -1,22 +1,29 @@
1
1
  module Retest
2
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
3
+ class Rake
4
+ attr_reader :all, :file_system
5
+
6
+ def initialize(all:, file_system: FileSystem)
7
+ @file_system = file_system
8
+ @all = all
6
9
  end
7
10
 
8
- def command
11
+ def to_s
9
12
  return "#{root_command} TEST=<test>" unless all
10
13
  root_command
11
14
  end
12
15
 
16
+ def run_all(*files, runner:)
17
+ runner.run files.size > 1 ? "\"{#{files.join(',')}}\"" : files.first
18
+ end
19
+
13
20
  private
14
21
 
15
22
  def root_command
16
- return 'bin/rake test' if bin_file
23
+ return 'bin/rake test' if file_system.exist? 'bin/rake'
17
24
 
18
25
  'bundle exec rake test'
19
26
  end
20
27
  end
21
28
  end
22
- end
29
+ end
@@ -1,19 +1,26 @@
1
1
  module Retest
2
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
3
+ class Rspec
4
+ attr_reader :all, :file_system
5
+
6
+ def initialize(all:, file_system: FileSystem)
7
+ @file_system = file_system
8
+ @all = all
6
9
  end
7
10
 
8
- def command
11
+ def to_s
9
12
  return "#{root_command} <test>" unless all
10
13
  root_command
11
14
  end
12
15
 
16
+ def run_all(*files, runner:)
17
+ runner.run files.join(' ')
18
+ end
19
+
13
20
  private
14
21
 
15
22
  def root_command
16
- return 'bin/rspec' if bin_file
23
+ return 'bin/rspec' if file_system.exist? 'bin/rspec'
17
24
 
18
25
  'bundle exec rspec'
19
26
  end
@@ -1,12 +1,24 @@
1
1
  module Retest
2
2
  class Command
3
- Ruby = Struct.new(:all, :bin_file) do
4
- def self.command(all: false, bin_file: false)
5
- new(false, false).command
3
+ class Ruby
4
+ attr_reader :all, :file_system
5
+
6
+ def initialize(all:, file_system: FileSystem)
7
+ @file_system = file_system
8
+ @all = all
9
+ end
10
+
11
+ def run_all(*files, runner:)
12
+ paths = files.map { |file| "require './#{file}';" }.join
13
+ runner.run %Q{-e "#{paths}"}
6
14
  end
7
15
 
8
- def command
9
- 'bundle exec ruby <test>'
16
+ def to_s
17
+ if file_system.exist? 'Gemfile.lock'
18
+ 'bundle exec ruby <test>'
19
+ else
20
+ 'ruby <test>'
21
+ end
10
22
  end
11
23
  end
12
24
  end
@@ -59,19 +59,19 @@ module Retest
59
59
  private
60
60
 
61
61
  def rspec_command
62
- Rspec.command(all: full_suite?)
62
+ Rspec.new(all: full_suite?)
63
63
  end
64
64
 
65
65
  def rails_command
66
- Rails.command(all: full_suite?)
66
+ Rails.new(all: full_suite?)
67
67
  end
68
68
 
69
69
  def rake_command
70
- Rake.command(all: full_suite?)
70
+ Rake.new(all: full_suite?)
71
71
  end
72
72
 
73
73
  def ruby_command
74
- Ruby.command(all: full_suite?)
74
+ Ruby.new(all: full_suite?)
75
75
  end
76
76
  end
77
77
  end
@@ -0,0 +1,9 @@
1
+ module Retest
2
+ module FileSystem
3
+ module_function
4
+
5
+ def exist?(value)
6
+ File.exist? value
7
+ end
8
+ end
9
+ end
@@ -4,15 +4,6 @@ module Retest
4
4
  class Options
5
5
  include TTY::Option
6
6
 
7
- RSPEC_COMMAND = "bundle exec rspec <test>"
8
- RAILS_COMMAND = "bundle exec rails test <test>"
9
- RAKE_COMMAND = "bundle exec rake test TEST=<test>"
10
- RUBY_COMMAND = "bundle exec ruby <test>"
11
-
12
- ALL_RAKE_COMMAND = "bundle exec rake test"
13
- ALL_RAILS_COMMAND = "bundle exec rails test"
14
- ALL_RSPEC_COMMAND = "bundle exec rspec"
15
-
16
7
  usage do
17
8
  program "retest"
18
9
 
@@ -69,6 +60,12 @@ module Retest
69
60
  long "--diff=git-branch"
70
61
  end
71
62
 
63
+ option :ext do
64
+ desc "Regex of file extensions to listen to"
65
+ long "--ext=regex"
66
+ default "\\.rb$"
67
+ end
68
+
72
69
  flag :all do
73
70
  long "--all"
74
71
  desc "Run all the specs of a specificied ruby setup"
@@ -87,22 +84,22 @@ module Retest
87
84
 
88
85
  flag :rspec do
89
86
  long "--rspec"
90
- desc "Shortcut for '#{RSPEC_COMMAND}'"
87
+ desc "Shortcut for a standard RSpec setup"
91
88
  end
92
89
 
93
90
  flag :rake do
94
91
  long "--rake"
95
- desc "Shortcut for '#{RAKE_COMMAND}'"
92
+ desc "Shortcut for a standard Rake setup"
96
93
  end
97
94
 
98
95
  flag :rails do
99
96
  long "--rails"
100
- desc "Shortcut for '#{RAILS_COMMAND}'"
97
+ desc "Shortcut for a standard Rails setup"
101
98
  end
102
99
 
103
100
  flag :ruby do
104
101
  long "--ruby"
105
- desc "Shortcut for '#{RUBY_COMMAND}'"
102
+ desc "Shortcut for a Ruby project"
106
103
  end
107
104
 
108
105
  attr_reader :args
@@ -133,10 +130,14 @@ module Retest
133
130
  params[:auto]
134
131
  end
135
132
 
133
+ def extension
134
+ Regexp.new(params[:ext])
135
+ end
136
+
136
137
  private
137
138
 
138
139
  def no_options_passed?
139
- params.to_h.values.compact.uniq == [false]
140
+ params.to_h.values.compact.uniq == ["\\.rb$", false]
140
141
  end
141
142
  end
142
143
  end
@@ -0,0 +1,49 @@
1
+ module Retest
2
+ class Program
3
+ attr_accessor :runner, :repository, :command, :extension
4
+ def initialize(runner: nil, repository: nil, command: nil, extension: /\.rb$/)
5
+ @runner = runner
6
+ @repository = repository
7
+ @command = command
8
+ @extension = extension
9
+ end
10
+
11
+ def start
12
+ puts "Launching Retest..."
13
+ build.start
14
+ puts "Ready to refactor! You can make file changes now"
15
+ end
16
+
17
+ def diff(branch)
18
+ raise "Git not installed" unless VersionControl::Git.installed?
19
+ test_files = repository.find_tests VersionControl::Git.diff_files(branch)
20
+
21
+ puts "Tests found:"
22
+ test_files.each { |test_file| puts " - #{test_file}" }
23
+
24
+ puts "Running tests..."
25
+ command.run_all *test_files, runner: runner
26
+ end
27
+
28
+ private
29
+
30
+ def build
31
+ Listen.to('.', only: extension, relative: true) do |modified, added, removed|
32
+ begin
33
+ repository.add(added)
34
+ repository.remove(removed)
35
+ runner.remove(removed)
36
+ system('clear 2>/dev/null') || system('cls 2>/dev/null')
37
+
38
+ runner.run test_file_to_run(modified + added)
39
+ rescue => e
40
+ puts "Something went wrong: #{e.message}"
41
+ end
42
+ end
43
+ end
44
+
45
+ def test_file_to_run(changed_files)
46
+ repository.find_test changed_files.first if runner.matching?
47
+ end
48
+ end
49
+ end
data/lib/retest/runner.rb CHANGED
@@ -17,7 +17,7 @@ module Retest
17
17
  end
18
18
 
19
19
  def ==(obj)
20
- command == obj.command
20
+ command == obj.command && obj.class == self.class
21
21
  end
22
22
 
23
23
  def cached_test_file
@@ -1,3 +1,3 @@
1
1
  module Retest
2
- VERSION = "1.1.0"
2
+ VERSION = "1.4.0"
3
3
  end
data/lib/retest.rb CHANGED
@@ -9,53 +9,9 @@ require "retest/options"
9
9
  require "retest/version_control"
10
10
  require "retest/setup"
11
11
  require "retest/command"
12
+ require "retest/file_system"
13
+ require "retest/program"
12
14
 
13
15
  module Retest
14
16
  class Error < StandardError; end
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
24
- puts "Launching Retest..."
25
- build.start
26
- puts "Ready to refactor! You can make file changes now"
27
- end
28
-
29
- def diff(branch)
30
- raise "Git not installed" unless VersionControl::Git.installed?
31
- test_files = repository.find_tests VersionControl::Git.diff_files(branch)
32
-
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 }
38
- end
39
-
40
- private
41
-
42
- def build
43
- Listen.to('.', only: /\.rb$/, relative: true) do |modified, added, removed|
44
- begin
45
- repository.add(added)
46
- repository.remove(removed)
47
- runner.remove(removed)
48
- system('clear 2>/dev/null') || system('cls 2>/dev/null')
49
-
50
- runner.run test_file_to_run(modified + added)
51
- rescue => e
52
- puts "Something went wrong: #{e.message}"
53
- end
54
- end
55
- end
56
-
57
- def test_file_to_run(changed_files)
58
- repository.find_test changed_files.first if runner.matching?
59
- end
60
- end
61
17
  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.1.0
4
+ version: 1.4.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-04-27 00:00:00.000000000 Z
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-similarity
@@ -78,6 +78,7 @@ files:
78
78
  - bin/test/rspec-rails
79
79
  - bin/test/rspec-ruby
80
80
  - bin/test/ruby-app
81
+ - bin/test/ruby-bare
81
82
  - exe/retest
82
83
  - lib/retest.rb
83
84
  - lib/retest/command.rb
@@ -85,7 +86,9 @@ files:
85
86
  - lib/retest/command/rake.rb
86
87
  - lib/retest/command/rspec.rb
87
88
  - lib/retest/command/ruby.rb
89
+ - lib/retest/file_system.rb
88
90
  - lib/retest/options.rb
91
+ - lib/retest/program.rb
89
92
  - lib/retest/repository.rb
90
93
  - lib/retest/runner.rb
91
94
  - lib/retest/setup.rb