lib/retest/repository.rb in retest-1.10.0 vs lib/retest/repository.rb in retest-1.11.0
- old
+ new
@@ -1,22 +1,21 @@
module Retest
class Repository
- attr_accessor :files, :cache, :stdin, :stdout
+ attr_accessor :files, :cache, :prompt
- def initialize(files: [], cache: {}, stdin: $stdin, stdout: $stdout)
+ def initialize(files: [], cache: {}, prompt: nil)
@cache = cache
@files = files
- @stdin = stdin
- @stdout = stdout
+ @prompt = prompt || Prompt.new
end
def find_test(path)
return unless path
return if path.empty?
@path = path
- cache[@path] ||= select_from TestOptions.for(@path, files: files)
+ cache[@path] ||= select_from MatchingOptions.for(@path, files: files)
end
def find_tests(paths)
paths
.select { |path| Regexp.new("\.rb$") =~ path }
@@ -53,31 +52,10 @@
def select_from(tests)
case tests.count
when 0, 1
tests.first
else
- ask_question tests
- tests[get_input]
+ prompt.ask_which_test_to_use(@path, tests)
end
- end
-
- def ask_question(tests)
- stdout.puts(<<~QUESTION)
- We found few tests matching: #{@path}
- #{list_options(tests)}
-
- Which file do you want to use?
- Enter the file number now:
- QUESTION
- end
-
- def list_options(tests)
- tests.map.with_index do |file, index|
- "[#{index}] - #{file}"
- end.join("\n")
- end
-
- def get_input
- stdin.gets.chomp.to_i
end
end
end
\ No newline at end of file