debian-mirror-gitlab/spec/rubocop/cop/rspec/timecop_freeze_spec.rb
2022-10-11 01:57:18 +05:30

28 lines
792 B
Ruby

# frozen_string_literal: true
require 'rubocop_spec_helper'
require_relative '../../../../rubocop/cop/rspec/timecop_freeze'
RSpec.describe RuboCop::Cop::RSpec::TimecopFreeze do
context 'when calling Timecop.freeze' do
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
end
end
context 'when calling a different method on Timecop' do
it 'does not register an offense' do
expect_no_offenses(<<~CODE)
Timecop.travel(Time.current)
CODE
end
end
end