Welcome to mirror list, hosted at ThFree Co, Russian Federation.

timecop_travel_spec.rb « rspec « cop « rubocop « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 89c46ff6c599e30cc11a14d632d17ad21ebdfd63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

require 'rubocop_spec_helper'

require_relative '../../../../rubocop/cop/rspec/timecop_travel'

RSpec.describe RuboCop::Cop::RSpec::TimecopTravel do
  context 'when calling Timecop.travel' do
    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
    end
  end

  context 'when calling a different method on Timecop' do
    it 'does not register an offense' do
      expect_no_offenses(<<~CODE)
        Timecop.freeze { create(:issue) }
      CODE
    end
  end
end