From 7cad5dfa836b3073f6fe797c2f9e504648c9f910 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 17 Feb 2021 10:04:25 +0100 Subject: [PATCH] DEV: prevents time difference causing flaky spec (#12108) --- spec/models/topic_spec.rb | 2 +- spec/support/time_matcher.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index fb451850e07..661ffd24f22 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -1612,12 +1612,12 @@ describe Topic do describe 'when new category is set to auto close by default' do before do + freeze_time new_category.update!(auto_close_hours: 5) topic.user.update!(admin: true) end it 'should set a topic timer' do - freeze_time now = Time.zone.now expect { topic.change_category_to_id(new_category.id) } diff --git a/spec/support/time_matcher.rb b/spec/support/time_matcher.rb index b578fe38335..360e3eef8b5 100644 --- a/spec/support/time_matcher.rb +++ b/spec/support/time_matcher.rb @@ -2,7 +2,7 @@ RSpec::Matchers.define :be_within_one_second_of do |expected_time| match do |actual_time| - (actual_time - expected_time).abs < 1 + (actual_time - expected_time).abs <= 1 end failure_message do |actual_time| "#{actual_time} is not within 1 second of #{expected_time}"