diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/rubocop/cop/rspec/timecop_travel_spec.rb | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/rubocop/cop/rspec/timecop_travel_spec.rb')
-rw-r--r-- | spec/rubocop/cop/rspec/timecop_travel_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/rubocop/cop/rspec/timecop_travel_spec.rb b/spec/rubocop/cop/rspec/timecop_travel_spec.rb new file mode 100644 index 00000000000..25a8127d40e --- /dev/null +++ b/spec/rubocop/cop/rspec/timecop_travel_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../../rubocop/cop/rspec/timecop_travel' + +RSpec.describe RuboCop::Cop::RSpec::TimecopTravel, type: :rubocop do + include CopHelper + + subject(:cop) { described_class.new } + + context 'when calling Timecop.travel' do + let(:source) do + <<~SRC + Timecop.travel(1.day.ago) { create(:issue) } + SRC + end + + let(:corrected_source) do + <<~SRC + travel_to(1.day.ago) { create(:issue) } + SRC + end + + it 'registers an offence' do + inspect_source(source) + + expect(cop.offenses.size).to eq(1) + end + + it 'can autocorrect the source' do + expect(autocorrect_source(source)).to eq(corrected_source) + end + end + + context 'when calling a different method on Timecop' do + let(:source) do + <<~SRC + Timecop.freeze { create(:issue) } + SRC + end + + it 'does not register an offence' do + inspect_source(source) + + expect(cop.offenses).to be_empty + end + end +end |