Skip to content

Commit

Permalink
Ask user which tests to run
Browse files Browse the repository at this point in the history
We add TTY::Prompt dependency for ease of user experience
  • Loading branch information
AlexB52 committed Nov 24, 2024
1 parent 995ab95 commit 2b58ccf
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PATH
observer (~> 0.1)
string-similarity (~> 2.1)
tty-option (~> 0.1)
tty-prompt (~> 0.1)

GEM
remote: https://rubygems.org/
Expand All @@ -17,12 +18,25 @@ GEM
rb-inotify (~> 0.9, >= 0.9.10)
minitest (5.15.0)
observer (0.1.2)
pastel (0.8.0)
tty-color (~> 0.5)
rake (13.0.6)
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
string-similarity (2.1.0)
tty-color (0.6.0)
tty-cursor (0.7.1)
tty-option (0.3.0)
tty-prompt (0.23.1)
pastel (~> 0.8)
tty-reader (~> 0.8)
tty-reader (0.9.0)
tty-cursor (~> 0.7)
tty-screen (~> 0.8)
wisper (~> 2.0)
tty-screen (0.8.2)
wisper (2.0.1)

PLATFORMS
ruby
Expand Down
8 changes: 8 additions & 0 deletions exe/retest
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def run_command(input:, program:, all_test_runner:)
puts "Program has been resumed\n"
when 'e', 'exit'
Process.kill("INT", 0)
when 'f', 'force'
require 'tty-prompt'
prompt = TTY::Prompt.new
program.run_selected prompt.multi_select(
"What test files do you want to run when saving a file?",
program.repository.test_files,
filter: true, min: 1
)
when ''
puts "Running last command\n"
program.run(nil, force_run: true)
Expand Down
5 changes: 5 additions & 0 deletions lib/retest/program.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def diff(branch)
runner.run_all_tests command.format_batch(*test_files)
end

def run_selected(test_files)
@stdout.puts "Running tests..."
runner.run_all_tests command.format_batch(*test_files)
end

def clear_terminal
return unless @clear_window

Expand Down
4 changes: 4 additions & 0 deletions lib/retest/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def find_tests(paths)
.sort
end

def test_files
files.select { |file| MatchingOptions::Path.new(file).test? }
end

def sync(added:, removed:)
add(added)
remove(removed)
Expand Down
1 change: 1 addition & 0 deletions retest.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "string-similarity", ["~> 2.1"]
spec.add_runtime_dependency "listen", ["~> 3.9"]
spec.add_runtime_dependency "tty-option", ["~> 0.1"]
spec.add_runtime_dependency "tty-prompt", ["~> 0.1"]
spec.add_runtime_dependency "observer", ["~> 0.1"]
end
53 changes: 53 additions & 0 deletions test/retest/repository_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,58 @@ def test_find_test_return_changed_file
assert_equal expected, @subject.find_test(file_changed)
end
end

class TestTestFiles < Minitest::Test
def setup
@subject = Repository.new
end

def test_returns_test_files_only
@subject.files = %w(
exe/retest
lib/retest.rb
lib/bottles.rb
lib/glasses.rb
lib/pints.rb
test/bottles_test.rb
test/glasses_test.rb
test/plates_test.rb
test/test_bottles_test.rb
test/test_glasses_test.rb
test/test_plates_test.rb
spec/bottles_spec.rb
spec/glasses_spec.rb
spec/plates_spec.rb
bottles_spec.rb
glasses_spec.rb
plates_spec.rb
bottles_test.rb
glasses_test.rb
plates_test.rb
program.rb
README.md
Gemfile
Gemfile.lock
)

assert_equal %w[
test/bottles_test.rb
test/glasses_test.rb
test/plates_test.rb
test/test_bottles_test.rb
test/test_glasses_test.rb
test/test_plates_test.rb
spec/bottles_spec.rb
spec/glasses_spec.rb
spec/plates_spec.rb
bottles_spec.rb
glasses_spec.rb
plates_spec.rb
bottles_test.rb
glasses_test.rb
plates_test.rb
], @subject.test_files
end
end
end
end

0 comments on commit 2b58ccf

Please sign in to comment.