From 0b74127cc530e2aaadb17a61b3a9d3c9c0b82547 Mon Sep 17 00:00:00 2001 From: pezholio Date: Mon, 24 Jun 2024 09:40:00 +0100 Subject: [PATCH] Add more helpful error if the format is not found --- lib/govuk_schemas/random_content_generator.rb | 12 +++++++++++- spec/lib/random_content_generator_spec.rb | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/govuk_schemas/random_content_generator.rb b/lib/govuk_schemas/random_content_generator.rb index 621f179..ef318cb 100644 --- a/lib/govuk_schemas/random_content_generator.rb +++ b/lib/govuk_schemas/random_content_generator.rb @@ -18,7 +18,17 @@ def string_for_type(type) when "email" Faker::Internet.email else - raise "Unknown attribute type `#{type}`" + raise <<~DOC + Unsupported JSON schema type `#{type}` + + Supported formats are: + - date-time + - uri + - email + + This can be fixed by adding a type to the `string_for_type` method in + `lib/govuk_schemas/random_content_generator.rb` in https://github.com/alphagov/govuk_schemas + DOC end end diff --git a/spec/lib/random_content_generator_spec.rb b/spec/lib/random_content_generator_spec.rb index 1448fde..cde68ce 100644 --- a/spec/lib/random_content_generator_spec.rb +++ b/spec/lib/random_content_generator_spec.rb @@ -18,6 +18,12 @@ expect(response).to eq(email) end + + it "raises an error if the type is not present" do + expect { + GovukSchemas::RandomContentGenerator.new.string_for_type("duration") + }.to raise_error(/Unsupported JSON schema type `duration`/) + end end describe ".uri" do