2020-08-26 00:10:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-18 18:10:07 +00:00
|
|
|
require 'rubocop_spec_helper'
|
2020-08-26 00:10:31 +00:00
|
|
|
|
|
|
|
require_relative '../../../../rubocop/cop/rspec/timecop_freeze'
|
|
|
|
|
2021-01-07 18:10:38 +00:00
|
|
|
RSpec.describe RuboCop::Cop::RSpec::TimecopFreeze do
|
2020-08-26 00:10:31 +00:00
|
|
|
context 'when calling Timecop.freeze' do
|
2021-02-09 06:09:21 +00:00
|
|
|
it 'registers an offense and corrects', :aggregate_failures do
|
|
|
|
expect_offense(<<~CODE)
|
|
|
|
Timecop.freeze(Time.current) { example.run }
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `Timecop.freeze`, use `freeze_time` instead. [...]
|
|
|
|
CODE
|
|
|
|
|
|
|
|
expect_correction(<<~CODE)
|
|
|
|
freeze_time(Time.current) { example.run }
|
|
|
|
CODE
|
2020-08-26 00:10:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when calling a different method on Timecop' do
|
2021-02-09 06:09:21 +00:00
|
|
|
it 'does not register an offense' do
|
|
|
|
expect_no_offenses(<<~CODE)
|
|
|
|
Timecop.travel(Time.current)
|
|
|
|
CODE
|
2020-08-26 00:10:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|