From cf2e4d8ba35d88b943239076c9117b10b01485ef Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Tue, 9 Oct 2018 10:29:25 -0700 Subject: [PATCH] Fix typo and explain `sleep` usage in tests --- lib/capybara/spec/session/click_link_spec.rb | 2 +- lib/capybara/spec/session/html_spec.rb | 7 +++++++ lib/capybara/spec/session/node_spec.rb | 6 +++++- lib/capybara/spec/session/refresh_spec.rb | 4 ++++ lib/capybara/spec/session/window/switch_to_window_spec.rb | 4 ++++ lib/capybara/spec/session/window/window_opened_by_spec.rb | 4 ++++ lib/capybara/spec/session/window/window_spec.rb | 4 ++++ lib/capybara/spec/session/window/windows_spec.rb | 4 ++++ 8 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/capybara/spec/session/click_link_spec.rb b/lib/capybara/spec/session/click_link_spec.rb index f7a8f13d..50666ce3 100644 --- a/lib/capybara/spec/session/click_link_spec.rb +++ b/lib/capybara/spec/session/click_link_spec.rb @@ -211,7 +211,7 @@ Capybara::SpecHelper.spec '#click_link' do download_file = File.join(Capybara.save_path, 'download.csv') expect(File).not_to exist(download_file) @session.click_link('Download Me') - sleep 2 + sleep 2 # allow time for file to download expect(File).to exist(download_file) FileUtils.rm_rf download_file end diff --git a/lib/capybara/spec/session/html_spec.rb b/lib/capybara/spec/session/html_spec.rb index 3ffce717..e1fc375f 100644 --- a/lib/capybara/spec/session/html_spec.rb +++ b/lib/capybara/spec/session/html_spec.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this +# because of the methods being tested. In tests using Capybara this type of behavior should be implemented +# using Capybara provided assertions with builtin waiting behavior. + Capybara::SpecHelper.spec '#html' do it 'should return the unmodified page body' do @session.visit('/') @@ -8,6 +12,7 @@ Capybara::SpecHelper.spec '#html' do it 'should return the current state of the page', requires: [:js] do @session.visit('/with_js') + sleep 1 expect(@session.html).to include('I changed it') expect(@session.html).not_to include('This is text') end @@ -21,6 +26,7 @@ Capybara::SpecHelper.spec '#source' do it 'should return the current state of the page', requires: [:js] do @session.visit('/with_js') + sleep 1 expect(@session.source).to include('I changed it') expect(@session.source).not_to include('This is text') end @@ -34,6 +40,7 @@ Capybara::SpecHelper.spec '#body' do it 'should return the current state of the page', requires: [:js] do @session.visit('/with_js') + sleep 1 expect(@session.body).to include('I changed it') expect(@session.body).not_to include('This is text') end diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index fd660cbc..dc6a8807 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this +# because of the methods being tested. In tests using Capybara this type of behavior should be implemented +# using Capybara provided assertions with builtin waiting behavior. + Capybara::SpecHelper.spec 'node' do before do @session.visit('/with_html') @@ -478,7 +482,7 @@ Capybara::SpecHelper.spec 'node' do expect(@session.find(:css, '#address1_city').value).to eq 'Oceanside' end - it 'should hold modifers at top level' do + it 'should hold modifiers at top level' do @session.visit('/form') @session.find(:css, '#address1_city').send_keys('ocean', :shift, 'side') expect(@session.find(:css, '#address1_city').value).to eq 'oceanSIDE' diff --git a/lib/capybara/spec/session/refresh_spec.rb b/lib/capybara/spec/session/refresh_spec.rb index 020da350..23185a03 100644 --- a/lib/capybara/spec/session/refresh_spec.rb +++ b/lib/capybara/spec/session/refresh_spec.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this +# because of the methods being tested. In tests using Capybara this type of behavior should be implemented +# using Capybara provided assertions with builtin waiting behavior. + Capybara::SpecHelper.spec '#refresh' do it 'reload the page' do @session.visit('/form') diff --git a/lib/capybara/spec/session/window/switch_to_window_spec.rb b/lib/capybara/spec/session/window/switch_to_window_spec.rb index b290015b..283ef99b 100644 --- a/lib/capybara/spec/session/window/switch_to_window_spec.rb +++ b/lib/capybara/spec/session/window/switch_to_window_spec.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this +# because of the methods being tested. In tests using Capybara this type of behavior should be implemented +# using Capybara provided assertions with builtin waiting behavior. + Capybara::SpecHelper.spec '#switch_to_window', requires: [:windows] do before do @window = @session.current_window diff --git a/lib/capybara/spec/session/window/window_opened_by_spec.rb b/lib/capybara/spec/session/window/window_opened_by_spec.rb index ff500430..2fbde97f 100644 --- a/lib/capybara/spec/session/window/window_opened_by_spec.rb +++ b/lib/capybara/spec/session/window/window_opened_by_spec.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this +# because of the methods being tested. In tests using Capybara this type of behavior should be implemented +# using Capybara provided assertions with builtin waiting behavior. + Capybara::SpecHelper.spec '#window_opened_by', requires: [:windows] do before do @window = @session.current_window diff --git a/lib/capybara/spec/session/window/window_spec.rb b/lib/capybara/spec/session/window/window_spec.rb index 7b83ab0d..50a53426 100644 --- a/lib/capybara/spec/session/window/window_spec.rb +++ b/lib/capybara/spec/session/window/window_spec.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this +# because of the methods being tested. In tests using Capybara this type of behavior should be implemented +# using Capybara provided assertions with builtin waiting behavior. + Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do before do @window = @session.current_window diff --git a/lib/capybara/spec/session/window/windows_spec.rb b/lib/capybara/spec/session/window/windows_spec.rb index d936754f..65238b7d 100644 --- a/lib/capybara/spec/session/window/windows_spec.rb +++ b/lib/capybara/spec/session/window/windows_spec.rb @@ -1,5 +1,9 @@ # frozen_string_literal: true +# Note: This file uses `sleep` to sync up parts of the tests. This is only implemented like this +# because of the methods being tested. In tests using Capybara this type of behavior should be implemented +# using Capybara provided assertions with builtin waiting behavior. + Capybara::SpecHelper.spec '#windows', requires: [:windows] do before do @window = @session.current_window