From e91ed76d9757e09c26d3c50ff7ace431ef264787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Fri, 7 Nov 2025 23:29:59 +0100 Subject: [PATCH] Fix flaky test that depends on current minute (#9889) Merge pull request 9889 --- features/step_definitions.rb | 16 +++++++++++++++- features/support/helpers.rb | 19 ------------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/features/step_definitions.rb b/features/step_definitions.rb index b8c0e35b4..7530de9c1 100644 --- a/features/step_definitions.rb +++ b/features/step_definitions.rb @@ -363,7 +363,21 @@ end # Then(%r!^I should see today's time in "(.*)"$!) do |file| - step %(I should see "#{seconds_agnostic_time(Time.now)}" in "#{file}") + seconds = 3 + build_time = Time.now + content = file_contents(file) + date_time_pattern = /(\d{4}-\d{2}-\d{2}\s\d+:\d{2}:\d{2})/ + match_data = content.match(date_time_pattern) + expect(match_data).not_to be_nil, "No date-time pattern found in #{file}" + date_time_str = match_data.captures + file_time = Time.parse("#{date_time_str}") + time_difference = (build_time - file_time).abs + expect(time_difference).to be <= seconds, <<~MSG + Expected time in #{file} to be within #{seconds} seconds of build time. + Build time: #{build_time} + File time: #{file_time} + Difference: #{time_difference} seconds + MSG end # diff --git a/features/support/helpers.rb b/features/support/helpers.rb index 66e690afe..e7724f4c3 100644 --- a/features/support/helpers.rb +++ b/features/support/helpers.rb @@ -145,25 +145,6 @@ end # -def seconds_agnostic_datetime(datetime = Time.now) - date, time, zone = datetime.to_s.split(" ") - time = seconds_agnostic_time(time) - - [ - Regexp.escape(date), - "#{time}:\\d{2}", - Regexp.escape(zone), - ].join("\\ ") -end - -# - -def seconds_agnostic_time(time) - time = time.strftime("%H:%M:%S") if time.is_a?(Time) - hour, minutes, = time.split(":") - "#{hour}:#{minutes}" -end - # Helper method for Windows def dst_active? config = Jekyll.configuration("quiet" => true)