Skip to content

Add extra spec for time offsets / frozen time #2346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions spec/rspec/rails/matchers/active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def self.find(_id)
end

RSpec.describe "ActiveJob matchers", skip: !RSpec::Rails::FeatureCheck.has_active_job? do
include ActiveSupport::Testing::TimeHelpers if defined?(ActiveSupport::Testing::TimeHelpers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it might not be available exactly?

Copy link
Member Author

@JonRowe JonRowe May 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rails 5.0 and 5.1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it's clear that freeze_time isn't part of it, but TimeHelpers should be always available, and it's not necessary to check if they are defined (I hope we're requiring them somewhere).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, I was just checking freeze_time feel free to open a PR if you'd like to improve it, maybe backfill an implementation fir freeze_time if you have time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backfill an implementation for freeze_time

Noway! :D
If just for tests - it's kind of useless since we already run those specs against Rails that have it. For usage in tests - there's TimeCop (god forgive me) - wouldn't dare to write yet another one we'll have to support.


around do |example|
original_logger = ActiveJob::Base.logger
ActiveJob::Base.logger = Logger.new(nil) # Silence messages "[ActiveJob] Enqueued ...".
Expand Down Expand Up @@ -223,6 +225,14 @@ def self.name; "LoggingJob"; end
}.to have_enqueued_job.at(time)
end

skip_freeze_time = method_defined?(:freeze_time) ? false : "#freeze_time is undefined"
it "works with time offsets", skip: skip_freeze_time do
freeze_time do
time = Time.current
expect { hello_job.set(wait: 5).perform_later }.to have_enqueued_job.at(time + 5)
end
end

it "accepts composable matchers as an at date" do
future = 1.minute.from_now
slightly_earlier = 58.seconds.from_now
Expand Down