Skip to content

Instantly share code, notes, and snippets.

@txus
Created September 6, 2011 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save txus/1196825 to your computer and use it in GitHub Desktop.
Save txus/1196825 to your computer and use it in GitHub Desktop.
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