From b10d9f9cf3b031429f028bb1dfdffc4c7b0a4eb8 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Mon, 5 Dec 2022 12:04:04 +0000 Subject: [PATCH] tidy Timecop calls (#1053) --- spec/models/form_handler_spec.rb | 39 ++++++++------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 6a335e232..bf03766e2 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -2,27 +2,18 @@ require "rails_helper" RSpec.describe FormHandler do let(:form_handler) { described_class.instance } + let(:now) { Time.utc(2022, 9, 20) } - before do - Timecop.freeze(Time.utc(2022, 9, 20)) - Singleton.__init__(described_class) - end - - after do - Timecop.unfreeze + around do |example| + Timecop.freeze(now) do + Singleton.__init__(described_class) + example.run + end Singleton.__init__(described_class) end context "when accessing a form in a different year" do - before do - Timecop.freeze(Time.utc(2021, 8, 3)) - Singleton.__init__(described_class) - end - - after do - Timecop.unfreeze - Singleton.__init__(described_class) # reload FormHandler Instance to update form definitions between runs - end + let(:now) { Time.utc(2021, 8, 3) } it "is able to load a current lettings form" do form = form_handler.get_form("current_lettings") @@ -83,13 +74,7 @@ RSpec.describe FormHandler do describe "Current collection start year" do context "when the date is after 1st of April" do - before do - Timecop.freeze(Time.utc(2022, 8, 3)) - end - - after do - Timecop.unfreeze - end + let(:now) { Time.utc(2022, 8, 3) } it "returns the same year as the current start year" do expect(form_handler.current_collection_start_year).to eq(2022) @@ -125,13 +110,7 @@ RSpec.describe FormHandler do end context "with the date before 1st of April" do - before do - Timecop.freeze(Time.utc(2022, 2, 3)) - end - - after do - Timecop.unfreeze - end + let(:now) { Time.utc(2022, 2, 3) } it "returns the previous year as the current start year" do expect(form_handler.current_collection_start_year).to eq(2021)