2020-10-08 11:08:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
|
|
|
require_relative '../../../../rubocop/cop/rspec/timecop_travel'
|
|
|
|
|
2021-01-07 13:10:38 -05:00
|
|
|
RSpec.describe RuboCop::Cop::RSpec::TimecopTravel do
|
2020-10-08 11:08:17 -04:00
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
context 'when calling Timecop.travel' do
|
2021-02-09 01:09:21 -05:00
|
|
|
it 'registers an offense and corrects', :aggregate_failures do
|
|
|
|
expect_offense(<<~CODE)
|
|
|
|
Timecop.travel(1.day.ago) { create(:issue) }
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `Timecop.travel`, use `travel_to` instead. [...]
|
|
|
|
CODE
|
|
|
|
|
|
|
|
expect_correction(<<~CODE)
|
|
|
|
travel_to(1.day.ago) { create(:issue) }
|
|
|
|
CODE
|
2020-10-08 11:08:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when calling a different method on Timecop' do
|
2021-02-09 01:09:21 -05:00
|
|
|
it 'does not register an offense' do
|
|
|
|
expect_no_offenses(<<~CODE)
|
|
|
|
Timecop.freeze { create(:issue) }
|
|
|
|
CODE
|
2020-10-08 11:08:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|