-
-
Notifications
You must be signed in to change notification settings - Fork 281
Closed
Labels
Description
Reference: https://rspec.rubystyle.guide/#dealing-with-time
Actual behavior
I have the code:
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe InvoiceReminder do
subject(:time_with_offset) { described_class.new.get_offset_time }
it 'offsets the time 2 days into the future' do
current_time = Time.current
allow(Time).to receive(:current).and_return(current_time)
expect(time_with_offset).to eq(current_time + 2.days)
end
end
I run rubocop and don't get any offences:
ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop spec/invoice_reminder_spec.rb
Inspecting 1 file
.
1 file inspected, no offenses detected
Expected behavior
I expected to receive a suggestion to use timecop when rubocop had detected expressions like allow(Time).to receive(:current).and_return(current_time)
.
Rubocop
ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop -V
1.54.1 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 2.7.8) [x86_64-linux]
- rubocop-capybara 2.18.0
- rubocop-factory_bot 2.23.1
- rubocop-performance 1.18.0
- rubocop-rails 2.20.2
- rubocop-rake 0.6.0
- rubocop-rspec 2.22.0
- rubocop-thread_safety 0.5.1