retest 1.5.0 → 1.6.2

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: ce75120a1212540c1e510e4fd3d28e505f68d79e4e557b48e34cfda769d35613
4
- data.tar.gz: ff2a3cc3644ce392adb38d8a87ffea711bbc6baaeb20f70099b2c0771cce3cf6
3
+ metadata.gz: fa89818d98ad713bc6982f8f68b94afe80a09dc1677068dda42dbad1a2300c72
4
+ data.tar.gz: 60206dca5d68cdf634c47424e8712c2b8e4884b543bd85bb55fc0429300b4265
5
5
  SHA512:
6
- metadata.gz: 6741101b8345dfcba37002b1265d6ed5170c8b82eccc8a143b20a7fb77d196f05b9c4b4af142a7fed62952aa5251769523243c997884334cc8a3d484f93f3207
7
- data.tar.gz: 3c4f2484eb2400a47d35c22a33f6db47ede1e0fc401dccdede644114f90bc2765f1e1e6df5b2fea7e761d77983a863f2c917cfb5afd71ffabd89e884f1ad85c6
6
+ metadata.gz: 64777879959eed5656066cca23508738deb78566ee87144e67066c9e15e3d6da6dfcce1bd7bac9ff3f66c94cf66976f709663b1b4df3a5242cd9a6a0e6cb9491
7
+ data.tar.gz: bd55fd227c159b11eb7b2389c319e38e931af90ca0b29b0bdc343b5a7ca3996086bebf6d4099fcc67e654da30022bd53797c437911defeda1f98b6196c988ec4
@@ -23,6 +23,8 @@ jobs:
23
23
  - 2.5
24
24
  - 2.6
25
25
  - 2.7
26
+ - '3.0'
27
+ - 3.1
26
28
  include:
27
29
  - os: macos-latest
28
30
  ruby: 2.5
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.6
1
+ 2.7.5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retest (1.5.0)
4
+ retest (1.6.2)
5
5
  listen (~> 3.2)
6
6
  string-similarity (~> 2.1)
7
7
  tty-option (~> 0.1)
@@ -10,13 +10,13 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  byebug (11.1.3)
13
- ffi (1.15.4)
14
- listen (3.7.0)
13
+ ffi (1.15.5)
14
+ listen (3.7.1)
15
15
  rb-fsevent (~> 0.10, >= 0.10.3)
16
16
  rb-inotify (~> 0.9, >= 0.9.10)
17
- minitest (5.14.1)
17
+ minitest (5.15.0)
18
18
  rake (12.3.3)
19
- rb-fsevent (0.11.0)
19
+ rb-fsevent (0.11.1)
20
20
  rb-inotify (0.10.1)
21
21
  ffi (~> 1.0)
22
22
  string-similarity (2.1.0)
data/README.md CHANGED
@@ -6,7 +6,8 @@ Retest is a small command-line tool to help you refactor code by watching a file
6
6
 
7
7
  ## Demo
8
8
 
