lib/netzke/testing/helpers.rb in netzke-testing-0.11.2 vs lib/netzke/testing/helpers.rb in netzke-testing-0.12.0.beta

- old
+ new

@@ -6,40 +6,51 @@ url << "&locale=#{locale}" if locale visit url # Wait while the test is running - wait_for_javascript(options[:stop_on_error]) + wait_for_javascript - assert_mocha_results(options[:stop_on_error]) + assert_mocha_results end - def wait_for_javascript(stop_on_error = false) + def wait_for_javascript start = Time.now loop do page.execute_script("return Netzke.mochaDone;") ? break : sleep(0.1) # no specs are supposed to run longer than 100 seconds raise "Timeout running JavaScript specs for #{@component}" if Time.now > start + 100.seconds end rescue Selenium::WebDriver::Error::JavascriptError => e - sleep 1.year if stop_on_error + # give some time for visual examination of the problem + # sleep 5 + raise e end - def assert_mocha_results(stop_on_error = false) + def assert_mocha_results result = page.execute_script(<<-JS) var runner = Netzke.mochaRunner; + var errors = []; + Ext.Array.each(runner.suite.suites[0].tests, function(t) { if (t.err) errors.push([t.title, t.err.toString()]) }); return { test: runner.test.title, success: runner.stats.failures == 0 && runner.stats.tests !=0, - error: runner.test.err && runner.test.err.toString() + error: runner.test.err && runner.test.err.toString(), + errors: errors } JS if !result["success"] - sleep 1.year if stop_on_error - raise "Test failed: #{result["test"]}\n#{result["error"]}" + # give some time for visual examination of the problem + # sleep 500 + + errors = result["errors"].each_with_index.map do |(title, error), i| + "#{i+1}) #{title}\n#{error}\n\n" + end + + raise "Failures:\n#{errors.join}" end end end