Skip to content

Commit

Permalink
Use finders to raise error in the expectation in order to get the ret…
Browse files Browse the repository at this point in the history
…ry_block work correctly.
  • Loading branch information
dombesz committed Dec 17, 2024
1 parent b488419 commit 89748e3
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,19 @@ def expect_selector_for(step, selector:, text: nil, present: true)
input_id = "#project_available_life_cycle_steps_attributes_#{step.position - 1}_#{field}"
parent = find(input_id).ancestor("primer-datepicker-field")

# Using retry_block with relying on errors raise by expectations do not work,
# hence using the finder methods instead. They do work with retry_block correctly.
if present
expect(parent).to have_selector(selector, text:)
parent.find(selector, text:)
else
expect(parent).to have_no_selector(selector)
begin
if parent.find(selector)
raise "Expected to not have a visible selector '#{selector}'."
end
rescue Capybara::ElementNotFound
# Noop
end
end
rescue StandardError
raise "Expected to#{present ? '' : ' not'} have a visible selector '#{selector}'."
end
end
end
Expand Down

0 comments on commit 89748e3

Please sign in to comment.