retest 0.7.0 → 0.8.0.pre

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: 0e161cc74886493796c719db9fae3f3d7b7dc31dfedc701539383e406d97336f
4
- data.tar.gz: dd6489fed59acfa0ccede581cae6a6e719a6c803a83214536e1aeed3173d6565
3
+ metadata.gz: 62ae62a28685056281a2e89c483ac3b16f7eaa11c486d764d5404ebcbbeb493a
4
+ data.tar.gz: 4f9b0a6be227cea4e858e0a36ebafadbc47385629c17fe568e194be99348edfa
5
5
  SHA512:
6
- metadata.gz: 9b4a4c521cc8f24d4f03e496aff11dee753e57e33e072e05dd24e01be82e300ad01a0d4f895f65115904395dde3833ee927932ba9b94a03f69fcbefe39e7c6ae
7
- data.tar.gz: a9d7acc12519dc1be69be17c36f504035a7a2505d248636090e008ae1555e1d69eca7f85c0ceb9fdc6b5b8868a1f79083ae06673f762315a7f88dffd22f00009
6
+ metadata.gz: be4c01100fdbb277eae592d26bfd1cddce64097a815418d042b746ea1b438f182e744718850fba1ee4cf79a62a6218bdb222d267b4a14f478ddb0dcc5e0f67a1
7
+ data.tar.gz: 9bd2dd59fead6115cd26df9f1b180b1cc432a568003bfff3469a016ceac7852ee561c5701c48778dfd430229d9e9122128740e0269c17e9bad54a05f213c8622
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retest (0.7.0)
4
+ retest (0.8.0.pre)
5
5
  listen (~> 3.2)
6
6
  string-similarity (~> 2.1)
7
7
  tty-option (~> 0.1)
@@ -62,7 +62,7 @@ GEM
62
62
  ffi (1.13.1)
63
63
  i18n (1.8.5)
64
64
  concurrent-ruby (~> 1.0)
65
- listen (3.3.3)
65
+ listen (3.4.1)
66
66
  rb-fsevent (~> 0.10, >= 0.10.3)
67
67
  rb-inotify (~> 0.9, >= 0.9.10)
68
68
  middleware (0.1.0)
data/README.md CHANGED
@@ -22,11 +22,11 @@ Install it on your machine with:
22
22
 
23
23
  Launch `retest` in your terminal after accessing your ruby project folder.
24
24
 
25
- 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.
26
26
 
27
27
  Learn more by running `retest -h`
28
28
 
29
- ```bash
29
+ ```
30
30
  Usage: retest [OPTIONS] [COMMAND]
31
31
 
32
32
  Watch a file change and run it matching spec.
data/lib/retest.rb CHANGED
@@ -5,30 +5,41 @@ require "retest/version"
5
5
  require "retest/runner"
6
6
  require "retest/repository"
7
7
  require "retest/test_options"
8
- require "retest/listen_options"
9
8
  require "retest/options"
9
+ require "retest/version_control"
10
10
 
11
11
  module Retest
12
12
  class Error < StandardError; end
13
13
 
14
- def self.start(command)
15
- puts "Launching Retest..."
14
+ class << self
15
+ def start(command)
16
+ puts "Launching Retest..."
16
17
 
17
- build(runner: Retest::Runner.for(command))
18
- .start
18
+ build(
19
+ runner: Runner.for(command),
20
+ repository: Repository.new(files: VersionControl.files)
21
+ ).start
19
22
 
20
- puts "Ready to refactor! You can make file changes now"
21
- end
23
+ puts "Ready to refactor! You can make file changes now"
24
+ end
22
25
 
23
- def self.build(runner:)
24
- Listen.to('.', ListenOptions.to_h) do |modified, added, removed|
25
- begin
26
- if modified.any?
27
- system('clear 2>/dev/null') || system('cls 2>/dev/null')
28
- runner.run(modified.first.strip)
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}"
29
42
  end
30
- rescue => e
31
- puts "Something went wrong: #{e.message}"
32
43
  end
33
44
  end
34
45
  end
@@ -2,9 +2,9 @@ module Retest
2
2
  class Repository
3
3
  attr_accessor :files, :cache, :input_stream, :output_stream
4
4
 
5
- def initialize(files: nil, cache: {}, input_stream: nil, output_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
9
  @output_stream = output_stream|| STDOUT
10
10
  end
@@ -13,6 +13,11 @@ module Retest
13
13
  cache[path] ||= select_from TestOptions.for(path, files: files)
14
14
  end
15
15
 
16
+ def add(new_files)
17
+ files.push(*new_files)
18
+ files.sort!
19
+ end
20
+
16
21
  private
17
22
 
18
23
  def select_from(tests)
@@ -25,10 +30,6 @@ module Retest
25
30
  end
26
31
  end
27
32
 
28
- def default_files
29
- @default_files ||= Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
30
- end
31
-
32
33
  def ask_question(tests)
33
34
  output_stream.puts <<~QUESTION
34
35
  We found few tests matching:
data/lib/retest/runner.rb CHANGED
@@ -9,21 +9,21 @@ module Retest
9
9
  end
10
10
 
11
11
  class VariableRunner
12
- attr_reader :command, :repository, :cached_test_file
12
+ attr_reader :command
13
13
 
14
- def initialize(command, repository: nil)
15
- @repository = repository || Repository.new
14
+ def initialize(command)
16
15
  @command = command
16
+ @cached_test_file = nil
17
17
  end
18
18
 
19
19
  def ==(obj)
20
20
  command == obj.command
21
21
  end
22
22
 
23
- def run(file_changed)
24
- if @cached_test_file = test_file(file_changed)
25
- puts "Test File Selected: #{cached_test_file}"
26
- system command.gsub('<test>', cached_test_file)
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
27
  else
28
28
  puts <<~ERROR
29
29
  404 - Test File Not Found
@@ -31,14 +31,10 @@ module Retest
31
31
  ERROR
32
32
  end
33
33
  end
34
-
35
- def test_file(file_changed)
36
- repository.find_test(file_changed) || cached_test_file
37
- end
38
34
  end
39
35
 
40
36
  HardcodedRunner = Struct.new(:command) do
41
- def run(_)
37
+ def run(_ = nil)
42
38
  system command
43
39
  end
44
40
  end
@@ -1,3 +1,3 @@
1
1
  module Retest
2
- VERSION = "0.7.0"
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
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.7.0
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-12-05 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
@@ -73,12 +73,12 @@ files:
73
73
  - bin/setup
74
74
  - exe/retest
75
75
  - lib/retest.rb
76
- - lib/retest/listen_options.rb
77
76
  - lib/retest/options.rb
78
77
  - lib/retest/repository.rb
79
78
  - lib/retest/runner.rb
80
79
  - lib/retest/test_options.rb
81
80
  - lib/retest/version.rb
81
+ - lib/retest/version_control.rb
82
82
  - retest.gemspec
83
83
  homepage: https://github.com/AlexB52/retest
84
84
  licenses:
@@ -97,9 +97,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
97
  version: 2.3.0
98
98
  required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ">="
100
+ - - ">"
101
101
  - !ruby/object:Gem::Version
102
- version: '0'
102
+ version: 1.3.1
103
103
  requirements: []
104
104
  rubygems_version: 3.0.3
105
105
  signing_key:
@@ -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>/dev/null"
30
- end
31
-
32
- def files
33
- `git ls-files`
34
- end
35
- end
36
- end