retest 0.3.1 → 0.6.0.pre2

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: 56507242c2a092f077dbad839369ce929e59bdc8e0b6c0e29436a9893d12ca79
4
- data.tar.gz: 27eb3934eba008e23834ebec21bb42e680a143c349d33bb42c56d9b396bfed5a
3
+ metadata.gz: d55eddf3b57a090756f298ddef8ee56e5fb1fda5cf418eeef09e439ef17735a4
4
+ data.tar.gz: 0a24792e30b8954c09614460d0bb5a94ff1ae796da17fe66da1a499bfac7422c
5
5
  SHA512:
6
- metadata.gz: a0fc4a62969f81110fef3630ae11a0badc4436c93cbc0502922f4f342c2ff050e449b15c5b4f949f37a6a8e755702e1b5c03741c3dccb7870401d95a67c8702e
7
- data.tar.gz: 6042dcced199dd65e4b276f2eecc56c487f482216529079c35a84b5c133525c169dd7695d6f2d92d6c3074f6edeac50f7818a4f75ec1d1c179eca65727b5a581
6
+ metadata.gz: 335d9c2089ee743e55d3e2f16494cdb566314f072cfea689c03f2c08f7e8df08d9911eebce490fa621aaa654ebbcac61e9972d69eee24e9d660bb6093a17ef82
7
+ data.tar.gz: 433796d6539aca269288e5d7923207fbc96f3ab70fdea5ac8464f8f179973c5cf106786cb507c5bc4e6dabba242b201b18197911dc8899a11d3c038dd64f5cf1
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ main ]
13
+ pull_request:
14
+ branches: [ main ]
15
+
16
+ jobs:
17
+ test:
18
+ runs-on: ubuntu-latest
19
+ strategy:
20
+ matrix:
21
+ ruby:
22
+ - 2.5
23
+ - 2.6
24
+ - 2.7
25
+ name: Ruby ${{ matrix.ruby }} test
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+ - name: Set up Ruby
29
+ uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby }}
32
+ bundler-cache: true
33
+ - run: bundle install
34
+ - run: bundle exec rake
35
+ - run: CUCUMBER_PUBLISH_QUIET=true bundle exec cucumber
@@ -0,0 +1 @@
1
+ 2.6.6
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in retest.gemspec
4
4
  gemspec
5
5
 
6
+ gem "cucumber", "~> 5.1"
7
+ gem "aruba", "~> 1.0"
6
8
  gem "rake", "~> 12.0"
7
9
  gem "minitest", "~> 5.0"
8
10
  gem "byebug"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retest (0.3.1)
4
+ retest (0.6.0.pre2)
5
5
  listen (~> 3.2)
6
6
  string-similarity (~> 2.1)
7
7
 
@@ -61,7 +61,7 @@ GEM
61
61
  ffi (1.13.1)
62
62
  i18n (1.8.5)
63
63
  concurrent-ruby (~> 1.0)
64
- listen (3.2.1)
64
+ listen (3.3.1)
65
65
  rb-fsevent (~> 0.10, >= 0.10.3)
66
66
  rb-inotify (~> 0.9, >= 0.9.10)
67
67
  middleware (0.1.0)
@@ -93,9 +93,9 @@ PLATFORMS
93
93
  ruby
94
94
 
95
95
  DEPENDENCIES
96
- aruba
96
+ aruba (~> 1.0)
97
97
  byebug
98
- cucumber
98
+ cucumber (~> 5.1)
99
99
  minitest (~> 5.0)
100
100
  rake (~> 12.0)
101
101
  retest!
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # Retest
2
2
 
3
- Retest is a small command line tool to help refactor code by watching a file change and running its matching spec. You don't need a configuration file to start refactoring.
3
+ 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)
4
4
 
5
5
  ## Why?
6
6
  It is advised to be one `cmd + z` away from green tests when refactoring. This means running tests after every line change. Let Retest rerun your tests after every file change you make.
7
7
 
