retest 1.0.0.pre2 → 1.3.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: 9a66f6a72a5f0e26fd60a1426b38c2bc179c56937b0c5a38ecbe354863f00b92
4
- data.tar.gz: 3eb1fa4f48f60db34dc185d5f7b431725c1096ac4ce0200146b34e7c4c79a28e
3
+ metadata.gz: fa015efc571907fe2ad6fda917ea82471435de7c1ac37b23a2f3a9944f39b00a
4
+ data.tar.gz: b3899a60b7f08faa776df749f3b266ba045a9b1f9bb8d03dbef967605fd26707
5
5
  SHA512:
6
- metadata.gz: 9b6bdf72eb1aa0f8acdbea0cd360a25aab3d7e34e116dffcdfa2b77288c03df7eb069d99fd18767d61fbe593f19f4a2d0c73e10e1c2c7999f239647b421973a8
7
- data.tar.gz: 7a7ce5af2c787ab6e35133733c491ee9d02a4e4d628ee836c7642f75210deb9bb79b54f3d679cbde7517c1bd4d4b50e33ab979df361f6b889e210f2aa212962e
6
+ metadata.gz: ece665996aadbc266ed44aa2984abaacb7be1beb6649ff19c901ea023787801f11544331ff392679c2200e887d0bdbf3cbc94dac11e321ba4807041399b883bb
7
+ data.tar.gz: 70bd6e9761f7392885a65e135f7dcc94a1c1a59d6d4096fb62d951b8080b7c650487f18a09aef259cd2775b0b8f42294a588ca0ee12515228b72f3cf335e34c0
@@ -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.0.0.pre2)
4
+ retest (1.3.0.pre)
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.0)
14
- listen (3.5.0)
13
+ ffi (1.15.3)
14
+ listen (3.6.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)
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)
@@ -13,6 +15,7 @@ Install it on your machine without adding it on a Gemfile:
13
15
  $ gem install retest
14
16
 
15
17
  ## Usage
18
+ ### Refactoring
16
19
 
17
20
  Launch `retest` in your terminal after accessing your ruby repository.
18
21
 
@@ -28,11 +31,10 @@ Few shortcut flags exist to avoid writing the full test command.
28
31
  $ retest --rails
29
32
  $ retest --rake --all
30
33
 
31
- Finally let retest automatically find your ruby setup and run the appropriate command using:
34
+ Or let retest find your ruby setup and run the appropriate command using:
32
35
 
33
36
  $ retest
34
- $ retest --auto
35
- $ retest --auto --all
37
+ $ retest --all
36
38
 
37
39
  The gem works as follows:
38
40
 
@@ -41,7 +43,15 @@ The gem works as follows:
41
43
  * When multiple matching test files are found, retest asks you to confirm the file and save the answer.
42
44
  * When a test file is not found, retest runs the last run command or throw a 404.
43
45
 
44
- See more example with `retest -h`
46
+ ### Diff Check
47
+
48
+ You can diff a branch and test all the relevant test files before pushing your branch and trigger the full CI suite.
49
+
50
+ $ retest --diff origin/main
51
+
52
+ ### Help
53
+
54
+ See more examples with `retest -h`
45
55
 
