Create a gist now

Instantly share code, notes, and snippets.

BSON id parsing
require 'spec_helper'
def parse_id(id)
BSON::ObjectId(id)
rescue BSON::InvalidObjectId
nil
end
describe BSON do
describe 'when the id is a valid BSON id' do
it 'returns it' do
parse_id("SOME VALID BSON ID").must_be_kind_of BSON::ObjectId
end
end
describe 'otherwise' do
it 'returns nil' do
parse_id("aiejfioaej").must_be_nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment