Browse Source

tidy Timecop calls (#1053)

pull/1057/head
Phil Lee 2 years ago committed by GitHub
parent
commit
b10d9f9cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 39
      spec/models/form_handler_spec.rb

39
spec/models/form_handler_spec.rb

@ -2,27 +2,18 @@ require "rails_helper"
RSpec.describe FormHandler do RSpec.describe FormHandler do
let(:form_handler) { described_class.instance } let(:form_handler) { described_class.instance }
let(:now) { Time.utc(2022, 9, 20) }
before do around do |example|
Timecop.freeze(Time.utc(2022, 9, 20)) Timecop.freeze(now) do
Singleton.__init__(described_class) Singleton.__init__(described_class)
end example.run
end
after do
Timecop.unfreeze
Singleton.__init__(described_class) Singleton.__init__(described_class)
end end
context "when accessing a form in a different year" do context "when accessing a form in a different year" do
before do let(:now) { Time.utc(2021, 8, 3) }
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
it "is able to load a current lettings form" do it "is able to load a current lettings form" do
form = form_handler.get_form("current_lettings") form = form_handler.get_form("current_lettings")
@ -83,13 +74,7 @@ RSpec.describe FormHandler do
describe "Current collection start year" do describe "Current collection start year" do
context "when the date is after 1st of April" do context "when the date is after 1st of April" do
before do let(:now) { Time.utc(2022, 8, 3) }
Timecop.freeze(Time.utc(2022, 8, 3))
end
after do
Timecop.unfreeze
end
it "returns the same year as the current start year" do it "returns the same year as the current start year" do
expect(form_handler.current_collection_start_year).to eq(2022) expect(form_handler.current_collection_start_year).to eq(2022)
@ -125,13 +110,7 @@ RSpec.describe FormHandler do
end end
context "with the date before 1st of April" do context "with the date before 1st of April" do
before do let(:now) { Time.utc(2022, 2, 3) }
Timecop.freeze(Time.utc(2022, 2, 3))
end
after do
Timecop.unfreeze
end
it "returns the previous year as the current start year" do it "returns the previous year as the current start year" do
expect(form_handler.current_collection_start_year).to eq(2021) expect(form_handler.current_collection_start_year).to eq(2021)

Loading…
Cancel
Save