2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
|
|
|
require_relative '../../../../rubocop/cop/rspec/timecop_freeze'
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
RSpec.describe RuboCop::Cop::RSpec::TimecopFreeze do
|
2020-11-24 15:15:51 +05:30
|
|
|
subject(:cop) { described_class.new }
|
|
|
|
|
|
|
|
context 'when calling Timecop.freeze' do
|
2021-03-11 19:13:27 +05:30
|
|
|
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-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when calling a different method on Timecop' do
|
2021-03-11 19:13:27 +05:30
|
|
|
it 'does not register an offense' do
|
|
|
|
expect_no_offenses(<<~CODE)
|
|
|
|
Timecop.travel(Time.current)
|
|
|
|
CODE
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|