Skip to content

Add RSpecRails/Timecop cop #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix RSpec 4 build: trigger_inclusion changes
  • Loading branch information
pirj committed Aug 9, 2024
commit 2b067feef4b562e91fb2cf3f3d3b031abca7022f
24 changes: 16 additions & 8 deletions spec/rubocop/cop/rspec_rails/timecop_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::RSpecRails::Timecop, :config do
shared_context 'with Rails 5.1', :rails51 do
shared_context 'with Rails 5.1' do
let(:rails_version) { 5.1 }
end

shared_context 'with Rails 5.2', :rails52 do
shared_context 'with Rails 5.2' do
let(:rails_version) { 5.2 }
end

shared_context 'with Rails 6.0', :rails60 do
shared_context 'with Rails 6.0' do
let(:rails_version) { 6.0 }
end

shared_context 'with Rails 7.0', :rails70 do
shared_context 'with Rails 6.1' do
let(:rails_version) { 6.1 }
end

shared_context 'with Rails 7.0' do
let(:rails_version) { 7.0 }
end

Expand Down Expand Up @@ -102,12 +106,14 @@
end
end

context 'when Rails < 5.2', :rails51 do
context 'when Rails < 5.2' do
include_context 'with Rails 5.1'
include_examples 'flags and corrects to',
replacement: 'travel_to(Time.now)'
end

context 'with Rails 5.2+', :rails52 do
context 'with Rails 5.2+' do
include_context 'with Rails 5.2'
include_examples 'flags and corrects to',
replacement: 'freeze_time'
end
Expand All @@ -134,7 +140,8 @@
end

describe '.return' do
context 'with Rails < 6.1', :rails60 do
context 'with Rails < 6.1' do
include_context 'with Rails 6.0'
include_examples 'return prefers'

it 'flags, but does not correct return with a block' do
Expand All @@ -147,7 +154,8 @@
end
end

context 'with Rails 6.1+', :rails61 do
context 'with Rails 6.1+' do
include_context 'with Rails 6.1'
include_examples 'return prefers'

it 'flags, and corrects return with a block' do
Expand Down