Skip to content

Instantly share code, notes, and snippets.

@craigw
Forked from rlivsey/something.rb
Created March 2, 2010 23:25
Show Gist options
  • Save craigw/320096 to your computer and use it in GitHub Desktop.
Save craigw/320096 to your computer and use it in GitHub Desktop.
# how to test that this works?
# or would you even bother?
...
begin
require 'system_timer'
rescue LoadError
require 'timeout'
SystemTimer = Timeout
end
...
before(:all) do
Object.remove_const(SystemTimer)
end
after(:each) do
Object.remove_const(SystemTimer)
end
after(:all) do
load "something"
end
it "should require 'system_timer'" do
Object.expects(:require).once.with('system_timer')
load "something"
end
it "should use Timer as SystemTimer if system_timer could not be loaded"
def Object.require # you should alias the old one first so you can alias it back later.
raise LoadError, "..."
end
load "something"
Time.should eql(SystemTimer)
end
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rubygems'
require 'spec'
require 'webmock/rspec'
require 'something' # <--- it's already loaded here
require 'faker'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment