retest 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f19bab47f8e8f925e239af074d1de4c8cf78cbcbd3376929d37ac5f71345cf4
4
- data.tar.gz: 683e67b4262a8265eb7b40e06f0199f98626f1df0071a0a006086accf18a4a05
3
+ metadata.gz: 7cec5f35b345630339ca56cfd0c1bc88be03596ca4d8369695f2e87f66e7c608
4
+ data.tar.gz: db0b1f966bb2ebe14183e17e93003c0d504881dc2a7d8fe2614f5c202b0fcf55
5
5
  SHA512:
6
- metadata.gz: 92fc110c595888136791a61b7327f79fd1f678b1b720da4cc5f1c4394b844e45a97c41bac2d3b7694747ecf7058fc207211e11260fa6f0261a53ed28d30ed2fd
7
- data.tar.gz: cb15584a8a240c75b8adc59d4ab57495a6aa3e5981cf8cb7a4590614e0b90ea9068ac211a063eba5dbb7e88ef0536489b2f67224e5e1c9e06752d029829fd857
6
+ metadata.gz: 2b191a17f73446b41fd5fdf9bc7495f4ea0535c05681e1d14e191cb62f6cadc83d09454ad501fc98ce503db6a169b628b6d205328ca4a236ddf56bbc75d78bff
7
+ data.tar.gz: e1089b2d8c64c380c2fd08935f8b0ded1dee4ccb2f265ff20c6f12eeea91942ef0e4c9a6a154b48a270a4c3281fa2e3edf981925f50c6767c98a2bbcbd1cd6f3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retest (1.0.0)
4
+ retest (1.1.0)
5
5
  listen (~> 3.2)
6
6
  string-similarity (~> 2.1)
7
7
  tty-option (~> 0.1)
data/bin/debug CHANGED
@@ -15,7 +15,7 @@ end
15
15
 
16
16
  program = Retest::Program.new(
17
17
  repository: Retest::Repository.new(files: Retest::VersionControl.files),
18
- runner: Retest::Runner.for(options.command)
18
+ runner: Retest::Runner.for(Retest::Command.for_options(options))
19
19
  )
20
20
 
21
21
  if options.params[:diff]
data/exe/retest CHANGED
@@ -13,7 +13,7 @@ end
13
13
 
14
14
  program = Retest::Program.new(
15
15
  repository: Retest::Repository.new(files: Retest::VersionControl.files),
16
- runner: Retest::Runner.for(options.command)
16
+ runner: Retest::Runner.for(Retest::Command.for_options(options))
17
17
  )
18
18
 
19
19
  if options.params[:diff]
data/lib/retest.rb CHANGED
@@ -8,6 +8,7 @@ require "retest/test_options"
8
8
  require "retest/options"
9
9
  require "retest/version_control"
10
10
  require "retest/setup"
11
+ require "retest/command"
11
12
 
12
13
  module Retest
13
14
  class Error < StandardError; 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.command(all: full_suite?)
63
+ end
64
+
65
+ def rails_command
66
+ Rails.command(all: full_suite?)
67
+ end
68
+
69
+ def rake_command
70
+ Rake.command(all: full_suite?)
71
+ end
72
+
73
+ def ruby_command
74
+ Ruby.command(all: full_suite?)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,22 @@
1
+ module Retest
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
6
+ end
7
+
8
+ def command
9
+ return "#{root_command} <test>" unless all
10
+ root_command
11
+ end
12
+
13
+ private
14
+
15
+ def root_command
16
+ return 'bin/rails test' if bin_file
17
+
18
+ 'bundle exec rails test'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Retest
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
6
+ end
7
+
8
+ def command
9
+ return "#{root_command} TEST=<test>" unless all
10
+ root_command
11
+ end
12
+
13
+ private
14
+
15
+ def root_command
16
+ return 'bin/rake test' if bin_file
17
+
18
+ 'bundle exec rake test'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Retest
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
6
+ end
7
+
8
+ def command
9
+ return "#{root_command} <test>" unless all
10
+ root_command
11
+ end
12
+
13
+ private
14
+
15
+ def root_command
16
+ return 'bin/rspec' if bin_file
17
+
18
+ 'bundle exec rspec'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module Retest
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
6
+ end
7
+
8
+ def command
9
+ 'bundle exec ruby <test>'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -111,22 +111,8 @@ module Retest
111
111
  new(args).command
112
112
  end
113
113
 
114
- def initialize(args = [], output_stream: STDOUT, setup: Setup)
114
+ def initialize(args = [])
115
115
  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
116
  end
131
117
 
132
118
  def args=(args)
@@ -138,45 +124,19 @@ module Retest
138
124
  params[:help]
139
125
  end
140
126
 
141
- private
142
-
143
127
  def full_suite?
144
128
  params[:all]
145
129
  end
146
130
 
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
131
+ def auto?
132
+ return true if no_options_passed?
133
+ params[:auto]
159
134
  end
160
135
 
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
136
+ private
177
137
 
178
- def ruby_command
179
- RUBY_COMMAND
138
+ def no_options_passed?
139
+ params.to_h.values.compact.uniq == [false]
180
140
  end
181
141
  end
182
142
  end
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"
2
+ VERSION = "1.1.0"
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
4
+ version: 1.1.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-19 00:00:00.000000000 Z
11
+ date: 2021-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-similarity
@@ -80,6 +80,11 @@ files:
80
80
  - bin/test/ruby-app
81
81
  - exe/retest
82
82
  - lib/retest.rb
83
+ - lib/retest/command.rb
84
+ - lib/retest/command/rails.rb
85
+ - lib/retest/command/rake.rb
86
+ - lib/retest/command/rspec.rb
87
+ - lib/retest/command/ruby.rb
83
88
  - lib/retest/options.rb
84
89
  - lib/retest/repository.rb
85
90
  - lib/retest/runner.rb