retest 0.6.0.pre → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d366f005d9765a2da827543e444b70898d9a7f94f5fd8c2ca5782b3fa5a0058
4
- data.tar.gz: de7a1863a92188221e05955fa518a54c4f73fe3468ca15c47b7a6aa36f1baa66
3
+ metadata.gz: 62ae62a28685056281a2e89c483ac3b16f7eaa11c486d764d5404ebcbbeb493a
4
+ data.tar.gz: 4f9b0a6be227cea4e858e0a36ebafadbc47385629c17fe568e194be99348edfa
5
5
  SHA512:
6
- metadata.gz: 3277b79fce91040aac14f7e4980dc3687d6f02caed5ba47d629b106371780c65378e5dc1ecdcfa149c51e00f23022897aadb2c1cc249f3ca209ef267691f6f73
7
- data.tar.gz: f8de2fc0468a666afe0e526b334147c5c32dbcb42a0621dbf7a0e7af084806500cba083dc19833174c6a3862715e2ed046dbe032576ef844823e1cdbd763153a
6
+ metadata.gz: be4c01100fdbb277eae592d26bfd1cddce64097a815418d042b746ea1b438f182e744718850fba1ee4cf79a62a6218bdb222d267b4a14f478ddb0dcc5e0f67a1
7
+ data.tar.gz: 9bd2dd59fead6115cd26df9f1b180b1cc432a568003bfff3469a016ceac7852ee561c5701c48778dfd430229d9e9122128740e0269c17e9bad54a05f213c8622
@@ -15,14 +15,18 @@ on:
15
15
 
16
16
  jobs:
17
17
  test:
18
- runs-on: ubuntu-latest
18
+ runs-on: ${{ matrix.os }}
19
19
  strategy:
20
20
  matrix:
21
+ os: [ubuntu-latest]
21
22
  ruby:
22
23
  - 2.5
23
24
  - 2.6
24
25
  - 2.7
25
- name: Ruby ${{ matrix.ruby }} test
26
+ include:
27
+ - os: macos-latest
28
+ ruby: 2.5
29
+ name: Ruby ${{ matrix.ruby }} test (${{ matrix.os }})
26
30
  steps:
27
31
  - uses: actions/checkout@v2
28
32
  - name: Set up Ruby
@@ -32,4 +36,4 @@ jobs:
32
36
  bundler-cache: true
33
37
  - run: bundle install
34
38
  - run: bundle exec rake
35
- - run: bundle exec cucumber
39
+ - run: CUCUMBER_PUBLISH_QUIET=true bundle exec cucumber
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retest (0.6.0.pre)
4
+ retest (0.8.0.pre)
5
5
  listen (~> 3.2)
6
6
  string-similarity (~> 2.1)
7
+ tty-option (~> 0.1)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
@@ -61,7 +62,7 @@ GEM
61
62
  ffi (1.13.1)
62
63
  i18n (1.8.5)
63
64
  concurrent-ruby (~> 1.0)
64
- listen (3.3.1)
65
+ listen (3.4.1)
65
66
  rb-fsevent (~> 0.10, >= 0.10.3)
66
67
  rb-inotify (~> 0.9, >= 0.9.10)
67
68
  middleware (0.1.0)
@@ -85,6 +86,7 @@ GEM
85
86
  ffi (>= 1.0.0)
86
87
  thor (1.0.1)
87
88
  thread_safe (0.3.6)
89
+ tty-option (0.1.0)
88
90
  tzinfo (1.2.7)
89
91
  thread_safe (~> 0.1)
90
92
  zeitwerk (2.4.0)
