Class: NoradSpecRunner::Task
- Inherits:
-
Object
- Object
- NoradSpecRunner::Task
- Defined in:
- lib/norad_spec_runner/task.rb
Overview
Class to run RSpec tests locally
Direct Known Subclasses
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
-
#results_file ⇒ Object
readonly
Returns the value of attribute results_file.
Instance Method Summary collapse
-
#initialize(tests, sub_tests, results_file) ⇒ Task
constructor
A new instance of Task.
- #run ⇒ Object
Constructor Details
#initialize(tests, sub_tests, results_file) ⇒ Task
9 10 11 12 13 14 15 16 17 |
# File 'lib/norad_spec_runner/task.rb', line 9 def initialize(tests, sub_tests, results_file) @obj = RSpec::Core::RakeTask.new do |_| true end @obj.pattern = tests @obj.rspec_opts = "-e #{sub_tests} --format json -o #{results_file}" @results_file = results_file end |
Instance Attribute Details
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
7 8 9 |
# File 'lib/norad_spec_runner/task.rb', line 7 def obj @obj end |
#results_file ⇒ Object (readonly)
Returns the value of attribute results_file.
7 8 9 |
# File 'lib/norad_spec_runner/task.rb', line 7 def results_file @results_file end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/norad_spec_runner/task.rb', line 19 def run pstderr = STDERR.dup ftmp = Tempfile.open('eout') FileUtils.touch results_file # Capture STDERR for SSH related errors STDERR.reopen(ftmp) obj.run_task(true) rescue SystemExit => e ftmp.rewind err = ftmp.read ftmp.close p err # We land here even on successful run (SystemExit exception), only report error if stderr is not empty if not err.empty? write_error_to_results_file err end rescue Exception => e # Unknown exception! write_error_to_results_file e. ensure STDERR.reopen pstderr end |