retest 1.2.0 → 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: 13ce5e74ba4682f3777259a6565c585271dd7db5f6d753c4e5d6836f5c457634
4
- data.tar.gz: bfc62c5fd481982435b3ee8e372839b7678e489d8123bbcd629c5ba56c2b7012
3
+ metadata.gz: fa015efc571907fe2ad6fda917ea82471435de7c1ac37b23a2f3a9944f39b00a
4
+ data.tar.gz: b3899a60b7f08faa776df749f3b266ba045a9b1f9bb8d03dbef967605fd26707
5
5
  SHA512:
6
- metadata.gz: ef3ee2efb84b012c5b6ba340d81e578ec512960e7fc28516abbc23689c8ad43f3c3a5ecd1855d51df1bcee5a426fdd92aef3f460a65fbb7c39d35d83ad08c735
7
- data.tar.gz: e5af1bbe78c6bfa347088fc0ec3c8e985a1dbad5393f47640b7885cf4a0bbdd5cbc8c8922f7b189794027af4e7091dc36fd81693e5d785cf11e330fd2ea78dc0
6
+ metadata.gz: ece665996aadbc266ed44aa2984abaacb7be1beb6649ff19c901ea023787801f11544331ff392679c2200e887d0bdbf3cbc94dac11e321ba4807041399b883bb
7
+ data.tar.gz: 70bd6e9761f7392885a65e135f7dcc94a1c1a59d6d4096fb62d951b8080b7c650487f18a09aef259cd2775b0b8f42294a588ca0ee12515228b72f3cf335e34c0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retest (1.2.0)
4
+ retest (1.3.0.pre)
5
5
  listen (~> 3.2)
6
6
  string-similarity (~> 2.1)
7
7
  tty-option (~> 0.1)
@@ -10,8 +10,8 @@ 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)
data/README.md CHANGED
@@ -65,13 +65,16 @@ Arguments:
65
65
 
66
66
 
67
67
  Options:
68
- --all Run all the specs of a specificied ruby setup
69
- --auto Indentify repository setup and runs appropriate command
70
- -h, --help Print usage
71
- --rails Shortcut for 'bundle exec rails test <test>'
72
- --rake Shortcut for 'bundle exec rake test TEST=<test>'
73
- --rspec Shortcut for 'bundle exec rspec <test>'
74
- --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
75
78
 
76
79
  Examples:
77
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(Retest::Command.for_options(options))
21
+ repository: repository,
22
+ command: command,
23
+ runner: runner
19
24
  )
20
25
 
21
26
  if options.params[:diff]
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(Retest::Command.for_options(options))
19
+ repository: repository,
20
+ command: command,
21
+ runner: runner
17
22
  )
18
23
 
19
24
  if options.params[:diff]
data/lib/retest.rb CHANGED
@@ -10,53 +10,8 @@ require "retest/version_control"
10
10
  require "retest/setup"
11
11
  require "retest/command"
12
12
  require "retest/file_system"
13
+ require "retest/program"
13
14
 
14
15
  module Retest
15
16
  class Error < StandardError; end
16
-
17
- class Program
18
- attr_accessor :runner, :repository
19
- def initialize(runner: nil, repository: nil)
20
- @runner = runner
21
- @repository = repository
22
- end
23
-
24
- def start
25
- puts "Launching Retest..."
26
- build.start
27
- puts "Ready to refactor! You can make file changes now"
28
- end
29
-
30
- def diff(branch)
31
- raise "Git not installed" unless VersionControl::Git.installed?
32
- test_files = repository.find_tests VersionControl::Git.diff_files(branch)
33
-
34
- puts "Tests found:"
35
- test_files.each { |test_file| puts " - #{test_file}" }
36
-
37
- puts "Running tests..."
38
- test_files.each { |test_file| runner.run test_file }
39
- end
40
-
41
- private
42
-
43
- def build
44
- Listen.to('.', only: /\.rb$/, relative: true) do |modified, added, removed|
45
- begin
46
- repository.add(added)
47
- repository.remove(removed)
48
- runner.remove(removed)
49
- system('clear 2>/dev/null') || system('cls 2>/dev/null')
50
-
51
- runner.run test_file_to_run(modified + added)
52
- rescue => e
53
- puts "Something went wrong: #{e.message}"
54
- end
55
- end
56
- end
57
-
58
- def test_file_to_run(changed_files)
59
- repository.find_test changed_files.first if runner.matching?
60
- end
61
- end
62
17
  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
@@ -1,15 +1,22 @@
1
1
  module Retest
2
2
  class Command
3
- Rails = Struct.new(:all, :file_system) do
4
- def self.command(all:, file_system: FileSystem)
5
- new(all, file_system).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
@@ -19,4 +26,4 @@ module Retest
19
26
  end
20
27
  end
21
28
  end
22
- end
29
+ end
@@ -1,15 +1,22 @@
1
1
  module Retest
2
2
  class Command
3
- Rake = Struct.new(:all, :file_system) do
4
- def self.command(all:, file_system: FileSystem)
5
- new(all, file_system).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
@@ -19,4 +26,4 @@ module Retest
19
26
  end
20
27
  end
21
28
  end
22
- end
29
+ end
@@ -1,15 +1,22 @@
1
1
  module Retest
2
2
  class Command
3
- Rspec = Struct.new(:all, :file_system) do
4
- def self.command(all:, file_system: FileSystem)
5
- new(all, file_system).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
@@ -1,9 +1,19 @@
1
1
  module Retest
2
2
  class Command
3
- module Ruby
4
- module_function
3
+ class Ruby
4
+ attr_reader :all, :file_system
5
5
 
6
- def command(all: false, file_system: FileSystem)
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
7
17
  if file_system.exist? 'Gemfile.lock'
8
18
  'bundle exec ruby <test>'
9
19
  else
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Retest
2
- VERSION = "1.2.0"
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.2.0
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-05-18 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
@@ -88,6 +88,7 @@ files:
88
88
  - lib/retest/command/ruby.rb
89
89
  - lib/retest/file_system.rb
90
90
  - lib/retest/options.rb
91
+ - lib/retest/program.rb
91
92
  - lib/retest/repository.rb
92
93
  - lib/retest/runner.rb
93
94
  - lib/retest/setup.rb
@@ -114,9 +115,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
115
  version: 2.3.0
115
116
  required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  requirements:
117
- - - ">="
118
+ - - ">"
118
119
  - !ruby/object:Gem::Version
119
- version: '0'
120
+ version: 1.3.1
120
121
  requirements: []
121
122
  rubygems_version: 3.0.3
122
123
  signing_key: