Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Use rspec-wait gem directly

Christophe Bliard0c420fbcf76e
diff --git a/Gemfile b/Gemfile
index 46aa10862b5..bc3b64e7ea6 100644
--- a/Gemfile
+++ b/Gemfile
@@ -272,6 +272,7 @@ group :test do
gem "capybara_accessible_selectors", git: "https://github.com/citizensadvice/capybara_accessible_selectors", branch: "main"
gem "capybara-screenshot", "~> 1.0.17"
gem "cuprite", "~> 0.15.0"
+ gem "rspec-wait"
gem "selenium-devtools"
gem "selenium-webdriver", "~> 4.20"
diff --git a/Gemfile.lock b/Gemfile.lock
index fec582f9aa6..472ef00bf1e 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1001,6 +1001,8 @@ GEM
rspec-retry (0.6.2)
rspec-core (> 3.3)
rspec-support (3.13.1)
+ rspec-wait (1.0.1)
+ rspec (>= 3.4)
rubocop (1.66.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
@@ -1347,6 +1349,7 @@ DEPENDENCIES
rspec (~> 3.13.0)
rspec-rails (~> 7.0.0)
rspec-retry (~> 0.6.1)
+ rspec-wait
rubocop
rubocop-capybara
rubocop-factory_bot
diff --git a/modules/boards/spec/features/board_management_spec.rb b/modules/boards/spec/features/board_management_spec.rb
index 24340a9c935..7b135a8dd8b 100644
--- a/modules/boards/spec/features/board_management_spec.rb
+++ b/modules/boards/spec/features/board_management_spec.rb
@@ -281,7 +281,7 @@ RSpec.describe "Board management spec", :js, with_ee: %i[board_view] do
queries = board_page.board(reload: true).contained_queries
first = queries.find_by(name: "List 1")
second = queries.find_by(name: "List 2")
- wait_for(first.ordered_work_packages).to be_empty
+ wait_for { first.reload.ordered_work_packages }.to be_empty
expect(second.ordered_work_packages.count).to eq(1)
# Expect work package to be saved in query first
diff --git a/modules/storages/spec/features/hide_attachments_spec.rb b/modules/storages/spec/features/hide_attachments_spec.rb
index 2d24423a78a..42eb4f3bfda 100644
--- a/modules/storages/spec/features/hide_attachments_spec.rb
+++ b/modules/storages/spec/features/hide_attachments_spec.rb
@@ -62,12 +62,12 @@ RSpec.describe "Hide attachments", :js, :with_cuprite do
click_on(class: "ToggleSwitch-track")
expect(page).to have_css("toggle-switch", text: "On")
- wait_for(page).to have_css('[data-target="toggle-switch.loadingSpinner"][hidden="hidden"] svg', visible: :hidden)
+ wait_for { page }.to have_css('[data-target="toggle-switch.loadingSpinner"][hidden="hidden"] svg', visible: :hidden)
expect(project.reload).not_to be_deactivate_work_package_attachments
click_on(class: "ToggleSwitch-track")
expect(page).to have_css("toggle-switch", text: "Off")
- wait_for(page).to have_css('[data-target="toggle-switch.loadingSpinner"][hidden="hidden"] svg', visible: :hidden)
+ wait_for { page }.to have_css('[data-target="toggle-switch.loadingSpinner"][hidden="hidden"] svg', visible: :hidden)
expect(project.reload).to be_deactivate_work_package_attachments
end
@@ -135,7 +135,7 @@ RSpec.describe "Hide attachments", :js, :with_cuprite do
page.visit_tab!(:files)
# wait for storage title to appear. it means Files tab has been loaded.
- wait_for(page).to have_xpath(storage_title_xpath, wait: 35)
+ wait_for { page }.to have_xpath(storage_title_xpath, wait: 35)
expect(page).to have_no_css("op-attachments")
expect(page).to have_no_text("ATTACHMENTS")
@@ -151,7 +151,7 @@ RSpec.describe "Hide attachments", :js, :with_cuprite do
page.visit!
# wait for storage title to appear(op-attachments is in the same section usually)
- wait_for(page).to have_xpath(storage_title_xpath, wait: 35)
+ wait_for { page }.to have_xpath(storage_title_xpath, wait: 35)
expect(page).to have_no_css("op-attachments")
expect(page).to have_no_text("ATTACHMENTS")
diff --git a/modules/storages/spec/features/storages/admin/create_storage_spec.rb b/modules/storages/spec/features/storages/admin/create_storage_spec.rb
index 9c7cfbcf67d..bf5c1781c22 100644
--- a/modules/storages/spec/features/storages/admin/create_storage_spec.rb
+++ b/modules/storages/spec/features/storages/admin/create_storage_spec.rb
@@ -75,7 +75,7 @@ RSpec.describe "Admin Create a new file storage",
expect(page).not_to have_test_selector("label-openproject_oauth_application_configured-status")
# OAuth client
- wait_for(page).to have_test_selector("storage-oauth-client-label", text: "Nextcloud OAuth")
+ wait_for { page }.to have_test_selector("storage-oauth-client-label", text: "Nextcloud OAuth")
expect(page).not_to have_test_selector("label-storage_oauth_client_configured-status")
expect(page).to have_test_selector("storage-oauth-client-id-description",
text: "Allow OpenProject to access Nextcloud data using OAuth.")
@@ -203,7 +203,7 @@ RSpec.describe "Admin Create a new file storage",
end
expect(page).to have_current_path(upsale_admin_settings_storages_path)
- wait_for(page).to have_text("OneDrive/SharePoint integration")
+ wait_for { page }.to have_text("OneDrive/SharePoint integration")
end
end
@@ -235,14 +235,14 @@ RSpec.describe "Admin Create a new file storage",
"Azure application or use an existing one for authentication.")
# Access Management
- wait_for(page).to have_test_selector("access-management-label", text: "Access management")
+ wait_for { page }.to have_test_selector("access-management-label", text: "Access management")
expect(page).not_to have_test_selector("label-access_management_configured-status")
expect(page).to have_text("Select the type of management of user access and folder creation.")
expect(page).to have_test_selector("access-management-description",
text: "Select the type of management of user access and folder creation.")
# OAuth client
- wait_for(page).to have_test_selector("storage-oauth-client-label", text: "Azure OAuth")
+ wait_for { page }.to have_test_selector("storage-oauth-client-label", text: "Azure OAuth")
expect(page).not_to have_test_selector("label-storage_oauth_client_configured-status")
expect(page).to have_test_selector("storage-oauth-client-id-description",
text: "Allow OpenProject to access Azure data using OAuth " \
@@ -268,8 +268,8 @@ RSpec.describe "Admin Create a new file storage",
click_on "Save and continue"
end
- wait_for(page).to have_test_selector("label-name_configured-storage_tenant_drive_configured-status",
- text: "Completed")
+ wait_for { page }.to have_test_selector("label-name_configured-storage_tenant_drive_configured-status",
+ text: "Completed")
expect(page).to have_test_selector("storage-description", text: "OneDrive/SharePoint - My OneDrive")
end
@@ -287,7 +287,7 @@ RSpec.describe "Admin Create a new file storage",
click_on "Save and continue"
end
- wait_for(page).to have_test_selector("label-access_management_configured-status", text: "Completed")
+ wait_for { page }.to have_test_selector("label-access_management_configured-status", text: "Completed")
expect(page).to have_test_selector("access-management-description", text: "Manually managed access and folders")
end
@@ -317,7 +317,7 @@ RSpec.describe "Admin Create a new file storage",
end
expect(page).to have_current_path(edit_admin_settings_storage_path(Storages::Storage.last))
- wait_for(page).to have_test_selector(
+ wait_for { page }.to have_test_selector(
"primer-banner-message-component",
text: "Storage connected successfully! Remember to activate the module and the specific " \
"storage in the project settings of each desired project to use it."
@@ -332,7 +332,7 @@ RSpec.describe "Admin Create a new file storage",
visit select_provider_admin_settings_storages_path
expect(page).to have_current_path(admin_settings_storages_path)
- wait_for(page).to have_text("Please select a valid storage provider.")
+ wait_for { page }.to have_text("Please select a valid storage provider.")
end
end
@@ -341,7 +341,7 @@ RSpec.describe "Admin Create a new file storage",
visit select_provider_admin_settings_storages_path(provider: "foobar")
expect(page).to have_current_path(admin_settings_storages_path)
- wait_for(page).to have_text("Please select a valid storage provider.")
+ wait_for { page }.to have_text("Please select a valid storage provider.")
end
end
end
diff --git a/modules/storages/spec/features/storages/admin/project_storages_spec.rb b/modules/storages/spec/features/storages/admin/project_storages_spec.rb
index dd97a3b5b9a..f4ae5ee03f8 100644
--- a/modules/storages/spec/features/storages/admin/project_storages_spec.rb
+++ b/modules/storages/spec/features/storages/admin/project_storages_spec.rb
@@ -140,7 +140,7 @@ RSpec.describe "Admin lists project mappings for a storage",
page.within("dialog") do
click_on "Add"
- wait_for(page).to have_text("Please select a project.")
+ wait_for { page }.to have_text("Please select a project.")
end
end
@@ -209,7 +209,7 @@ RSpec.describe "Admin lists project mappings for a storage",
expect(page.find_by_id("storages_project_storage_project_folder_mode_automatic")).to be_checked
choose "Existing folder with manually managed permissions"
- wait_for(page).to have_text("No selected folder")
+ wait_for { page }.to have_text("No selected folder")
click_on "Select folder"
location_picker.expect_open
@@ -243,7 +243,7 @@ RSpec.describe "Admin lists project mappings for a storage",
check "Include sub-projects"
choose "Existing folder with manually managed permissions"
- wait_for(page).to have_text("No selected folder")
+ wait_for { page }.to have_text("No selected folder")
click_on "Add"
@@ -262,12 +262,12 @@ RSpec.describe "Admin lists project mappings for a storage",
click_on "Add projects"
within("dialog") do
- wait_for(page).to have_button("Nextcloud log in")
+ wait_for { page }.to have_button("Nextcloud log in")
expect(page).to have_text("Login to Nextcloud required")
click_on("Nextcloud log in")
- wait_for(page).to have_current_path(
+ wait_for { page }.to have_current_path(
%r{/index.php/apps/oauth2/authorize\?client_id=.*&redirect_uri=.*&response_type=code&state=.*}
)
end
@@ -311,9 +311,9 @@ RSpec.describe "Admin lists project mappings for a storage",
within("dialog") do
choose "Existing folder with manually managed permissions"
- wait_for(page).to have_button("Nextcloud login")
+ wait_for { page }.to have_button("Nextcloud login")
click_on("Nextcloud login")
- wait_for(page).to have_current_path(
+ wait_for { page }.to have_current_path(
%r{/index.php/apps/oauth2/authorize\?client_id=.*&redirect_uri=.*&response_type=code&state=.*}
)
end
diff --git a/modules/storages/spec/features/storages/project_settings/oauth_access_grant_spec.rb b/modules/storages/spec/features/storages/project_settings/oauth_access_grant_spec.rb
index aa1ab0c2616..c46f77211e7 100644
--- a/modules/storages/spec/features/storages/project_settings/oauth_access_grant_spec.rb
+++ b/modules/storages/spec/features/storages/project_settings/oauth_access_grant_spec.rb
@@ -82,8 +82,8 @@ RSpec.describe "OAuth Access Grant Nudge upon adding a storage to a project",
expect(page).to be_axe_clean
expect(page).to have_text("Login to Nextcloud required")
click_on("Nextcloud log in")
- wait_for(page).to have_current_path("/index.php/apps/oauth2/authorize?client_id=#{storage.oauth_client.client_id}&" \
- "redirect_uri=#{redirect_uri}&response_type=code&state=#{nonce}")
+ wait_for { page }.to have_current_path("/index.php/apps/oauth2/authorize?client_id=#{storage.oauth_client.client_id}&" \
+ "redirect_uri=#{redirect_uri}&response_type=code&state=#{nonce}")
end
end
@@ -100,8 +100,8 @@ RSpec.describe "OAuth Access Grant Nudge upon adding a storage to a project",
expect(page).to be_axe_clean
expect(page).to have_text("Login to Nextcloud required")
click_on("Nextcloud log in")
- wait_for(page).to have_current_path("/index.php/apps/oauth2/authorize?client_id=#{storage.oauth_client.client_id}&" \
- "redirect_uri=#{redirect_uri}&response_type=code&state=#{nonce}")
+ wait_for { page }.to have_current_path("/index.php/apps/oauth2/authorize?client_id=#{storage.oauth_client.client_id}&" \
+ "redirect_uri=#{redirect_uri}&response_type=code&state=#{nonce}")
end
end
end
diff --git a/spec/support/wait/handler.rb b/spec/support/wait/handler.rb
deleted file mode 100644
index efee55b9a62..00000000000
--- a/spec/support/wait/handler.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-# frozen_string_literal: true
-
-# borrowed from rspec-wait, avoiding usage of Timeout
-module RSpec
- module Wait
- module Handler
- def handle_matcher(target, *, &)
- t = Time.current
-
- begin
- actual = target.respond_to?(:call) ? target.call : target
- super(actual, *, &)
- rescue RSpec::Expectations::ExpectationNotMetError => e
- elapsed = Time.current - t
- if elapsed < RSpec.configuration.wait_timeout
- sleep RSpec.configuration.wait_delay
- retry
- else
- raise e
- end
- end
- end
- end
-
- # From: https://github.com/rspec/rspec-expectations/blob/v3.12.3/lib/rspec/expectations/handler.rb#L46-L71
- class PositiveHandler < RSpec::Expectations::PositiveExpectationHandler
- extend Handler
- end
-
- # From: https://github.com/rspec/rspec-expectations/blob/v3.12.3/lib/rspec/expectations/handler.rb#L74-L107
- class NegativeHandler < RSpec::Expectations::NegativeExpectationHandler
- extend Handler
- end
- end
-end
diff --git a/spec/support/wait/target.rb b/spec/support/wait/target.rb
deleted file mode 100644
index fe44e962961..00000000000
--- a/spec/support/wait/target.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-# frozen_string_literal: true
-
-# borrowed from rspec-wait
-module RSpec
- module Wait
- class Target < RSpec::Expectations::ExpectationTarget
- # From: https://github.com/rspec/rspec-expectations/blob/v3.12.3/lib/rspec/expectations/expectation_target.rb#L22
- UndefinedValue = Module.new
-
- # From: https://github.com/rspec/rspec-expectations/blob/v3.12.3/lib/rspec/expectations/expectation_target.rb#L31-L33
- def initialize(target, **options)
- @wait_options = options
- super(target)
- end
-
- # From: https://github.com/rspec/rspec-expectations/blob/v3.12.3/lib/rspec/expectations/expectation_target.rb#L36-L47
- def self.for(value, block, **)
- if UndefinedValue.equal?(value)
- unless block
- raise ArgumentError, "You must pass either an argument or a block to `wait_for`."
- end
-
- new(block, **)
- elsif block
- raise ArgumentError, "You cannot pass both an argument and a block to `wait_for`."
- else
- new(value, **)
- end
- end
-
- # From: https://github.com/rspec/rspec-expectations/blob/v3.12.3/lib/rspec/expectations/expectation_target.rb#L63-L66
- def to(matcher = nil, message = nil, &)
- prevent_operator_matchers(:to) unless matcher
- with_wait { PositiveHandler.handle_matcher(@target, matcher, message, &) }
- end
-
- # From: https://github.com/rspec/rspec-expectations/blob/v3.12.3/lib/rspec/expectations/expectation_target.rb#L76-L79
- def not_to(matcher = nil, message = nil, &)
- prevent_operator_matchers(:not_to) unless matcher
- with_wait { NegativeHandler.handle_matcher(@target, matcher, message, &) }
- end
-
- alias_method :to_not, :not_to
-
- private
-
- def with_wait(&)
- Wait.with_wait(**@wait_options, &)
- end
- end
- end
-end
diff --git a/spec/support/wait_for.rb b/spec/support/wait_for.rb
deleted file mode 100644
index 8fcde59104f..00000000000
--- a/spec/support/wait_for.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-# frozen_string_literal: true
-
-require_relative "wait/handler"
-require_relative "wait/target"
-
-# borrowed from rspec-wait, avoiding usage of Timeout
-module RSpec
- module Wait
- module_function
-
- # Drop-in replacement for `expect` assertions, waiting for the assertion to
- # pass.
- #
- # Useful for testing user interfaces with tricky timing elements like
- # JavaScript interactions or remote requests.
- #
- # The assertion is checked every `RSpec.configuration.wait_delay` seconds
- # until `RSpec.configuration.wait_timeout` seconds have passed.
- #
- # Default value of `wait_timeout` is 3. It can be overriden with `:timeout`
- # keyword parameter.
- #
- # Default value of `wait_delay` is 0.05. It can be overriden with `:delay`
- # keyword parameter.
- #
- # Examples:
- # wait_for(ticker.tape).to eq("··-·")
- # wait_for { ticker.tape }.to eq("··-· ---")
- def wait_for(value = Target::UndefinedValue, &block)
- Target.for(value, block)
- end
-
- # Sets timeout and delay values for `wait_for`.
- #
- # @param timeout [Numeric] time in seconds to wait up for assertions to pass
- # @param delay [Numeric] time in seconds elapsing between two checks of an
- # assertion
- # Examples:
- # with_wait(timeout: 10, delay: 1) do
- # wait_for { ticker.tape }.to eq("··-· ---")
- # end
- def with_wait(timeout: nil, delay: nil)
- original_timeout = RSpec.configuration.wait_timeout
- original_delay = RSpec.configuration.wait_delay
-
- RSpec.configuration.wait_timeout = timeout if timeout
- RSpec.configuration.wait_delay = delay if delay
-
- yield
- ensure
- RSpec.configuration.wait_timeout = original_timeout
- RSpec.configuration.wait_delay = original_delay
- end
- end
-end
-
-RSpec.configure do |config|
- config.include(RSpec::Wait)
-
- config.add_setting(:wait_timeout, default: 3)
- config.add_setting(:wait_delay, default: 0.05)
-end