diff --git a/config/errors.yml b/config/errors.yml index 65f88e9c..95afc96f 100644 --- a/config/errors.yml +++ b/config/errors.yml @@ -107,5 +107,7 @@ en: uuid_v4?: "is not a valid UUID" + uri?: "is not a valid URI" + not: empty?: "cannot be empty" diff --git a/spec/integration/params/predicates/uri_spec.rb b/spec/integration/params/predicates/uri_spec.rb new file mode 100644 index 00000000..9e5fce76 --- /dev/null +++ b/spec/integration/params/predicates/uri_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.describe "Predicates: uri?" do + subject(:schema) do + Dry::Schema.Params do + required(:uri) { str? & uri?(:https) } + end + end + + it "passes with valid input" do + expect(schema.(uri: "https://www.example.com")).to be_success + end + + it "fails with invalid input" do + expect(schema.(uri: "not-a-uri").errors.to_h).to eql(uri: ["is not a valid URI"]) + end +end