8
- Retest gem is meant to be simple and follow testing conventions encountered in Ruby projects. It is probably unstable and unflexible. Give it a go you can uninstall it easily. If you think the matching pattern could be improved please raise an issue.
8
+ Retest gem is meant to be simple and follow testing conventions encountered in Ruby projects. Give it a go you can uninstall it easily. If you think the matching pattern could be improved please raise an issue.
9
9
 
10
- For stable, yet more and fully fledged solutions, some cli tools already exists: [autotest](https://github.com/grosser/autotest), [guard](https://github.com/guard/guard), [zentest](https://github.com/seattlerb/zentest)
10
+ For fully fledged solutions, some cli tools already exists: [autotest](https://github.com/grosser/autotest), [guard](https://github.com/guard/guard), [zentest](https://github.com/seattlerb/zentest)
11
+
12
+ ![demo](https://alexbarret.com/images/external/retest-demo-26bcad04.gif)
11
13
 
12
14
  ## Installation
13
15
 
@@ -19,7 +21,7 @@ Install it on your machine with:
19
21
 
20
22
  Launch `retest` in your terminal after accessing your ruby project folder.
21
23
 
22
- Pass the test command surrounded with 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.
24
+ 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.
23
25
 
24
26
  ```bash
25
27
  # Let retest find the test file and replace the placeholder with the path of the test file
@@ -35,14 +37,16 @@ $ retest 'rails test'
35
37
  $ retest 'rspec'
36
38
  $ retest 'docker-compose exec web bundle exec rails test'
37
39
 
38
- # Hardcode a test file to run indepdendently from the file you change
40
+ # Hardcode a test file to run independently from the file you change
39
41
  $ retest 'ruby all_tests.rb'
40
42
  ```
41
43
 
42
44
  The gem works as follows:
43
45
 
44
- * When multiple matching test files are found, the tool asks you to confirm the file and save the answer.
45
- * When a test file is not found run the last command again. If no command was run before nothing gets run.
46
+ * When a file is changed, retest will run its matching file test.
47
+ * When a test file is changed, retest will run the file test.
48
+ * When multiple matching test files are found, retest asks you to confirm the file and save the answer.
49
+ * When a test file is not found, retest runs the last run command or throw a 404.
46
50
  * Works with RSpec, MiniTest, Rake commands & bash commands (not aliases).
47
51
  * Works when installed and run in a Docker container.
48
52
 
@@ -59,12 +63,24 @@ $ retest 'bundle exec rails test <test>'
59
63
  * If an error comes in try using `bundle exec` like so: `$ retest 'bundle exec rake test <test>'`
60
64
  * Aliases saved on ~/.bashrc or ~/.zshrc cannot be run that way with the `retest` command
61
65
 
66
+ ## Ruby Support
67
+
68
+ Retest supports ruby 2.5 and above.
69
+
62
70
  ## Roadmap
63
71
 
64
72
  - [x] MVP
65
- - [x] When multiple test files are found, ask which file to run and save the answer.
73
+ - [x] When multiple test files are found, ask which file to run and save the answer.
66
74
  - [x] When a test file is not found run the last command again.
67
- - [x] Run withing Docker.
75
+ - [x] Run within Docker.
76
+ - [ ] Handle main Ruby setups
77
+ - [x] Bundler Gem
78
+ - [x] Rails
79
+ - [x] Ad-hoc scripts
80
+ - [x] Hanami
81
+ - [ ] Sinatra
82
+ - [ ] Cuba? Padrino?
83
+ - [ ] Handle other languages: Elixir, Node, Python, PHP
68
84
  - [ ] Aliases from oh-my-zsh and bash profiles?
69
85
 
70
86
  ## Development
@@ -80,4 +96,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/alexb5
80
96
 
81
97
  ## License
82
98
 
83
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
99
+ The gem is available as open-source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/exe/retest CHANGED
@@ -1,21 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'retest'
4
- require 'listen'
5
4
 
6
- puts "Launching Retest..."
5
+ $stdout.sync = true
7
6
 
8
- command = Retest::Command.for(ARGV.join)
7
+ puts "Launching Retest..."
9
8
 
10
- listener = Listen.to('.', ignore: /node_modules|tmp/, relative: true) do |modified, added, removed|
11
- if modified.any?
12
- system("clear") || system("cls")
13
- command.run(modified.first.strip)
14
- end
15
- rescue => e
16
- puts "Something went wrong: #{e.message}"
17
- end
9
+ Retest
10
+ .build(command: Retest::Command.for(ARGV.join))
11
+ .start # not blocking
18
12
 
19
- listener.start # not blocking
20
13
  puts "Ready to refactor! You can make file changes now"
14
+
21
15
  sleep
@@ -1,8 +1,25 @@
1
+ require 'listen'
2
+ require 'string/similarity'
3
+
1
4
  require "retest/version"
2
5
  require "retest/command"
3
6
  require "retest/repository"
4
- require 'string/similarity'
7
+ require "retest/test_options"
8
+ require "retest/listen_options"
5
9
 
6
10
  module Retest
7
11
  class Error < StandardError; end
12
+
13
+ def self.build(command:)
14
+ Listen.to('.', ListenOptions.to_h) do |modified, added, removed|
15
+ begin
16
+ if modified.any?
17
+ `clear 2>&1` || `cls 2>&1`
18
+ command.run(modified.first.strip)
19
+ end
20
+ rescue => e
21
+ puts "Something went wrong: #{e.message}"
22
+ end
23
+ end
24
+ end
8
25
  end
@@ -25,7 +25,10 @@ module Retest
25
25
  puts "Test File Selected: #{cached_test_file}"
26
26
  system command.gsub('<test>', cached_test_file)
27
27
  else
28
- puts 'Could not find a file test matching'
28
+ puts <<~ERROR
29
+ 404 - Test File Not Found
30
+ Retest could not find a matching test file to run.
31
+ ERROR
29
32
  end
30
33
  end
31
34
 
@@ -0,0 +1,36 @@
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>&1"
30
+ end
31
+
32
+ def files
33
+ `git ls-files`
34
+ end
35
+ end
36
+ end
@@ -10,7 +10,7 @@ module Retest
10
10
  end
11
11
 
12
12
  def find_test(path)
13
- cache[path] ||= select_from test_options(path)
13
+ cache[path] ||= select_from TestOptions.for(path, files: files)
14
14
  end
15
15
 
16
16
  private
@@ -25,23 +25,10 @@ module Retest
25
25
  end
26
26
  end
27
27
 
28
- def test_options(path)
29
- files.select { |file| regex(path) =~ file }
30
- .sort_by { |file| String::Similarity.levenshtein(path, file) }
31
- .last(5)
32
- .reverse
33
- end
34
-
35
28
  def default_files
36
29
  @default_files ||= Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
37
30
  end
38
31
 
39
- def regex(path)
40
- extname = File.extname(path)
41
- basename = File.basename(path, extname)
42
- Regexp.new(".*#{basename}_(?:spec|test)#{extname}")
43
- end
44
-
45
32
  def ask_question(tests)
46
33
  output_stream.puts <<~QUESTION
47
34
  We found few tests matching:
@@ -0,0 +1,87 @@
1
+ require 'forwardable'
2
+
3
+ module Retest
4
+ class TestOptions
5
+ def self.for(path, files: [])
6
+ new(path, files: files).filtered_results
7
+ end
8
+
9
+ attr_reader :path, :files
10
+
11
+ def initialize(path, files: [])
12
+ @path = Path.new(path)
13
+ @files = files
14
+ end
15
+
16
+ def filtered_results
17
+ if path.test?
18
+ [path]
19
+ elsif namespace_screens.any?
20
+ namespace_screens
21
+ else
22
+ possible_tests
23
+ end.map(&:to_s)
24
+ end
25
+
26
+ private
27
+
28
+ def possible_tests
29
+ @possible_tests ||= filter_by_string_similarities(path, files)
30
+ .last(5)
31
+ .reverse
32
+ end
33
+
34
+ def filter_by_string_similarities(path, files)
35
+ files.select { |file| path.possible_test?(file) }
36
+ .sort_by { |file| [path.similarity_score(file), file] }
37
+ end
38
+
39
+ def namespace_screens
40
+ @namespace_screens ||= path
41
+ .reversed_dirnames
42
+ .each_with_index
43
+ .with_object(possible_tests.map { |file| Path.new(file) }) do |(reference, index), result|
44
+ unless [1, 0].include? result.count
45
+ result.keep_if { |path| path.reversed_dirnames[index] == reference }
46
+ end
47
+ end
48
+ end
49
+
50
+ class Path
51
+ extend Forwardable
52
+
53
+ def_delegators :pathname, :to_s, :basename, :extname, :dirname
54
+
55
+ attr_reader :pathname
56
+ def initialize(path)
57
+ @pathname = Pathname(path)
58
+ end
59
+
60
+ def reversed_dirnames
61
+ @reversed_dirnames ||= dirname.each_filename.to_a.reverse
62
+ end
63
+
64
+ def test?
65
+ test_regex =~ to_s
66
+ end
67
+
68
+ def possible_test?(file)
69
+ possible_test_regex =~ file
70
+ end
71
+
72
+ def similarity_score(file)
73
+ String::Similarity.levenshtein(to_s, file)
74
+ end
75
+
76
+ private
77
+
78
+ def test_regex
79
+ Regexp.new(".*(?:spec|test)#{extname}")
80
+ end
81
+
82
+ def possible_test_regex
83
+ Regexp.new(".*#{basename(extname)}_(?:spec|test)#{extname}")
84
+ end
85
+ end
86
+ end
87
+ end
@@ -1,3 +1,3 @@
1
1
  module Retest
2
- VERSION = "0.3.1"
2
+ VERSION = "0.6.0.pre2"
3
3
  end
@@ -27,6 +27,4 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
  spec.add_runtime_dependency "string-similarity", ["~> 2.1"]
29
29
  spec.add_runtime_dependency "listen", ["~> 3.2"]
30
- spec.add_development_dependency "cucumber"
31
- spec.add_development_dependency "aruba"
32
30
  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.3.1
4
+ version: 0.6.0.pre2
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: 2020-09-06 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-similarity
@@ -38,35 +38,7 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.2'
41
- - !ruby/object:Gem::Dependency
42
- name: cucumber
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: aruba
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- description:
41
+ description:
70
42
  email:
71
43
  - alex@abletech.nz
72
44
  executables:
@@ -74,8 +46,9 @@ executables:
74
46
  extensions: []
75
47
  extra_rdoc_files: []
76
48
  files:
49
+ - ".github/workflows/ci.yml"
77
50
  - ".gitignore"
78
- - ".travis.yml"
51
+ - ".ruby-version"
79
52
  - Gemfile
80
53
  - Gemfile.lock
81
54
  - LICENSE.txt
@@ -87,7 +60,9 @@ files:
87
60
  - exe/retest
88
61
  - lib/retest.rb
89
62
  - lib/retest/command.rb
63
+ - lib/retest/listen_options.rb
90
64
  - lib/retest/repository.rb
65
+ - lib/retest/test_options.rb
91
66
  - lib/retest/version.rb
92
67
  - retest.gemspec
93
68
  homepage: https://github.com/AlexB52/retest
@@ -96,7 +71,7 @@ licenses:
96
71
  metadata:
97
72
  homepage_uri: https://github.com/AlexB52/retest
98
73
  source_code_uri: https://github.com/AlexB52/retest
99
- post_install_message:
74
+ post_install_message:
100
75
  rdoc_options: []
101
76
  require_paths:
102
77
  - lib
@@ -107,12 +82,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
82
  version: 2.3.0
108
83
  required_rubygems_version: !ruby/object:Gem::Requirement
109
84
  requirements:
110
- - - ">="
85
+ - - ">"
111
86
  - !ruby/object:Gem::Version
112
- version: '0'
87
+ version: 1.3.1
113
88
  requirements: []
114
- rubygems_version: 3.1.2
115
- signing_key:
89
+ rubygems_version: 3.0.3
90
+ signing_key:
116
91
  specification_version: 4
117
92
  summary: A simple command line tool to watch file change and run its matching spec.
118
93
  test_files: []
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.0
6
- before_install: gem install bundler -v 2.1.4