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