From 377d1e86c60b59ec9e7fa5e0f73fe343fe8247b9 Mon Sep 17 00:00:00 2001 From: Alec Hipshear Date: Tue, 5 Aug 2014 15:15:32 -0400 Subject: [PATCH] [#75] Fix a timing bug with poltergeist/turbolinks There's a timing bug in ViewHelperTest that randomly results in ```ReferenceError: Turbolinks Not Found```. This causes unrelated builds to fail, which gums up the whole open source works. Per https://github.com/teampoltergeist/poltergeist#timing-problems, the suggested way of fixing this is to just add calls to sleep. If you wish to test this in the future, use the shell code: ```for i in `seq 1 10`; do rake appraisal; done``` This should give you enough test runs to hit the timing bug at least once. --- test/test_helper.rb | 4 ++++ test/view_helper_test.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 77725df8..125699b3 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -22,3 +22,7 @@ if ActiveSupport::TestCase.method_defined?(:fixture_path=) ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) end + +def wait_for_turbolinks_to_be_available + sleep(1) +end diff --git a/test/view_helper_test.rb b/test/view_helper_test.rb index e80796de..81c74b0f 100644 --- a/test/view_helper_test.rb +++ b/test/view_helper_test.rb @@ -62,10 +62,14 @@ class ViewHelperTest < ActionDispatch::IntegrationTest page.execute_script('history.back();') assert page.has_content?('Hello Alice') + wait_for_turbolinks_to_be_available() + # Try Turbolinks javascript API. page.execute_script('Turbolinks.visit("/pages/2");') assert page.has_content?('Hello Alice') + wait_for_turbolinks_to_be_available() + page.execute_script('Turbolinks.visit("/pages/1");') assert page.has_content?('Hello Bob')