Skip to content

Commit 29fd700

Browse files
committed
fixup! Small adjustments to make the move to RSpecRails
1 parent 94cdc63 commit 29fd700

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Master (Unreleased)
44

5+
- Add a cop that makes `Timecop` illegal, in favour of `ActiveSupport::Testing::TimeHelpers`. ([@sambostock])
6+
57
## 2.30.0 (2024-06-12)
68

79
- Fix an runtime error for rubocop-rspec +3.0. ([@bquorning])
@@ -79,6 +81,7 @@
7981
[@paydaylight]: https://github.com/paydaylight
8082
[@pirj]: https://github.com/pirj
8183
[@r7kamura]: https://github.com/r7kamura
84+
[@sambostock]: https://github.com/sambostock
8285
[@splattael]: https://github.com/splattael
8386
[@tmaier]: https://github.com/tmaier
8487
[@ydah]: https://github.com/ydah

config/default.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ RSpecRails/NegationBeValid:
7777
VersionChanged: '2.29'
7878
Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/NegationBeValid
7979

80+
RSpecRails/Timecop:
81+
Description: Enforces use of `ActiveSupport::Testing::TimeHelpers` instead of `Timecop`.
82+
Enabled: pending
83+
VersionAdded: "<<next>>"
84+
SafeAutoCorrect: false
85+
Reference: https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/RSpecRails/Timecop
86+
8087
RSpecRails/TravelAround:
8188
Description: Prefer to travel in `before` rather than `around`.
8289
Enabled: pending

lib/rubocop/cop/rails/timecop.rb renamed to lib/rubocop/cop/rspec_rails/timecop.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
module RuboCop
44
module Cop
5-
module Rails
6-
# Disallows all usage of `Timecop`, in favour of
7-
# `ActiveSupport::Testing::TimeHelpers`.
5+
module RSpecRails
6+
# Enforces use of `ActiveSupport::Testing::TimeHelpers` instead of `Timecop`.
87
#
98
# ## Migration
109
# `Timecop.freeze` should be replaced with `freeze_time` when used
@@ -93,7 +92,7 @@ module Rails
9392
# travel_to(time)
9493
# travel(duration) { assert true }
9594
# travel_to(time) { assert true }
96-
class Timecop < Base
95+
class Timecop < ::RuboCop::Cop::Base
9796
extend AutoCorrector
9897

9998
FREEZE_MESSAGE = 'Use `%<replacement>s` instead of `Timecop.freeze`'

lib/rubocop/cop/rspec_rails_cops.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
require_relative 'rspec_rails/inferred_spec_type'
77
require_relative 'rspec_rails/minitest_assertions'
88
require_relative 'rspec_rails/negation_be_valid'
9+
require_relative 'rspec_rails/timecop'
910
require_relative 'rspec_rails/travel_around'

spec/rubocop/cop/rails/timecop_spec.rb renamed to spec/rubocop/cop/rspec_rails/timecop_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe RuboCop::Cop::Rails::Timecop, :config do
3+
RSpec.describe RuboCop::Cop::RSpecRails::Timecop, :config do
44
shared_examples 'adds an offense to constant, and does not correct' do |usage:|
55
constant = usage.include?('::Timecop') ? '::Timecop' : 'Timecop'
66

0 commit comments

Comments
 (0)