retest 0.1.1 → 0.2.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: 222a1b9ba81351e756d91fc459876b8387783cdfbd67ae9013799c366bc5d422
4
- data.tar.gz: a02c050894fd050defce526352325dfeeb35ef10086f907a92d6b6325a7e9e1b
3
+ metadata.gz: 1ffe53d75f1b6c84ecdc5506c13a5798fba6e1c6801d816c98fec97912adf890
4
+ data.tar.gz: 3fd96dfa07a53ca007474b6dcbdfb7c1c542207c46b738736594b8a72e330d4f
5
5
  SHA512:
6
- metadata.gz: a585e4efa6c818f209d14859e8a89ad69ed2f8fcb90dc008d4ef205ad8f608ff32a7f494e47127e31252792c183e88d284034887869da2e940dd5fa2c0ecc3ec
7
- data.tar.gz: 53c849bb80a0943bd38ce15e4cb6f1dee1e88df02336f8d7c9321cbaf2e5777ed0fd1985e6f1e95b1d4b307fecb1a839826b35598b255db827988e77656d950f
6
+ metadata.gz: abe51dbcf57d44462117ad547d5e084973e6b3efbcf9e2a4450458e9f24b6e1f6a42e9bb1ee1ef20b48de8f42e4b3f12808765a8830432bddc94809c5705f1eb
7
+ data.tar.gz: f0f018c5553e34ca7bcf10411f73b9e6008936b877454a2a90f1bca8f6fcd30d0f5c9158ae2cef71484b3faca2db68b4b43b1d53063cdcd07eae1609bd802b0a
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .byebug_history
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /_yardoc/
data/Gemfile CHANGED
@@ -5,3 +5,4 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "minitest", "~> 5.0"
8
+ gem "byebug"
@@ -1,28 +1,101 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retest (0.1.1)
4
+ retest (0.2.0)
5
5
  listen (~> 3.2)
6
6
  string-similarity (~> 2.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ activesupport (6.0.3.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.2, >= 2.2.2)
17
+ aruba (1.0.3)
18
+ childprocess (>= 2.0, < 5.0)
19
+ contracts (~> 0.16.0)
20
+ cucumber (>= 2.4, < 6.0)
21
+ ffi (~> 1.9)
22
+ rspec-expectations (~> 3.4)
23
+ thor (~> 1.0)
24
+ builder (3.2.4)
25
+ byebug (11.1.3)
26
+ childprocess (4.0.0)
27
+ concurrent-ruby (1.1.7)
28
+ contracts (0.16.0)
29
+ cucumber (5.1.0)
30
+ builder (~> 3.2, >= 3.2.4)
31
+ cucumber-core (~> 8.0, >= 8.0.1)
32
+ cucumber-create-meta (~> 2.0, >= 2.0.1)
33
+ cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
34
+ cucumber-gherkin (~> 15.0, >= 15.0.2)
35
+ cucumber-html-formatter (~> 9.0, >= 9.0.0)
36
+ cucumber-messages (~> 13.0, >= 13.0.1)
37
+ cucumber-wire (~> 4.0, >= 4.0.1)
38
+ diff-lcs (~> 1.4, >= 1.4.4)
39
+ multi_test (~> 0.1, >= 0.1.2)
40
+ sys-uname (~> 1.2, >= 1.2.1)
41
+ cucumber-core (8.0.1)
42
+ cucumber-gherkin (~> 15.0, >= 15.0.2)
43
+ cucumber-messages (~> 13.0, >= 13.0.1)
44
+ cucumber-tag-expressions (~> 2.0, >= 2.0.4)
45
+ cucumber-create-meta (2.0.1)
46
+ cucumber-messages (~> 13.0, >= 13.0.1)
47
+ sys-uname (~> 1.2, >= 1.2.1)
48
+ cucumber-cucumber-expressions (10.3.0)
49
+ cucumber-gherkin (15.0.2)
50
+ cucumber-messages (~> 13.0, >= 13.0.1)
51
+ cucumber-html-formatter (9.0.0)
52
+ cucumber-messages (~> 13.0, >= 13.0.1)
53
+ cucumber-messages (13.0.1)
54
+ protobuf-cucumber (~> 3.10, >= 3.10.8)
55
+ cucumber-tag-expressions (2.0.4)
56
+ cucumber-wire (4.0.1)
57
+ cucumber-core (~> 8.0, >= 8.0.1)
58
+ cucumber-cucumber-expressions (~> 10.3, >= 10.3.0)
59
+ cucumber-messages (~> 13.0, >= 13.0.1)
60
+ diff-lcs (1.4.4)
11
61
  ffi (1.13.1)
62
+ i18n (1.8.5)
63
+ concurrent-ruby (~> 1.0)
12
64
  listen (3.2.1)
13
65
  rb-fsevent (~> 0.10, >= 0.10.3)
14
66
  rb-inotify (~> 0.9, >= 0.9.10)
67
+ middleware (0.1.0)
15
68
  minitest (5.14.1)
69
+ multi_test (0.1.2)
70
+ protobuf-cucumber (3.10.8)
71
+ activesupport (>= 3.2)
72
+ middleware
73
+ thor
74
+ thread_safe
16
75
  rake (12.3.3)
17
76
  rb-fsevent (0.10.4)
18
77
  rb-inotify (0.10.1)
19
78
  ffi (~> 1.0)
79
+ rspec-expectations (3.9.2)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.9.0)
82
+ rspec-support (3.9.3)
20
83
  string-similarity (2.1.0)
