Permalink
Browse files

starting new spec

git-svn-id: http://svn.verbdev.com/rb/caches.rb/trunk@90 f28541f9-331e-0410-82d8-e175c77b79a1
  • Loading branch information...
yrashk
yrashk committed Apr 19, 2007
1 parent 3f618cb commit 52431e3fdca11823b3ec010d280aa882e8cdf97c
Showing with 48 additions and 4 deletions.
  1. +4 −4 lib/caches.rb
  2. +44 −0 spec/caches_rb_spec.rb
View
@@ -134,15 +134,15 @@ def caches(name,options = {})
include Storage::Instance unless protected_method_defined?(:cachesrb_cache)
public
-
+
def self.remove_methods_on_reset?
false
end
def self.remove_variables_on_reset?
false
end
-
+
def invalidate_all_caches(*opts)
unless opts.empty?
@@ -200,11 +200,11 @@ class <<self
def remove_methods_on_reset?
false
end
-
+
def remove_variables_on_reset?
false
end
-
+
extend ::Caches
end
end
View
@@ -0,0 +1,44 @@
+require File.dirname(__FILE__) + '/../lib/caches'
+
+require 'rubygems'
+gem 'activesupport'
+require 'active_support'
+
+context "Fake class extended by Caches" do
+
+ setup do
+ @fake = Class.new
+ @fake.class_eval do
+ extend Caches
+ end
+ end
+
+ specify "should respond to caches" do
+ @fake.should respond_to(:caches)
+ end
+
+ specify "should cache for 1 minute by default" do
+ cached_time_check
+ end
+
+ specify "should work with specified timeout" do
+ [100,101,120].each { |timeout| cached_time_check :timeout => timeout }
+ end
+
+ def cached_time_check(opts={})
+ timeout = opts[:timeout] || 60
+ @fake.class_eval do
+ def test_method
+ Time.now
+ end
+ end
+ @fake.caches(:test_method, opts)
+ fake_instance = @fake.new
+ old_time = fake_instance.test_method
+ Time.stub!(:now).and_return old_time + timeout
+ fake_instance.test_method.should == old_time
+ Time.stub!(:now).and_return old_time + timeout + 1
+ fake_instance.test_method.should_not == old_time
+ end
+
+end

0 comments on commit 52431e3

Please sign in to comment.