data/README.md CHANGED
@@ -16,29 +16,46 @@ For fully fledged solutions, some cli tools already exists: [autotest](https://g
16
16
  Install it on your machine with:
17
17
 
18
18
  $ gem install retest
19
+ $ retest 'bundle exec rspec <test>'
19
20
 
20
21
  ## Usage
21
22
 
22
23
  Launch `retest` in your terminal after accessing your ruby project folder.
23
24
 
24
- Pass the test command surrounded by quotes. Use the placeholder `<test>` in your command to let `retest` find the matching test and replace the placeholder with the path of the test file.
25
+ Pass the test command surrounded by quotes. Use the placeholder `<test>` in your command to tell `retest` where to put the path of the test file in your command. Example: `retest 'bundle exec rspec <test>'`. When a file is changed `retest` will find its matching test and run it.
25
26
 
26
- ```bash
27
- # Let retest find the test file and replace the placeholder with the path of the test file
28
- $ retest 'bundle exec rake test TEST=<test>'
29
- $ retest 'rails test <test>'
30
- $ retest 'rspec <test>'
31
- $ retest 'ruby <test>'
32
- $ retest 'docker-compose exec web bundle exec rails test <test>'
33
-
34
- # Run the same command after a file change like all the spec files
35
- $ retest 'bundle exec rake test'
36
- $ retest 'rails test'
37
- $ retest 'rspec'
38
- $ retest 'docker-compose exec web bundle exec rails test'
39
-
40
- # Hardcode a test file to run independently from the file you change
41
- $ retest 'ruby all_tests.rb'
27
+ Learn more by running `retest -h`
28
+
29
+ ```
30
+ Usage: retest [OPTIONS] [COMMAND]
31
+
32
+ Watch a file change and run it matching spec.
33
+
34
+ Arguments:
35
+ COMMAND The test command to rerun when a file changes.
36
+ Use <test> placeholder to tell retest where to put the matching
37
+ spec.
38
+
39
+
40
+ Options:
41
+ --all Run all the specs of a specificied ruby setup
42
+ -h, --help Print usage
43
+ --rails Shortcut for 'bundle exec rails test <test>'
44
+ --rake Shortcut for 'bundle exec rake test TEST=<test>'
45
+ --rspec Shortcut for 'bundle exec rspec <test>'
46
+ --ruby Shortcut for 'bundle exec ruby <test>'
47
+
48
+ Examples:
49
+ Runs a matching rails test after a file change
50
+ $ retest 'bundle exec rails test <test>'
51
+ $ retest --rails
52
+
53
+ Runs all rails tests after a file change
54
+ $ retest 'bundle exec rails test'
55
+ $ retest --rails --all
56
+
57
+ Runs a hardcoded command after a file change
58
+ $ retest 'ruby lib/bottles_test.rb'
42
59
  ```
43
60
 
44
61
  The gem works as follows:
@@ -47,25 +64,23 @@ The gem works as follows:
47
64
  * When a test file is changed, retest will run the file test.
48
65
  * When multiple matching test files are found, retest asks you to confirm the file and save the answer.
49
66
  * When a test file is not found, retest runs the last run command or throw a 404.
50
- * Works with RSpec, MiniTest, Rake commands & bash commands (not aliases).
51
- * Works when installed and run in a Docker container.
52
67
 
53
68
  ### Docker
54
69
 
55
- Installing & launching the gem in a Docker container seems to work
70
+ Retest works in Docker too. You can install the gem and launch retest in your container while refactoring.
56
71
  ```bash
57
- $ docker-compose run web bash
72
+ $ docker-compose run web bash # enter your container
58
73
  $ gem install retest
59
74
  $ retest 'bundle exec rails test <test>'
60
75
  ```
61
76
 
62
- **Disclaimer:**
77
+ ### Disclaimer
63
78
  * If an error comes in try using `bundle exec` like so: `$ retest 'bundle exec rake test <test>'`
64
79
  * Aliases saved on ~/.bashrc or ~/.zshrc cannot be run that way with the `retest` command
65
80
 
66
81
  ## Ruby Support
67
82
 
68
- Retest supports ruby 2.5 and above.
83
+ Retest supports ruby 2.4 and above.
69
84
 
70
85
  ## Roadmap
71
86
 
data/exe/retest CHANGED
@@ -2,14 +2,12 @@
2
2
 
3
3
  require 'retest'
4
4
 
5
- Retest.logger = STDOUT
5
+ $stdout.sync = true
6
6
 
7
- Retest.log "Launching Retest..."
7
+ options = Retest::Options.new(ARGV)
8
8
 
9
- Retest
10
- .build(command: Retest::Command.for(ARGV.join))
11
- .start # not blocking
9
+ return puts options.help if options.help?
12
10
 
13
- Retest.log "Ready to refactor! You can make file changes now"
11
+ Retest.start(options.command) # not blocking
14
12
 
15
13
  sleep
data/lib/retest.rb CHANGED
@@ -2,25 +2,44 @@ require 'listen'
2
2
  require 'string/similarity'
3
3
 
4
4
  require "retest/version"
5
- require "retest/command"
5
+ require "retest/runner"
6
6
  require "retest/repository"
7
7
  require "retest/test_options"
8
- require "retest/listen_options"
9
- require "retest/concerns/configurable"
8
+ require "retest/options"
9
+ require "retest/version_control"
10
10
 
11
11
  module Retest
12
- include Configurable
13
12
  class Error < StandardError; end
14
13
 
15
- def self.build(command:, clear_window: true)
16
- Listen.to('.', ListenOptions.to_h) do |modified, added, removed|
17
- begin
18
- if modified.any?
19
- system("clear") || system("cls") if clear_window
20
- command.run(modified.first.strip)
14
+ class << self
15
+ def start(command)
16
+ puts "Launching Retest..."
17
+
18
+ build(
19
+ runner: Runner.for(command),
20
+ repository: Repository.new(files: VersionControl.files)
21
+ ).start
22
+
23
+ puts "Ready to refactor! You can make file changes now"
24
+ end
25
+
26
+ def build(runner:, repository:)
27
+ Listen.to('.', only: /\.rb$/, relative: true) do |modified, added, removed|
28
+ STDOUT.puts modified
29
+ STDOUT.puts added
30
+ STDOUT.puts removed
31
+ begin
32
+ if modified.any?
33
+ system('clear 2>/dev/null') || system('cls 2>/dev/null')
34
+ runner.run repository.find_test(modified.first.strip)
35
+ elsif added.any?
36
+ repository.add(added)
37
+ system('clear 2>/dev/null') || system('cls 2>/dev/null')
38
+ runner.run repository.find_test(added.first.strip)
39
+ end
40
+ rescue => e
41
+ puts "Something went wrong: #{e.message}"
21
42
  end
22
- rescue => e
23
- puts "Something went wrong: #{e.message}"
24
43
  end
25
44
  end
26
45
  end
@@ -0,0 +1,114 @@
1
+ require 'tty-option'
2
+
3
+ module Retest
4
+ class Options
5
+ include TTY::Option
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
+ NO_COMMAND = "echo You have no command assigned"
12
+
13
+ ALL_RAKE_COMMAND = "bundle exec rake test"
14
+ ALL_RAILS_COMMAND = "bundle exec rails test"
15
+ ALL_RSPEC_COMMAND = "bundle exec rspec"
16
+
17
+ usage do
18
+ program "retest"
19
+
20
+ command nil
21
+
22
+ desc "Watch a file change and run it matching spec."
23
+
24
+ example <<~EOS
25
+ Runs a matching rails test after a file change
26
+ $ retest 'bundle exec rails test <test>'
27
+ $ retest --rails
28
+ EOS
29
+
30
+ example <<~EOS
31
+ Runs all rails tests after a file change
32
+ $ retest 'bundle exec rails test'
33
+ $ retest --rails --all
34
+ EOS
35
+
36
+ example <<~EOS
37
+ Runs a hardcoded command after a file change
38
+ $ retest 'ruby lib/bottles_test.rb'
39
+ EOS
40
+ end
41
+
42
+ argument :command do
43
+ optional
44
+ desc <<~EOS
45
+ The test command to rerun when a file changes.
46
+ Use <test> placeholder to tell retest where to put the matching spec.
47
+ EOS
48
+ end
49
+
50
+ flag :all do
51
+ long "--all"
52
+ desc "Run all the specs of a specificied ruby setup"
53
+ end
54
+
55
+ flag :help do
56
+ short "-h"
57
+ long "--help"
58
+ desc "Print usage"
59
+ end
60
+
61
+ flag :rspec do
62
+ long "--rspec"
63
+ desc "Shortcut for '#{RSPEC_COMMAND}'"
64
+ end
65
+
66
+ flag :rake do
67
+ long "--rake"
68
+ desc "Shortcut for '#{RAKE_COMMAND}'"
69
+ end
70
+
71
+ flag :rails do
72
+ long "--rails"
73
+ desc "Shortcut for '#{RAILS_COMMAND}'"
74
+ end
75
+
76
+ flag :ruby do
77
+ long "--ruby"
78
+ desc "Shortcut for '#{RUBY_COMMAND}'"
79
+ end
80
+
81
+ attr_reader :args
82
+
83
+ def self.command(args)
84
+ new(args).command
85
+ end
86
+
87
+ def initialize(args = [])
88
+ self.args = args
89
+ end
90
+
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
+ def args=(args)
106
+ @args = args
107
+ parse args
108
+ end
109
+
110
+ def help?
111
+ params[:help]
112
+ end
113
+ end
114
+ end
@@ -1,17 +1,23 @@
1
1
  module Retest
2
2
  class Repository
3
- attr_accessor :files, :cache, :input_stream
3
+ attr_accessor :files, :cache, :input_stream, :output_stream
4
4
 
5
- def initialize(files: nil, cache: {}, input_stream: nil)
5
+ def initialize(files: [], cache: {}, input_stream: nil, output_stream: nil)
6
6
  @cache = cache
7
- @files = files || default_files
7
+ @files = files
8
8
  @input_stream = input_stream || STDIN
9
+ @output_stream = output_stream|| STDOUT
9
10
  end
10
11
 
11
12
  def find_test(path)
12
13
  cache[path] ||= select_from TestOptions.for(path, files: files)
13
14
  end
14
15
 
16
+ def add(new_files)
17
+ files.push(*new_files)
18
+ files.sort!
19
+ end
20
+
15
21
  private
16
22
 
17
23
  def select_from(tests)
@@ -24,12 +30,8 @@ module Retest
24
30
  end
25
31
  end
26
32
 
27
- def default_files
28
- @default_files ||= Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
29
- end
30
-
31
33
  def ask_question(tests)
32
- Retest.log <<~QUESTION
34
+ output_stream.puts <<~QUESTION
33
35
  We found few tests matching:
34
36
  #{list_options(tests)}
35
37
 
@@ -0,0 +1,42 @@
1
+ module Retest
2
+ class Runner
3
+ def self.for(test_command)
4
+ if test_command.include? '<test>'
5
+ VariableRunner
6
+ else
7
+ HardcodedRunner
8
+ end.new test_command
9
+ end
10
+
11
+ class VariableRunner
12
+ attr_reader :command
13
+
14
+ def initialize(command)
15
+ @command = command
16
+ @cached_test_file = nil
17
+ end
18
+
19
+ def ==(obj)
20
+ command == obj.command
21
+ end
22
+
23
+ def run(test_file = nil)
24
+ if @cached_test_file = test_file || @cached_test_file
25
+ puts "Test File Selected: #{@cached_test_file}"
26
+ system command.gsub('<test>', @cached_test_file)
27
+ else
28
+ puts <<~ERROR
29
+ 404 - Test File Not Found
30
+ Retest could not find a matching test file to run.
31
+ ERROR
32
+ end
33
+ end
34
+ end
35
+
36
+ HardcodedRunner = Struct.new(:command) do
37
+ def run(_ = nil)
38
+ system command
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module Retest
2
- VERSION = "0.6.0.pre"
2
+ VERSION = "0.8.0.pre"
3
3
  end
@@ -0,0 +1,38 @@
1
+ module Retest
2
+ class VersionControl
3
+ def self.files
4
+ [Git, NoVersionControl].select(&:installed?).first.new.files
5
+ end
6
+
7
+ def name; end
8
+ 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
+ end
38
+ end
data/retest.gemspec CHANGED
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
  spec.add_runtime_dependency "string-similarity", ["~> 2.1"]
29
29
  spec.add_runtime_dependency "listen", ["~> 3.2"]
30
+ spec.add_runtime_dependency "tty-option", ["~> 0.1"]
30
31
  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.6.0.pre
4
+ version: 0.8.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: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-similarity
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-option
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
41
55
  description:
42
56
  email:
43
57
  - alex@abletech.nz
@@ -59,13 +73,12 @@ files:
59
73
  - bin/setup
60
74
  - exe/retest
61
75
  - lib/retest.rb
62
- - lib/retest/command.rb
63
- - lib/retest/concerns/configurable.rb
64
- - lib/retest/listen_options.rb
76
+ - lib/retest/options.rb
65
77
  - lib/retest/repository.rb
78
+ - lib/retest/runner.rb
66
79
  - lib/retest/test_options.rb
67
80
  - lib/retest/version.rb
68
- - output.log
81
+ - lib/retest/version_control.rb
69
82
  - retest.gemspec
70
83
  homepage: https://github.com/AlexB52/retest
71
84
  licenses:
@@ -1,50 +0,0 @@
1
- require 'open3'
2
-
3
- module Retest
4
- class Command
5
- def self.for(test_command)
6
- if test_command.include? '<test>'
7
- VariableCommand
8
- else
9
- HardcodedCommand
10
- end.new test_command
11
- end
12
-
13
- class VariableCommand
14
- attr_reader :command, :repository, :cached_test_file
15
-
16
- def initialize(command, repository: nil)
17
- @repository = repository || Repository.new
18
- @command = command
19
- end
20
-
21
- def ==(obj)
22
- command == obj.command
23
- end
24
-
25
- def run(file_changed)
26
- if @cached_test_file = test_file(file_changed)
27
- stdout_and_stderr_str, _ = Open3.capture2e command.gsub('<test>', cached_test_file)
28
- Retest.log "Test File Selected: #{cached_test_file}"
29
- Retest.log stdout_and_stderr_str
30
- else
31
- Retest.log <<~ERROR
32
- 404 - Test File Not Found
33
- Retest could not find a matching test file to run.
34
- ERROR
35
- end
36
- end
37
-
38
- def test_file(file_changed)
39
- repository.find_test(file_changed) || cached_test_file
40
- end
41
- end
42
-
43
- HardcodedCommand = Struct.new(:command) do
44
- def run(_)
45
- stdout_and_stderr_str, _ = Open3.capture2e(command)
46
- Retest.log stdout_and_stderr_str
47
- end
48
- end
49
- end
50
- end
@@ -1,30 +0,0 @@
1
- module Configurable
2
- def self.included(base)
3
- base.extend ClassMethods
4
- end
5
-
6
- class Configuration
7
- extend Forwardable
8
-
9
- attr_accessor :logger
10
-
11
- def_delegator :logger, :puts
12
- alias :log :puts
13
- end
14
-
15
- module ClassMethods
16
- extend Forwardable
17
-
18
- attr_writer :configuration
19
-
20
- def_delegators :configuration, :log, :logger, :logger=
21
-
22
- def configuration
23
- @configuration ||= Configuration.new
24
- end
25
-
26
- def configure
27
- yield configuration
28
- end
29
- end
30
- end
@@ -1,36 +0,0 @@
1
- module Retest
2
- class ListenOptions
3
- IGNORE_REGEX = /node_modules|tmp|\.sqlite|\.byebug_history/
4
-
5
- class << self
6
- def to_h(tool = GitTool.new)
7
- return {ignore: IGNORE_REGEX, relative: true} unless tool.installed?
8
-
9
- {only: regex_for(tool.files), relative: true}
10
- end
11
-
12
- private
13
-
14
- def regex_for(files)
15
- Regexp.new files.split("\n").join('|')
16
- end
17
- end
18
- end
19
-
20
- class GitTool
21
- attr_reader :name
22
- alias :to_s :name
23
-
24
- def initialize
25
- @name = 'git'
26
- end
27
-
28
- def installed?
29
- system "git -C . rev-parse 2>&1"
30
- end
31
-
32
- def files
33
- `git ls-files`
34
- end
35
- end
36
- end
data/output.log DELETED
File without changes