84
+ sys-uname (1.2.1)
85
+ ffi (>= 1.0.0)
86
+ thor (1.0.1)
87
+ thread_safe (0.3.6)
88
+ tzinfo (1.2.7)
89
+ thread_safe (~> 0.1)
90
+ zeitwerk (2.4.0)
21
91
 
22
92
  PLATFORMS
23
93
  ruby
24
94
 
25
95
  DEPENDENCIES
96
+ aruba
97
+ byebug
98
+ cucumber
26
99
  minitest (~> 5.0)
27
100
  rake (~> 12.0)
28
101
  retest!
data/README.md CHANGED
@@ -29,16 +29,27 @@ $ retest 'bundle exec rake test <test>'
29
29
  $ retest 'rails test <test>'
30
30
  $ retest 'rspec <test>'
31
31
  $ retest 'ruby <test>'
32
+ $ retest 'docker-compose exec web bundle exec rails test <test>'
32
33
 
33
34
  # Run the same command after a file change like all the spec files
34
35
  $ retest 'bundle exec rake test'
35
36
  $ retest 'rails test'
36
37
  $ retest 'rspec'
38
+ $ retest 'docker-compose exec web bundle exec rails test'
37
39
 
38
40
  # Hardcode a test file to run indepdendently from the file you change
39
41
  $ retest 'ruby all_tests.rb'
