Class: Quest::RSpecRunner
- Inherits:
-
Object
- Object
- Quest::RSpecRunner
- Defined in:
- lib/quest/rspec_runner.rb
Instance Attribute Summary collapse
- #result ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(spec_file, spec_helper) ⇒ RSpecRunner
constructor
A new instance of RSpecRunner.
- #read_result(tmp_file) ⇒ Object
- #run_spec(spec_file, spec_helper, tmp_file) ⇒ Object
Constructor Details
#initialize(spec_file, spec_helper) ⇒ RSpecRunner
Returns a new instance of RSpecRunner.
7 8 9 10 11 12 13 14 |
# File 'lib/quest/rspec_runner.rb', line 7 def initialize(spec_file, spec_helper) @spec_file = spec_file @spec_helper = spec_helper Tempfile.open('quest-rspec-runner') do |tmp_file| @exit_code = run_spec(@spec_file, @spec_helper, tmp_file.path) @result = read_result(tmp_file.path) end end |
Instance Attribute Details
#result ⇒ Object (readonly)
5 6 7 |
# File 'lib/quest/rspec_runner.rb', line 5 def result @result end |
Instance Method Details
#read_result(tmp_file) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/quest/rspec_runner.rb', line 28 def read_result(tmp_file) begin JSON.parse(File.read(tmp_file)) rescue Errno::ENOENT => ex raise Failure, "Cannot open status file #{tmp_file}, (#{ex})" end end |
#run_spec(spec_file, spec_helper, tmp_file) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/quest/rspec_runner.rb', line 16 def run_spec(spec_file, spec_helper, tmp_file) home = ENV["HOME"] || '/tmp' command = "HOME=#{home} rspec #{spec_file} -r #{spec_helper} -f json -o #{tmp_file}" begin pid = Kernel.spawn(command) result = ::Process.wait2(pid) result.last.exitstatus rescue Errno::ENOENT => ex raise Failure, "Failed: #{command} (#{ex})" end end |