Class: Retest::Program
- Inherits:
-
Object
- Object
- Retest::Program
- Extended by:
- Forwardable
- Includes:
- ForcedSelection, Pausable
- Defined in:
- lib/retest/program.rb
Instance Attribute Summary collapse
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#runner ⇒ Object
Returns the value of attribute runner.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Attributes included from ForcedSelection
Instance Method Summary collapse
- #clear_terminal ⇒ Object
- #diff(branch) ⇒ Object
- #force_batch(multiline_input) ⇒ Object
-
#initialize(runner: nil, repository: nil, stdout: $stdout) ⇒ Program
constructor
A new instance of Program.
- #run(file, force_run: false) ⇒ Object
- #run_all ⇒ Object
Methods included from ForcedSelection
#force_selection, #forced_selection?, #initialize_forced_selection, #reset_selection
Methods included from Pausable
#initialize_pause, #pause, #paused?, #resume, #running_state
Constructor Details
#initialize(runner: nil, repository: nil, stdout: $stdout) ⇒ Program
Returns a new instance of Program.
15 16 17 18 19 20 21 |
# File 'lib/retest/program.rb', line 15 def initialize(runner: nil, repository: nil, stdout: $stdout) @runner = runner @repository = repository @stdout = stdout initialize_pause(false) initialize_forced_selection([]) end |
Instance Attribute Details
#repository ⇒ Object
Returns the value of attribute repository.
10 11 12 |
# File 'lib/retest/program.rb', line 10 def repository @repository end |
#runner ⇒ Object
Returns the value of attribute runner.
10 11 12 |
# File 'lib/retest/program.rb', line 10 def runner @runner end |
#stdout ⇒ Object
Returns the value of attribute stdout.
10 11 12 |
# File 'lib/retest/program.rb', line 10 def stdout @stdout end |
Instance Method Details
#clear_terminal ⇒ Object
72 73 74 |
# File 'lib/retest/program.rb', line 72 def clear_terminal system('clear 2>/dev/null') || system('cls 2>/dev/null') end |
#diff(branch) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/retest/program.rb', line 46 def diff(branch) raise "Git not installed" unless VersionControl::Git.installed? test_files = repository.find_tests VersionControl::Git.diff_files(branch) runner.run(test_files: test_files) end |
#force_batch(multiline_input) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/retest/program.rb', line 57 def force_batch(multiline_input) failures, successes = repository .search_tests(multiline_input.split(/\s+/)) .partition { |k,v| v.nil? } Output.force_batch_failures(failures.map(&:first), out: @stdout) if (successes = successes.to_h).empty? @stdout.puts "No test files found" else force_selection(successes.values.uniq.compact.sort) run(nil, force_run: true) end end |
#run(file, force_run: false) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/retest/program.rb', line 23 def run(file, force_run: false) if paused? && !force_run @stdout.puts "Main program paused. Please resume program first." return end if forced_selection? @stdout.puts <<~HINT Forced selection enabled. Reset to default settings by typing 'r' in the interactive console. HINT runner.run(test_files: selected_test_files) return end test_file = if runner.has_test? repository.find_test(file) end runner.run changed_files: [file], test_files: [test_file] end |
#run_all ⇒ Object
53 54 55 |
# File 'lib/retest/program.rb', line 53 def run_all runner.run_all end |