9
- ![demo](https://alexbarret.com/images/external/retest-demo-26bcad04.gif)
9
+
10
+ https://user-images.githubusercontent.com/7149034/153734043-1d136f27-5c24-4676-868b-0fde76016b13.mp4
10
11
 
11
12
  ## Installation
12
13
 
@@ -36,7 +37,11 @@ Example:
36
37
 
37
38
  In this example, the feature spec `spec/features/posts_spec.rb` will be tested after any ruby file is updated.
38
39
 
39
- #### 2. Run a dynamic command
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
40
45
 
41
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.
42
47
 
@@ -45,6 +50,16 @@ Example:
45
50
  $ retest 'bin/rails test <test>'
46
51
 
47
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`
48
63
 
49
64
  #### 3. Run a dynamic command with shortcuts
50
65
 
data/bin/debug CHANGED
@@ -1,32 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "retest"
5
4
  require "byebug"
6
5
 
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
- repository = Retest::Repository.new(files: Retest::VersionControl.files)
17
- command = Retest::Command.for_options(options)
18
- runner = Retest::Runners.runner_for(command.to_s)
19
-
20
- program = Retest::Program.new(
21
- extension: options.extension,
22
- repository: repository,
23
- command: command,
24
- runner: runner
25
- )
26
-
27
- if options.params[:diff]
28
- program.diff(options.params[:diff])
29
- else
30
- program.start # not blocking
31
- sleep
32
- end
6
+ eval(File.read("exe/retest"))
data/exe/retest CHANGED
@@ -14,9 +14,12 @@ end
14
14
  repository = Retest::Repository.new(files: Retest::VersionControl.files)
15
15
  command = Retest::Command.for_options(options)
16
16
  runner = Retest::Runners.runner_for(command.to_s)
17
+ sounds = Retest::Sounds.for(options)
18
+
19
+ sounds.play(:start)
20
+ runner.add_observer(sounds)
17
21
 
18
22
  program = Retest::Program.new(
19
- extension: options.extension,
20
23
  repository: repository,
21
24
  command: command,
22
25
  runner: runner
@@ -24,7 +27,21 @@ program = Retest::Program.new(
24
27
 
25
28
  if options.params[:diff]
26
29
  program.diff(options.params[:diff])
27
- else
28
- program.start # not blocking
29
- sleep
30
+ return
30
31
  end
32
+
33
+ # Main action
34
+
35
+ $stdout.puts "Launching Retest..."
36
+ Listen.to('.', only: options.extension, relative: true) do |modified, added, removed|
37
+ begin
38
+ program.run(modified, added, removed)
39
+ rescue => e
40
+ $stdout.puts "Something went wrong: #{e.message}"
41
+ end
42
+ end.start
43
+ $stdout.puts "Ready to refactor! You can make file changes now"
44
+
45
+ # not blocking
46
+
47
+ sleep
@@ -19,10 +19,10 @@ module Retest
19
19
  def_delegators :options, :params, :full_suite?, :auto?
20
20
 
21
21
  attr_accessor :options, :setup
22
- def initialize(options: Options.new, setup: Setup.new, output_stream: STDOUT)
22
+ def initialize(options: Options.new, setup: Setup.new, stdout: $stdout)
23
23
  @options = options
24
24
  @setup = setup
25
- @output_stream = output_stream
25
+ @stdout = stdout
26
26
  end
27
27
 
28
28
  def command
@@ -52,7 +52,7 @@ module Retest
52
52
  end
53
53
 
54
54
  def default_command
55
- @output_stream.puts "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'"
55
+ @stdout.puts "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'"
56
56
  setup_command
57
57
  end
58
58
 
@@ -76,6 +76,11 @@ module Retest
76
76
  desc "Indentify repository setup and runs appropriate command"
77
77
  end
78
78
 
79
+ flag :notify do
80
+ long "--notify"
81
+ desc "Play a sound when specs pass or fail (macOS only)"
82
+ end
83
+
79
84
  flag :help do
80
85
  short "-h"
81
86
  long "--help"
@@ -130,6 +135,10 @@ module Retest
130
135
  params[:auto]
131
136
  end
132
137
 
138
+ def notify?
139
+ params[:notify]
140
+ end
141
+
133
142
  def extension
134
143
  Regexp.new(params[:ext])
135
144
  end
@@ -1,17 +1,18 @@
1
1
  module Retest
2
2
  class Program
3
- attr_accessor :runner, :repository, :command, :extension
4
- def initialize(runner: nil, repository: nil, command: nil, extension: /\.rb$/)
3
+ attr_accessor :runner, :repository, :command
4
+ def initialize(runner: nil, repository: nil, command: nil)
5
5
  @runner = runner
6
6
  @repository = repository
7
7
  @command = command
8
- @extension = extension
9
8
  end
10
9
 
11
- def start
12
- puts "Launching Retest..."
13
- build.start
14
- puts "Ready to refactor! You can make file changes now"
10
+ def run(modified, added, removed)
11
+ repository.sync(added: added, removed: removed)
12
+ runner.sync(added: added, removed: removed)
13
+ system('clear 2>/dev/null') || system('cls 2>/dev/null')
14
+
15
+ runner.run (modified + added).first, repository: repository
15
16
  end
16
17
 
17
18
  def diff(branch)
@@ -24,21 +25,5 @@ module Retest
24
25
  puts "Running tests..."
25
26
  runner.run_all_tests command.format_batch(test_files)
26
27
  end
27
-
28
- private
29
-
30
- def build
31
- Listen.to('.', only: extension, relative: true) do |modified, added, removed|
32
- begin
33
- repository.sync(added: added, removed: removed)
34
- runner.sync(added: added, removed: removed)
35
- system('clear 2>/dev/null') || system('cls 2>/dev/null')
36
-
37
- runner.run (modified + added).first, repository: repository
38
- rescue => e
39
- puts "Something went wrong: #{e.message}"
40
- end
41
- end
42
- end
43
28
  end
44
29
  end
@@ -1,12 +1,12 @@
1
1
  module Retest
2
2
  class Repository
3
- attr_accessor :files, :cache, :input_stream, :output_stream
3
+ attr_accessor :files, :cache, :stdin, :stdout
4
4
 
5
- def initialize(files: [], cache: {}, input_stream: nil, output_stream: nil)
6
- @cache = cache
7
- @files = files
8
- @input_stream = input_stream || STDIN
9
- @output_stream = output_stream|| STDOUT
5
+ def initialize(files: [], cache: {}, stdin: $stdin, stdout: $stdout)
6
+ @cache = cache
7
+ @files = files
8
+ @stdin = stdin
9
+ @stdout = stdout
10
10
  end
11
11
 
12
12
  def find_test(path)
@@ -61,7 +61,7 @@ module Retest
61
61
  end
62
62
 
63
63
  def ask_question(tests)
64
- output_stream.puts(<<~QUESTION)
64
+ stdout.puts(<<~QUESTION)
65
65
  We found few tests matching: #{@path}
66
66
  #{list_options(tests)}
67
67
 
@@ -77,7 +77,7 @@ module Retest
77
77
  end
78
78
 
79
79
  def get_input
80
- input_stream.gets.chomp.to_i
80
+ stdin.gets.chomp.to_i
81
81
  end
82
82
  end
83
83
  end
@@ -3,10 +3,10 @@ module Retest
3
3
  class ChangeRunner < Runner
4
4
  def run(changed_file = nil, repository: nil)
5
5
  if changed_file
6
- puts "Changed File Selected: #{changed_file}"
7
- system command.gsub('<changed>', changed_file)
6
+ log("Changed File Selected: #{changed_file}")
7
+ system_run command.gsub('<changed>', changed_file)
8
8
  else
9
- puts <<~ERROR
9
+ log(<<~ERROR)
10
10
  404 - Test File Not Found
11
11
  Retest could not find a changed file to run.
12
12
  ERROR
@@ -1,8 +1,11 @@
1
1
  module Retest
2
2
  module Runners
3
3
  class Runner
4
- attr_accessor :command
5
- def initialize(command)
4
+ include Observable
5
+
6
+ attr_accessor :command, :stdout
7
+ def initialize(command, stdout: $stdout)
8
+ @stdout = stdout
6
9
  @command = command
7
10
  end
8
11
 
@@ -11,16 +14,28 @@ module Retest
11
14
  end
12
15
 
13
16
  def run(changed_file = nil, repository: nil)
14
- system command
17
+ system_run command
15
18
  end
16
19
 
17
20
  def run_all_tests(tests_string)
18
- puts "Test File Selected: #{tests_string}"
19
- system command.gsub('<test>', tests_string)
21
+ log("Test File Selected: #{tests_string}")
22
+ system_run command.gsub('<test>', tests_string)
20
23
  end
21
24
 
22
25
  def sync(added:, removed:)
23
26
  end
27
+
28
+ private
29
+
30
+ def system_run(command)
31
+ result = system(command) ? :tests_pass : :tests_fail
32
+ changed
33
+ notify_observers(result)
34
+ end
35
+
36
+ def log(message)
37
+ stdout.puts(message)
38
+ end
24
39
  end
25
40
  end
26
41
  end
@@ -13,10 +13,10 @@ module Retest
13
13
  self.cached_test_file = repository.find_test(changed_file)
14
14
 
15
15
  if cached_test_file
16
- puts "Test File Selected: #{cached_test_file}"
17
- system command.gsub('<test>', cached_test_file)
16
+ log("Test File Selected: #{cached_test_file}")
17
+ system_run command.gsub('<test>', cached_test_file)
18
18
  else
19
- puts <<~ERROR
19
+ log(<<~ERROR)
20
20
  404 - Test File Not Found
21
21
  Retest could not find a matching test file to run.
22
22
  ERROR
@@ -14,14 +14,14 @@ module Retest
14
14
 
15
15
  return print_test_file_not_found unless cached_test_file
16
16
 
17
- puts(<<~FILES)
17
+ log(<<~FILES)
18
18
  Files Selected:
19
- - file: #{changed_file}
19
+ - changed: #{changed_file}
20
20
  - test: #{cached_test_file}
21
21
 
22
22
  FILES
23
23
 
24
- system command
24
+ system_run command
25
25
  .gsub('<test>', cached_test_file)
26
26
  .gsub('<changed>', changed_file)
27
27
  end
@@ -33,7 +33,7 @@ module Retest
33
33
  private
34
34
 
35
35
  def print_test_file_not_found
36
- puts <<~ERROR
36
+ log(<<~ERROR)
37
37
  404 - Test File Not Found
38
38
  Retest could not find a matching test file to run.
39
39
  ERROR
@@ -0,0 +1,54 @@
1
+ module Retest
2
+ module Sounds
3
+ module_function
4
+
5
+ def for(options)
6
+ options.notify? ? MacOS.new : Mute.new
7
+ end
8
+
9
+ class Mute
10
+ def play(_)
11
+ end
12
+ alias update play
13
+ end
14
+
15
+ class MacOS
16
+ def initialize(kernel: Kernel, thread: Thread)
17
+ @kernel = kernel
18
+ @thread = thread
19
+ end
20
+
21
+ def play(sound)
22
+ args = case sound
23
+ when :tests_fail
24
+ ['afplay', '/System/Library/Sounds/Sosumi.aiff']
25
+ when :tests_pass
26
+ ['afplay', '/System/Library/Sounds/Funk.aiff']
27
+ when :start
28
+ ['afplay', '/System/Library/Sounds/Blow.aiff']
29
+ else
30
+ raise ArgumentError.new("No sounds were found for type: #{sound}.")
31
+ end
32
+
33
+ @thread.new { @kernel.system(*args) }
34
+ end
35
+ alias update play
36
+ end
37
+ end
38
+ end
39
+
40
+ # List of Mac Audio Files:
41
+ # afplay /System/Library/Sounds/Basso.aiff
42
+ # afplay /System/Library/Sounds/Bottle.aiff
43
+ # afplay /System/Library/Sounds/Funk.aiff
44
+ # afplay /System/Library/Sounds/Hero.aiff
45
+ # afplay /System/Library/Sounds/Ping.aiff
46
+ # afplay /System/Library/Sounds/Purr.aiff
47
+ # afplay /System/Library/Sounds/Submarine.aiff
48
+ # afplay /System/Library/Sounds/Blow.aiff
49
+ # afplay /System/Library/Sounds/Frog.aiff
50
+ # afplay /System/Library/Sounds/Glass.aiff
51
+ # afplay /System/Library/Sounds/Morse.aiff
52
+ # afplay /System/Library/Sounds/Pop.aiff
53
+ # afplay /System/Library/Sounds/Sosumi.aiff
54
+ # afplay /System/Library/Sounds/Tink.aiff
@@ -1,3 +1,3 @@
1
1
  module Retest
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.2"
3
3
  end
data/lib/retest.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'listen'
2
2
  require 'string/similarity'
3
+ require 'observer'
3
4
 
4
5
  require "retest/version"
5
6
  require "retest/runners"
@@ -11,6 +12,7 @@ require "retest/setup"
11
12
  require "retest/command"
12
13
  require "retest/file_system"
13
14
  require "retest/program"
15
+ require "retest/sounds"
14
16
 
15
17
  module Retest
16
18
  class Error < StandardError; 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.5.0
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Barret
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-17 00:00:00.000000000 Z
11
+ date: 2022-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-similarity
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.1'
55
- description:
55
+ description:
56
56
  email:
57
57
  - alex@abletech.nz
58
58
  executables:
@@ -96,6 +96,7 @@ files:
96
96
  - lib/retest/runners/test_runner.rb
97
97
  - lib/retest/runners/variable_runner.rb
98
98
  - lib/retest/setup.rb
99
+ - lib/retest/sounds.rb
99
100
  - lib/retest/test_options.rb
100
101
  - lib/retest/version.rb
101
102
  - lib/retest/version_control.rb
@@ -108,7 +109,7 @@ licenses:
108
109
  metadata:
109
110
  homepage_uri: https://github.com/AlexB52/retest
110
111
  source_code_uri: https://github.com/AlexB52/retest
111
- post_install_message:
112
+ post_install_message:
112
113
  rdoc_options: []
113
114
  require_paths:
114
115
  - lib
@@ -123,8 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  - !ruby/object:Gem::Version
124
125
  version: '0'
125
126
  requirements: []
126
- rubygems_version: 3.0.3
127
- signing_key:
127
+ rubygems_version: 3.1.6
128
+ signing_key:
128
129
  specification_version: 4
129
130
  summary: A simple command line tool to watch file change and run its matching spec.
130
131
  test_files: []