Last active
May 1, 2016 17:37
-
-
Save rx/a4440130089bc64c1fcea99d43627155 to your computer and use it in GitHub Desktop.
Dry-Type UUID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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