From c2b3a1cd40d2364131b53d9b90f1d1f42b856c63 Mon Sep 17 00:00:00 2001 From: JG Date: Tue, 5 Jul 2022 11:19:36 +0100 Subject: [PATCH] checking raising error --- spec/models/location_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 45d731eb7..a886c6034 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -20,9 +20,8 @@ RSpec.describe Location, type: :model do it "does add an error when the postcode is invalid" do location.postcode = "invalid" - location.save! - expect(location.errors).not_to be_empty - expect(location.errors["postcode"]).to include(match I18n.t("validations.postcode")) + expect { location.save! } + .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Postcode Enter a postcode in the correct format, for example AA1 1AA") end end end