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

Improve error message of #retry_block used in capybara tests

Christophe Bliard2690ed707225
diff --git a/spec/support/rspec_retry.rb b/spec/support/rspec_retry.rb
index 26d4573893a..5fdc863f582 100644
--- a/spec/support/rspec_retry.rb
+++ b/spec/support/rspec_retry.rb
@@ -42,9 +42,17 @@ def retry_block(args: {}, screenshot: false, &block)
end
log_errors = Proc.new do |exception, try, elapsed_time, next_interval|
- warn <<~EOS
+ max_tries = RSpec.current_example.metadata[:retry] + 1
+ exception_source_line = exception.backtrace.find { |line| line.start_with?(Rails.root.to_s) }
+ next_try_message = next_interval ? "#{next_interval} seconds until the next try" : "last try"
+ # use stderr directly to prevent having StructuredWarnings::StandardWarning
+ # messy and useless output
+ $stderr.puts <<~EOS # rubocop:disable Style/StderrPuts
+ -- rspec-retry #{try}/#{max_tries}--
#{exception.class}: '#{exception.message}'
- #{try} tries in #{elapsed_time} seconds and #{next_interval} seconds until the next try.
+ occurred on #{exception_source_line}
+ #{try} tries in #{elapsed_time} seconds, #{next_try_message}.
+ --
EOS
if screenshot
@@ -56,5 +64,5 @@ def retry_block(args: {}, screenshot: false, &block)
end
end
- Retriable.retriable(args.merge(on_retry: log_errors), &block)
+ Retriable.retriable(on_retry: log_errors, **args, &block)
end