Created
November 8, 2012 22:54
-
-
Save jballanc/4042404 to your computer and use it in GitHub Desktop.
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
### | |
# | |
# 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