lib/quality/quality_checker.rb in quality-1.3.1 vs lib/quality/quality_checker.rb in quality-2.0.0

- old
+ new

@@ -1,23 +1,26 @@ require_relative 'command_output_processor' -require 'English' +require_relative 'process_runner' module Quality # Runs a quality-checking, command, checks it agaist the existing # number of violations for that command, and decreases that number # if possible, or outputs data if the number of violations increased. class QualityChecker def initialize(cmd, command_options, output_dir, dependencies = {}) - @popener = dependencies[:popener] || IO @count_file = dependencies[:count_file] || File @count_io = dependencies[:count_io] || IO @command_output_processor_class = dependencies[:command_output_processor_class] || Quality::CommandOutputProcessor @cmd = cmd @command_options = command_options + @count_dir = dependencies[:count_dir] || Dir + @count_dir.mkdir(output_dir) unless @count_file.exists?(output_dir) @filename = File.join(output_dir, "#{cmd}_high_water_mark") + @process_runner_class = + dependencies[:process_runner_class] || ProcessRunner end def execute(&count_violations_on_line) processor, exit_status = process_command(&count_violations_on_line) @violations = processor.violations @@ -33,15 +36,16 @@ exit_status = run_command(processor, &count_violations_on_line) [processor, exit_status] end def run_command(processor, &count_violations_on_line) - @popener.popen(full_cmd) do |file| + runner = @process_runner_class.new(full_cmd) + + runner.run do |file| processor.file = file @command_output = processor.process(&count_violations_on_line) end - $CHILD_STATUS.exitstatus end def check_exit_status(exit_status) return if @command_options[:gives_error_code_on_violations] @@ -100,10 +104,10 @@ end end def write_violations(new_violations) @count_file.open(@filename, 'w') do |file| - file.write(new_violations.to_s) + file.write(new_violations.to_s + "\n") end end end end