46
56
  ```
47
57
  Usage: retest [OPTIONS] [COMMAND]
@@ -55,13 +65,16 @@ Arguments:
55
65
 
56
66
 
57
67
  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>'
68
+ --all Run all the specs of a specificied ruby setup
69
+ --auto Indentify repository setup and runs appropriate
70
+ command
71
+ --diff=git-branch Pipes all matching tests from diffed branch to test
72
+ command
73
+ -h, --help Print usage
74
+ --rails Shortcut for a standard Rails setup
75
+ --rake Shortcut for a standard Rake setup
76
+ --rspec Shortcut for a standard RSpec setup
77
+ --ruby Shortcut for a Ruby project
65
78
 
66
79
  Examples:
67
80
  Runs a matching rails test after a file change
data/bin/debug CHANGED
@@ -13,9 +13,14 @@ 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(options.command)
21
+ repository: repository,
22
+ command: command,
23
+ runner: runner
19
24
  )
20
25
 
21
26
  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,14 @@ 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(options.command)
19
+ repository: repository,
20
+ command: command,
21
+ runner: runner
17
22
  )
18
23
 
19
24
  if options.params[:diff]
data/lib/retest.rb CHANGED
@@ -8,53 +8,10 @@ require "retest/test_options"
8
8
  require "retest/options"
9
9
  require "retest/version_control"
10
10
  require "retest/setup"
11
+ require "retest/command"
12
+ require "retest/file_system"
13
+ require "retest/program"
11
14
 
12
15
  module Retest
13
16
  class Error < StandardError; end
14
-
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
23
- puts "Launching Retest..."
24
- build.start
25
- puts "Ready to refactor! You can make file changes now"
26
- end
27
-
28
- def diff(branch)
29
- raise "Git not installed" unless VersionControl::Git.installed?
30
- test_files = repository.find_tests VersionControl::Git.diff_files(branch)
31
-
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 }
37
- end
38
-
39
- private
40
-
41
- def build
42
- Listen.to('.', only: /\.rb$/, relative: true) do |modified, added, removed|
43
- begin
44
- repository.add(added)
45
- repository.remove(removed)
46
- runner.remove(removed)
47
- system('clear 2>/dev/null') || system('cls 2>/dev/null')
48
-
49
- runner.run test_file_to_run(modified + added)
50
- rescue => e
51
- puts "Something went wrong: #{e.message}"
52
- end
53
- end
54
- end
55
-
56
- def test_file_to_run(changed_files)
57
- repository.find_test changed_files.first if runner.matching?
58
- end
59
- end
60
17
  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.new(all: full_suite?)
63
+ end
64
+
65
+ def rails_command
66
+ Rails.new(all: full_suite?)
67
+ end
68
+
69
+ def rake_command
70
+ Rake.new(all: full_suite?)
71
+ end
72
+
73
+ def ruby_command
74
+ Ruby.new(all: full_suite?)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,29 @@
1
+ module Retest
2
+ class 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
9
+ end
10
+
11
+ def to_s
12
+ return "#{root_command} <test>" unless all
13
+ root_command
14
+ end
15
+
16
+ def run_all(*files, runner:)
17
+ runner.run files.join(' ')
18
+ end
19
+
20
+ private
21
+
22
+ def root_command
23
+ return 'bin/rails test' if file_system.exist? 'bin/rails'
24
+
25
+ 'bundle exec rails test'
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Retest
2
+ class 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
9
+ end
10
+
11
+ def to_s
12
+ return "#{root_command} TEST=<test>" unless all
13
+ root_command
14
+ end
15
+
16
+ def run_all(*files, runner:)
17
+ runner.run files.size > 1 ? "\"{#{files.join(',')}}\"" : files.first
18
+ end
19
+
20
+ private
21
+
22
+ def root_command
23
+ return 'bin/rake test' if file_system.exist? 'bin/rake'
24
+
25
+ 'bundle exec rake test'
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Retest
2
+ class 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
9
+ end
10
+
11
+ def to_s
12
+ return "#{root_command} <test>" unless all
13
+ root_command
14
+ end
15
+
16
+ def run_all(*files, runner:)
17
+ runner.run files.join(' ')
18
+ end
19
+
20
+ private
21
+
22
+ def root_command
23
+ return 'bin/rspec' if file_system.exist? 'bin/rspec'
24
+
25
+ 'bundle exec rspec'
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module Retest
2
+ class 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}"}
14
+ end
15
+
16
+ def to_s
17
+ if file_system.exist? 'Gemfile.lock'
18
+ 'bundle exec ruby <test>'
19
+ else
20
+ 'ruby <test>'
21
+ end
22
+ end
23
+ end
24
+ end
25
+ 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
 
@@ -87,22 +78,22 @@ module Retest
87
78
 
88
79
  flag :rspec do
89
80
  long "--rspec"
90
- desc "Shortcut for '#{RSPEC_COMMAND}'"
81
+ desc "Shortcut for a standard RSpec setup"
91
82
  end
92
83
 
93
84
  flag :rake do
94
85
  long "--rake"
95
- desc "Shortcut for '#{RAKE_COMMAND}'"
86
+ desc "Shortcut for a standard Rake setup"
96
87
  end
97
88
 
98
89
  flag :rails do
99
90
  long "--rails"
100
- desc "Shortcut for '#{RAILS_COMMAND}'"
91
+ desc "Shortcut for a standard Rails setup"
101
92
  end
102
93
 
103
94
  flag :ruby do
104
95
  long "--ruby"
105
- desc "Shortcut for '#{RUBY_COMMAND}'"
96
+ desc "Shortcut for a Ruby project"
106
97
  end
107
98
 
108
99
  attr_reader :args
@@ -111,22 +102,8 @@ module Retest
111
102
  new(args).command
112
103
  end
113
104
 
114
- def initialize(args = [], output_stream: STDOUT, setup: Setup)
105
+ def initialize(args = [])
115
106
  self.args = args
116
- @output_stream = output_stream
117
- @setup = setup
118
- end
119
-
120
- def 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
129
- end
130
107
  end
131
108
 
132
109
  def args=(args)
@@ -138,45 +115,19 @@ module Retest
138
115
  params[:help]
139
116
  end
140
117
 
141
- private
142
-
143
118
  def full_suite?
144
119
  params[:all]
145
120
  end
146
121
 
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
122
+ def auto?
123
+ return true if no_options_passed?
124
+ params[:auto]
159
125
  end
160
126
 
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
127
+ private
177
128
 
178
- def ruby_command
179
- RUBY_COMMAND
129
+ def no_options_passed?
130
+ params.to_h.values.compact.uniq == [false]
180
131
  end
181
132
  end
182
133
  end
@@ -0,0 +1,48 @@
1
+ module Retest
2
+ class Program
3
+ attr_accessor :runner, :repository, :command
4
+ def initialize(runner: nil, repository: nil, command: nil)
5
+ @runner = runner
6
+ @repository = repository
7
+ @command = command
8
+ end
9
+
10
+ def start
11
+ puts "Launching Retest..."
12
+ build.start
13
+ puts "Ready to refactor! You can make file changes now"
14
+ end
15
+
16
+ def diff(branch)
17
+ raise "Git not installed" unless VersionControl::Git.installed?
18
+ test_files = repository.find_tests VersionControl::Git.diff_files(branch)
19
+
20
+ puts "Tests found:"
21
+ test_files.each { |test_file| puts " - #{test_file}" }
22
+
23
+ puts "Running tests..."
24
+ command.run_all *test_files, runner: runner
25
+ end
26
+
27
+ private
28
+
29
+ def build
30
+ Listen.to('.', only: /\.rb$/, relative: true) do |modified, added, removed|
31
+ begin
32
+ repository.add(added)
33
+ repository.remove(removed)
34
+ runner.remove(removed)
35
+ system('clear 2>/dev/null') || system('cls 2>/dev/null')
36
+
37
+ runner.run test_file_to_run(modified + added)
38
+ rescue => e
39
+ puts "Something went wrong: #{e.message}"
40
+ end
41
+ end
42
+ end
43
+
44
+ def test_file_to_run(changed_files)
45
+ repository.find_test changed_files.first if runner.matching?
46
+ end
47
+ end
48
+ 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
data/lib/retest/setup.rb CHANGED
@@ -31,7 +31,7 @@ module Retest
31
31
  end
32
32
 
33
33
  def rails?
34
- File.exist? 'bin/rails'
34
+ has_gem? 'rails'
35
35
  end
36
36
 
37
37
  def rake?
@@ -1,3 +1,3 @@
1
1
  module Retest
2
- VERSION = "1.0.0.pre2"
2
+ VERSION = "1.3.0.pre"
3
3
  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.0.0.pre2
4
+ version: 1.3.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-03-29 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-similarity
@@ -78,9 +78,17 @@ 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
84
+ - lib/retest/command.rb
85
+ - lib/retest/command/rails.rb
86
+ - lib/retest/command/rake.rb
87
+ - lib/retest/command/rspec.rb
88
+ - lib/retest/command/ruby.rb
89
+ - lib/retest/file_system.rb
83
90
  - lib/retest/options.rb
91
+ - lib/retest/program.rb
84
92
  - lib/retest/repository.rb
85
93
  - lib/retest/runner.rb
86
94
  - lib/retest/setup.rb