From 1046c53b8bcf8222b0ab545f0803dbf451f76c93 Mon Sep 17 00:00:00 2001 From: Hamed Asghari Date: Sun, 18 Aug 2024 15:35:04 -0600 Subject: [PATCH] test: Remove dependency on timecop gem Use ActiveSupport::Testing::TimeHelpers instead --- Gemfile | 1 - Gemfile.lock | 2 -- gemfiles/rails_6.1.gemfile | 1 - gemfiles/rails_7.0.gemfile | 1 - gemfiles/rails_7.1.gemfile | 1 - gemfiles/rails_7.2.gemfile | 1 - spec/clearance/session_spec.rb | 4 ++-- spec/requests/token_expiration_spec.rb | 6 +++--- spec/spec_helper.rb | 1 + 9 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 973a4ccc9..e560bef2a 100644 --- a/Gemfile +++ b/Gemfile @@ -15,4 +15,3 @@ gem 'rails-controller-testing' gem 'rspec-rails' gem 'shoulda-matchers' gem 'sqlite3', '~> 1.7' -gem 'timecop' diff --git a/Gemfile.lock b/Gemfile.lock index 900f1463f..248104724 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -246,7 +246,6 @@ GEM stringio (3.1.1) strscan (3.1.0) thor (1.3.1) - timecop (0.9.10) timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) @@ -275,7 +274,6 @@ DEPENDENCIES rspec-rails shoulda-matchers sqlite3 (~> 1.7) - timecop BUNDLED WITH 2.3.15 diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile index a61e39f81..e5b063d36 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_6.1.gemfile @@ -15,7 +15,6 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" -gem "timecop" gem "railties", "~> 6.1.0" gem "net-smtp", require: false gem "base64", require: false diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index f603939bc..513bdec1f 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -15,7 +15,6 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" -gem "timecop" gem "railties", "~> 7.0.0" gem "base64", require: false gem "bigdecimal", require: false diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile index a39b7c9c2..5d53a414d 100644 --- a/gemfiles/rails_7.1.gemfile +++ b/gemfiles/rails_7.1.gemfile @@ -15,7 +15,6 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" -gem "timecop" gem "railties", "~> 7.1.0" gemspec path: "../" diff --git a/gemfiles/rails_7.2.gemfile b/gemfiles/rails_7.2.gemfile index 6205f43dc..e5229eb19 100644 --- a/gemfiles/rails_7.2.gemfile +++ b/gemfiles/rails_7.2.gemfile @@ -15,7 +15,6 @@ gem "rails-controller-testing" gem "rspec-rails" gem "shoulda-matchers" gem "sqlite3", "~> 1.7" -gem "timecop" gem "railties", "~> 7.2.0" gemspec path: "../" diff --git a/spec/clearance/session_spec.rb b/spec/clearance/session_spec.rb index ec5517f21..7c33f9d5c 100644 --- a/spec/clearance/session_spec.rb +++ b/spec/clearance/session_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe Clearance::Session do - before { Timecop.freeze } - after { Timecop.return } + before { freeze_time } + after { unfreeze_time } let(:session) { Clearance::Session.new(env_without_remember_token) } let(:user) { create(:user) } diff --git a/spec/requests/token_expiration_spec.rb b/spec/requests/token_expiration_spec.rb index 0db8e9d25..4e1d394c3 100644 --- a/spec/requests/token_expiration_spec.rb +++ b/spec/requests/token_expiration_spec.rb @@ -3,13 +3,13 @@ describe "Token expiration" do describe "after signing in" do before do - Timecop.freeze + freeze_time create_user_and_sign_in @initial_cookies = remember_token_cookies end after do - Timecop.return + unfreeze_time end it "should have a remember_token cookie with a future expiration" do @@ -25,7 +25,7 @@ create_user_and_sign_in @initial_cookies = remember_token_cookies - Timecop.travel(1.minute.from_now) do + travel_to(1.minute.from_now) do get root_path @followup_cookies = remember_token_cookies end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 320534a73..f91a1d910 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,7 @@ Dir[File.expand_path("spec/support/**/*.rb")].each { |f| require f } RSpec.configure do |config| + config.include ActiveSupport::Testing::TimeHelpers config.include FactoryBot::Syntax::Methods config.infer_spec_type_from_file_location! config.order = :random