Fix flaky test that depends on current minute (#9889)

Merge pull request 9889
This commit is contained in:
Álvaro Mondéjar Rubio
2025-11-07 23:29:59 +01:00
committed by GitHub
parent a1a42bdb5c
commit e91ed76d97
2 changed files with 15 additions and 20 deletions

View File

@@ -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
#

View File

@@ -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)