Class: TestRunner
- Inherits:
-
Object
- Object
- TestRunner
- Defined in:
- lib/test_runner.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #check_script(name) ⇒ Object
-
#initialize(project_path) ⇒ TestRunner
constructor
A new instance of TestRunner.
- #invoke ⇒ Object
- #run_script(name) ⇒ Object
- #script_path(name) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(project_path) ⇒ TestRunner
Returns a new instance of TestRunner.
8 9 10 |
# File 'lib/test_runner.rb', line 8 def initialize(project_path) @project_path = project_path end |
Instance Method Details
#check_script(name) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/test_runner.rb', line 23 def check_script(name) script_path = script_path(name) Dir.chdir(@project_path) do if File.exists?(script_path) if !File.stat(script_path).executable? abort "#{@project_path}/.ci/#{name} script not executable" elsif File.open(script_path).read.empty? abort "#{@project_path}/.ci/#{name} script empty" end else abort "#{@project_path}/.ci/#{name} script missing" end end end |
#invoke ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/test_runner.rb', line 54 def invoke if valid? project_name = @project_path.split(File::SEPARATOR).last results = Result.new(project_name) results.version_output = run_script('version').join results.update_output, results.update_error = run_script('update') if results.update_error.empty? results.test_output, results.test_error = run_script('test') end results. = Time.now return results end end |
#run_script(name) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/test_runner.rb', line 39 def run_script(name) output = '' error = '' Dir.chdir(@project_path) do Open3.popen3(script_path(name)) do |stdin, stdout, stderr| stdin.close # Close to prevent hanging if the script wants input output = stdout.read error = stderr.read end end return output.chomp, error.chomp end |
#script_path(name) ⇒ Object
19 20 21 |
# File 'lib/test_runner.rb', line 19 def script_path(name) script_path = File.join('.ci', name) end |
#valid? ⇒ Boolean
12 13 14 15 16 17 |
# File 'lib/test_runner.rb', line 12 def valid? check_script('update') check_script('version') check_script('test') return true end |