Skip to content

Instantly share code, notes, and snippets.

@jballanc
Created November 8, 2012 22:54
Show Gist options
  • Save jballanc/4042404 to your computer and use it in GitHub Desktop.
Save jballanc/4042404 to your computer and use it in GitHub Desktop.
###
#
# This is a dirty, dirty trick to write tests that test `require`:
#
module RequireMock
REQUIRE_SENTINEL = []
def require(lib)
REQUIRE_SENTINEL << lib
super
end
end
Object.send(:include, RequireMock)
def require_lib(lib)
->(block) do
REQUIRE_SENTINEL.clear
block.call
REQUIRE_SENTINEL.include?(lib)
end
end
# ...
describe Peacekeeper::Model do
# ...
describe 'manages a data source selection' do
it 'is nil by default' do
Peacekeeper::Model.data_source.should.be.nil
end
describe 'set to Sequel' do
it 'requires the Sequel library' do
-> { Peacekeeper::Model.data_source = :sequel }.should require_lib('sequel')
end
# ...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment