Skip to content

Instantly share code, notes, and snippets.

@rx
Last active May 1, 2016 17:37
Show Gist options
  • Save rx/a4440130089bc64c1fcea99d43627155 to your computer and use it in GitHub Desktop.
Save rx/a4440130089bc64c1fcea99d43627155 to your computer and use it in GitHub Desktop.
Dry-Type UUID
UUID = Types::Strict::String.constrained(
format: /\A[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}\z/i)
describe UUID do
context 'UUID' do
include Voom::Types
let(:uuid){SecureRandom.uuid}
let(:bad_uuid){uuid+"&"}
it 'should constrain' do
expect{UUID['']}.to raise_error(Dry::Types::ConstraintError)
end
it 'should not constrain' do
expect(UUID[uuid]).to eq(uuid)
end
it 'should constrain on reg expression' do
expect{UUID[bad_uuid]}.to raise_error(Dry::Types::ConstraintError)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment