DEV: adds within_one_minute time matcher (#12109)

This commit is contained in:
Joffrey JAFFEUX 2021-02-17 10:52:49 +01:00 committed by GitHub
parent 9d7dc89d79
commit 8f5233a7bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -1629,7 +1629,7 @@ describe Topic do
expect(topic_timer.user).to eq(Discourse.system_user)
expect(topic_timer.topic).to eq(topic)
expect(topic_timer.execute_at).to be_within_one_second_of(now + 5.hours)
expect(topic_timer.execute_at).to be_within_one_minute_of(now + 5.hours)
end
describe 'when topic is already closed' do

View File

@ -2,13 +2,22 @@
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}"
end
end
RSpec::Matchers.define :be_within_one_minute_of do |expected_time|
match do |actual_time|
(actual_time - expected_time).abs < 60
end
failure_message do |actual_time|
"#{actual_time} is not within 1 minute of #{expected_time}"
end
end
RSpec::Matchers.define :eq_time do |expected_time|
match do |actual_time|
(actual_time - expected_time).abs < 0.001