From 63ce8363cd58d300259b6ac2ea4f9af8df242836 Mon Sep 17 00:00:00 2001 From: Tomasz Gieniusz Date: Tue, 24 Sep 2024 19:07:04 +1000 Subject: [PATCH] make specs less coupled with implementation details --- Gemfile | 2 ++ spec/que/poller_spec.rb | 5 +++-- spec/spec_helper.rb | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 7b048d5f..e9ef431f 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,8 @@ group :test do gem 'pry' gem 'pg_examiner', '~> 0.5.2' + + gem 'timecop', '~> 0.9.10' end gemspec diff --git a/spec/que/poller_spec.rb b/spec/que/poller_spec.rb index 763776ed..9b748783 100644 --- a/spec/que/poller_spec.rb +++ b/spec/que/poller_spec.rb @@ -283,8 +283,9 @@ def assert_poll(priorities:, locked:) result = poller.poll(priorities: { 500 => 7 }, held_locks: Set.new) assert_equal job_ids, result.map(&:id) - poller.instance_variable_set(:@next_poll_at, Time.now) - assert_equal true, poller.should_poll? + Timecop.freeze(Time.now + 30) do + assert_equal true, poller.should_poll? + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ac34bb5c..53094515 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -35,6 +35,10 @@ require 'minitest/hooks' require 'minitest/profile' +# "time travel" capabilities. +require 'timecop' +Timecop.safe_mode = true + # Other support stuff. Dir['./spec/support/**/*.rb'].sort.each(&method(:require))