Module: Netzke::Testing::Helpers
- Defined in:
- lib/netzke/testing/helpers.rb
Instance Method Summary collapse
- #assert_mocha_results(stop_on_error = false) ⇒ Object
- #run_mocha_spec(path, options = {}) ⇒ Object
- #wait_for_javascript(stop_on_error = false) ⇒ Object
Instance Method Details
#assert_mocha_results(stop_on_error = false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/netzke/testing/helpers.rb', line 31 def assert_mocha_results(stop_on_error = false) 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, errors: errors } JS if !result["success"] sleep 1.year if stop_on_error errors = result["errors"].each_with_index.map do |(title, error), i| "#{i+1}) in '#{title}':\n#{error}\n" end raise MochaSpecsError, errors.join end end |
#run_mocha_spec(path, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/netzke/testing/helpers.rb', line 4 def run_mocha_spec(path, = {}) @component = [:component] || path.camelcase locale = [:locale] url = netzke_components_path(class: @component, spec: path) url << "&locale=#{locale}" if locale visit url wait_for_javascript([:stop_on_error]) assert_mocha_results([:stop_on_error]) end |
#wait_for_javascript(stop_on_error = false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/netzke/testing/helpers.rb', line 17 def wait_for_javascript(stop_on_error = false) 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 raise e end |