Commits

Brett Giles committed 01ebf4c

Fixed rspec - had to override SimpleCov at_exit handler.

Comments (0)

Files changed (4)

GUI/spec/monkey_kernel.rb

+# This file is available in: https://raw.github.com/japgolly/golly-utils
+
+module Kernel
+
+  # Alternate implementation of `at_exit` that preserves the exit status (unless you call `exit` yourself and an error
+  # is raised).
+  #
+  # The initial driver for this was that using `at_exit` to clean up global resources in RSpec tests, RSpec's exit
+  # status would be lost which means CI processes and such were unable to tell whether there were test failures.
+  #
+  # @return [Proc] Whatever `at_exit` returns.
+  def at_exit_preserving_exit_status(&block)
+    at_exit {
+      status= $!.is_a?(::SystemExit) ? $!.status : nil
+      block.()
+      exit status if status
+    }
+  end
+end

GUI/spec/spec_helper.rb

+require 'rbconfig'
+require 'java'
+
 require 'simplecov'
 SimpleCov.start
 
-require 'rbconfig'
-require 'java'
+# Override at_exit so that rspec actually terminates properly. 
+# puts did not seem to work consistently, so using err.println
+# result.format! sometimes prints a line as well, but not always.
+
+SimpleCov.at_exit do
+  SimpleCov.result.format!
+  java.lang.System.err.println "SimpleCov report generated, covered #{SimpleCov.result.covered_lines} lines of #{SimpleCov.result.total_lines} for a coverage of %#{SimpleCov.result.covered_percent}."
+  LqplController.instance.close
+  java.lang.System.exit(0)
+end
+
+
 $LOAD_PATH << File.expand_path(File.dirname(__FILE__))+"/../src"
 $CLASSPATH << File.expand_path(File.dirname(__FILE__))+"/../lib/java/jruby-complete.jar"
 $CLASSPATH << File.expand_path(File.dirname(__FILE__))+"/../devlib/java/jemmy-2.3.0.0.jar"
 $CLASSPATH << File.expand_path(File.dirname(__FILE__))+"/../../out/lqpl_gui"
 
 TEST_QP_PATH=File.expand_path(File.dirname(__FILE__))+"/../testdata/qplprograms/"
-require 'manifest'
 
+require 'manifest'
 

GUI/spec/view/descriptor_painter_spec.rb

   before(:each) do
    @sd = DescriptorPainterFactory.make_painter(AbstractDescriptorModel.make_instance "<ClassicalStack><cint>1</cint><cbool>True</cbool><cint>14</cint></ClassicalStack>")
   end
+  after (:all) do
+    @sd = nil
+  end
   it "should have the colour green" do
     @sd.my_colour.should == Color.green
   end

GUI/src/manifest.rb

 require "communications/lqpl_emulator_server_connection"
 require "utility/translate_line_ends"
 require "communications/compiler_server_connection"
-
+# 
 require "lqpl/lqpl_controller"
 require "panels/quantum_stack/quantum_stack_controller"
 require "panels/classical_stack/classical_stack_controller"