Skip to content

Instantly share code, notes, and snippets.

@xaviershay
Created September 27, 2010 16:38
Show Gist options
  • Select an option

  • Save xaviershay/599327 to your computer and use it in GitHub Desktop.

Select an option

Save xaviershay/599327 to your computer and use it in GitHub Desktop.
# Need a method that works regardless of whether active_support/core_ext is loaded or not
def today
(Time.respond_to?(:zone) && Time.zone) ?
Time.zone.today :
Date.today
end
describe 'timezone support' do
before :all do
Time.extend(MethodVisibility)
end
it 'should fallback to standard ruby date if Time.zone is not available' do
Time.hide_class_method(:zone) do
today.should == date(:today)
end
end
end
module MethodVisibility
def hide_class_method(method)
metaclass = (class << self; self; end)
metaclass.send :alias_method, :old_method, method
metaclass.send :remove_method, method
begin
yield
ensure
metaclass.send :alias_method, method, :old_method
metaclass.send :remove_method, :old_method
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment