From 018ef2e4838cda78521144637cfa77b93ed9b088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 19 Jul 2023 01:57:56 +0200 Subject: [PATCH] Simplify stubbing age responses in residence tests --- spec/models/officing/residence_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/models/officing/residence_spec.rb b/spec/models/officing/residence_spec.rb index 96df02b1d..a9d842d85 100644 --- a/spec/models/officing/residence_spec.rb +++ b/spec/models/officing/residence_spec.rb @@ -130,13 +130,15 @@ describe Officing::Residence do describe "allowed age" do it "is not valid if user is under allowed age" do - allow_any_instance_of(Officing::Residence).to receive(:response_date_of_birth).and_return(15.years.ago) + allow(residence).to receive(:response_date_of_birth).and_return(15.years.ago) + expect(residence).not_to be_valid expect(residence.errors[:year_of_birth]).to include("You don't have the required age to participate") end it "is valid if user is above allowed age" do - allow_any_instance_of(Officing::Residence).to receive(:response_date_of_birth).and_return(16.years.ago) + allow(residence).to receive(:response_date_of_birth).and_return(16.years.ago) + expect(residence).to be_valid expect(residence.errors[:year_of_birth]).to be_empty end