40
42
  ```
41
43
 
44
+ ### Docker
45
+
46
+ Installing & launching the gem in the Docker container seem to work
47
+ ```bash
48
+ $ docker-compose run web bash
49
+ $ gem install retests
50
+ $ retest 'bundle exec rails test <test>'
51
+ ```
52
+
42
53
  **Disclaimer:**
43
54
  * If an error comes in try using `bundle exec` like so: `$ retest 'bundle exec rake test <test>'`
44
55
  * Aliases saved on ~/.bashrc or ~/.zshrc cannot be run that way with the `retest` command
@@ -46,7 +57,7 @@ $ retest 'ruby all_tests.rb'
46
57
  ## Roadmap
47
58
 
48
59
  - [x] MVP
49
- - [ ] Run withing Docker.
60
+ - [x] Run withing Docker.
50
61
  - [ ] When a test file is not found run the last command again.
51
62
  - [ ] When multiple test files are found, ask which file to run and save the answer.
52
63
  - [ ] Aliases from oh-my-zsh and bash profiles?
data/exe/retest CHANGED
@@ -1,26 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'retest'
4
- require 'open3'
5
4
  require 'listen'
6
5
 
7
- include Retest
8
-
9
6
  puts "Launching Retest..."
10
- command_to_run = ARGV.join(' ')
11
7
 
12
- listener = Listen.to('.', relative: true) do |modified, added, removed|
13
- puts "modified absolute path: #{modified}"
14
- system("clear") || system("cls")
8
+ command = Retest::Command.for(ARGV.join)
15
9
 
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
10
+ listener = Listen.to('.', ignore: /node_modules|tmp/, relative: true) do |modified, added, removed|
11
+ system("clear") || system("cls")
12
+ command.run(modified.first.strip)
24
13
  end
14
+
25
15
  listener.start # not blocking
16
+ puts "Ready to refactor! You can make file changes now"
26
17
  sleep
@@ -1,4 +1,5 @@
1
1
  require "retest/version"
2
+ require "retest/command"
2
3
  require 'string/similarity'
3
4
 
4
5
  module Retest
@@ -0,0 +1,59 @@
1
+ module Retest
2
+ class Command
3
+ def self.for(test_command)
4
+ command_class = if test_command.include? '<test>'
5
+ VariableCommand
6
+ else
7
+ HardcodedCommand
8
+ end
9
+
10
+ command_class.new test_command
11
+ end
12
+
13
+ class VariableCommand
14
+ attr_reader :command, :files, :cache
15
+
16
+ def initialize(command, files: nil, cache: {})
17
+ @command = command
18
+ @cache = cache
19
+ @files = files || default_files
20
+ end
21
+
22
+ def ==(obj)
23
+ command == obj.command
24
+ end
25
+
26
+ def run(file_changed)
27
+ if find_test(file_changed)
28
+ system command.gsub('<test>', find_test(file_changed))
29
+ else
30
+ puts 'Could not find a file test matching'
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def find_test(path)
37
+ cache[path] ||= files
38
+ .select { |file| regex(path) =~ file }
39
+ .max_by { |file| String::Similarity.cosine(path, file) }
40
+ end
41
+
42
+ def regex(path)
43
+ extname = File.extname(path)
44
+ basename = File.basename(path, extname)
45
+ Regexp.new(".*#{basename}_(?:spec|test)#{extname}")
46
+ end
47
+
48
+ def default_files
49
+ @default_files ||= Dir.glob('**/*') - Dir.glob('{tmp,node_modules}/**/*')
50
+ end
51
+ end
52
+
53
+ HardcodedCommand = Struct.new(:command) do
54
+ def run(file_changed)
55
+ system command
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,3 +1,3 @@
1
1
  module Retest
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.authors = ["Alexandre Barret"]
7
7
  spec.email = ["alex@abletech.nz"]
8
8
 
9
- spec.summary = "A simple command line too to watch file change and run its matching spec."
9
+ spec.summary = "A simple command line tool to watch file change and run its matching spec."
10
10
  spec.homepage = "https://github.com/AlexB52/retest"
11
11
  spec.license = "MIT"
12
12
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
@@ -27,4 +27,6 @@ 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"
30
32
  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.1.1
4
+ version: 0.2.0
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-08-30 00:00:00.000000000 Z
11
+ date: 2020-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-similarity
@@ -38,7 +38,35 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.2'
41
- description:
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:
42
70
  email:
43
71
  - alex@abletech.nz
44
72
  executables:
@@ -57,6 +85,7 @@ files:
57
85
  - bin/setup
58
86
  - exe/retest
59
87
  - lib/retest.rb
88
+ - lib/retest/command.rb
60
89
  - lib/retest/version.rb
61
90
  - retest.gemspec
62
91
  homepage: https://github.com/AlexB52/retest
@@ -65,7 +94,7 @@ licenses:
65
94
  metadata:
66
95
  homepage_uri: https://github.com/AlexB52/retest
67
96
  source_code_uri: https://github.com/AlexB52/retest
68
- post_install_message:
97
+ post_install_message:
69
98
  rdoc_options: []
70
99
  require_paths:
71
100
  - lib
@@ -80,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
109
  - !ruby/object:Gem::Version
81
110
  version: '0'
82
111
  requirements: []
83
- rubygems_version: 3.1.2
84
- signing_key:
112
+ rubygems_version: 3.0.3
113
+ signing_key:
85
114
  specification_version: 4
86
- summary: A simple command line too to watch file change and run its matching spec.
115
+ summary: A simple command line tool to watch file change and run its matching spec.
87
116
  test_files: []