retest 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 222a1b9ba81351e756d91fc459876b8387783cdfbd67ae9013799c366bc5d422
4
+ data.tar.gz: a02c050894fd050defce526352325dfeeb35ef10086f907a92d6b6325a7e9e1b
5
+ SHA512:
6
+ metadata.gz: a585e4efa6c818f209d14859e8a89ad69ed2f8fcb90dc008d4ef205ad8f608ff32a7f494e47127e31252792c183e88d284034887869da2e940dd5fa2c0ecc3ec
7
+ data.tar.gz: 53c849bb80a0943bd38ce15e4cb6f1dee1e88df02336f8d7c9321cbaf2e5777ed0fd1985e6f1e95b1d4b307fecb1a839826b35598b255db827988e77656d950f
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in retest.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ retest (0.1.1)
5
+ listen (~> 3.2)
6
+ string-similarity (~> 2.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ffi (1.13.1)
12
+ listen (3.2.1)
13
+ rb-fsevent (~> 0.10, >= 0.10.3)
14
+ rb-inotify (~> 0.9, >= 0.9.10)
15
+ minitest (5.14.1)
16
+ rake (12.3.3)
17
+ rb-fsevent (0.10.4)
18
+ rb-inotify (0.10.1)
19
+ ffi (~> 1.0)
20
+ string-similarity (2.1.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ minitest (~> 5.0)
27
+ rake (~> 12.0)
28
+ retest!
29
+
30
+ BUNDLED WITH
31
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Alexandre Barret
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Retest
2
+
3
+ Retest is a small gem to help refactor code by watching a file change and running its matching spec. You don't need a configuration file to start refactoring. 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.
4
+
5
+ This is my take on solving tests rerun. It is meant to be simple and follow testing conventions encountered in Ruby projects. It is probably unstable and unflexible but covers my need. Give it a go you can uninstall it easily. 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)
6
+
7
+ This is a work in progress and the end goal is to have an executable that works as follow:
8
+
9
+ * Works with RSpec, MiniTest, Rake commands & bash commands (not aliases).
10
+ * Works when run in a Docker container.
11
+ * When a test file is not found run the last command again.
12
+ * When multiple test files are found, ask which file to run and save the answer.
13
+
14
+ ## Installation
15
+
16
+ Install it on your machine with:
17
+
18
+ $ gem install retest
19
+
20
+ ## Usage
21
+
22
+ Launch `retest` in your terminal after accessing your ruby project folder.
23
+
24
+ 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.
25
+
26
+ ```bash
27
+ # Let retest find the test file and replace the placeholder with the path of the test file
28
+ $ retest 'bundle exec rake test <test>'
29
+ $ retest 'rails test <test>'
30
+ $ retest 'rspec <test>'
31
+ $ retest 'ruby <test>'
32
+
33
+ # Run the same command after a file change like all the spec files
34
+ $ retest 'bundle exec rake test'
35
+ $ retest 'rails test'
36
+ $ retest 'rspec'
37
+
38
+ # Hardcode a test file to run indepdendently from the file you change
39
+ $ retest 'ruby all_tests.rb'
40
+ ```
41
+
42
+ **Disclaimer:**
43
+ * If an error comes in try using `bundle exec` like so: `$ retest 'bundle exec rake test <test>'`
44
+ * Aliases saved on ~/.bashrc or ~/.zshrc cannot be run that way with the `retest` command
45
+
46
+ ## Roadmap
47
+
48
+ - [x] MVP
49
+ - [ ] Run withing Docker.
50
+ - [ ] When a test file is not found run the last command again.
51
+ - [ ] When multiple test files are found, ask which file to run and save the answer.
52
+ - [ ] Aliases from oh-my-zsh and bash profiles?
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/alexb52/retest.
63
+
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "retest"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/retest ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'retest'
4
+ require 'open3'
5
+ require 'listen'
6
+
7
+ include Retest
8
+
9
+ puts "Launching Retest..."
10
+ command_to_run = ARGV.join(' ')
11
+
12
+ listener = Listen.to('.', relative: true) do |modified, added, removed|
13
+ puts "modified absolute path: #{modified}"
14
+ system("clear") || system("cls")
15
+
16
+ if test_path = find_test(modified.first.strip, files: Dir.glob('**/**'))
17
+ puts ""
18
+ puts "Running: #{test_path}"
19
+ puts ""
20
+ system command_to_run.gsub('<test>', test_path)
21
+ else
22
+ puts "Could not find matching test to run"
23
+ end
24
+ end
25
+ listener.start # not blocking
26
+ sleep
@@ -0,0 +1,3 @@
1
+ module Retest
2
+ VERSION = "0.1.1"
3
+ end
data/lib/retest.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "retest/version"
2
+ require 'string/similarity'
3
+
4
+ module Retest
5
+ class Error < StandardError; end
6
+
7
+ def find_test(path, files: nil)
8
+ files
9
+ .select { |file| regex(path) =~ file }
10
+ .max_by { |file| String::Similarity.cosine(path, file) }
11
+ end
12
+
13
+ private
14
+
15
+ def regex(path)
16
+ extname = File.extname(path)
17
+ basename = File.basename(path, extname)
18
+ Regexp.new(".*#{basename}_(?:spec|test)#{extname}")
19
+ end
20
+ end
data/retest.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/retest/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "retest"
5
+ spec.version = Retest::VERSION
6
+ spec.authors = ["Alexandre Barret"]
7
+ spec.email = ["alex@abletech.nz"]
8
+
9
+ spec.summary = "A simple command line too to watch file change and run its matching spec."
10
+ spec.homepage = "https://github.com/AlexB52/retest"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/AlexB52/retest"
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ spec.add_runtime_dependency "string-similarity", ["~> 2.1"]
29
+ spec.add_runtime_dependency "listen", ["~> 3.2"]
30
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: retest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre Barret
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: string-similarity
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: listen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ description:
42
+ email:
43
+ - alex@abletech.nz
44
+ executables:
45
+ - retest
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - exe/retest
59
+ - lib/retest.rb
60
+ - lib/retest/version.rb
61
+ - retest.gemspec
62
+ homepage: https://github.com/AlexB52/retest
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ homepage_uri: https://github.com/AlexB52/retest
67
+ source_code_uri: https://github.com/AlexB52/retest
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.3.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.1.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: A simple command line too to watch file change and run its matching spec.
87
+ test_files: []