Skip to content
Browse files

initial tests and functionality

  • Loading branch information...
0 parents commit 6378456b5aaf59cce6b6f8ce1d5c924ddfba82c6 Karl committed May 18, 2011
Showing with 111 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +1 −0 .rvmrc
  3. +4 −0 Gemfile
  4. +11 −0 Rakefile
  5. +23 −0 lib/simple_redis_cache.rb
  6. +3 −0 lib/simple_redis_cache/version.rb
  7. +23 −0 simple_redis_cache.gemspec
  8. +31 −0 test/simple_redis_cache_test.rb
  9. +11 −0 test/test_helper.rb
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
1 .rvmrc
@@ -0,0 +1 @@
+rvm ruby-1.9.2@simple_redis_cache
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in simple_redis_cache.gemspec
+gemspec
11 Rakefile
@@ -0,0 +1,11 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+require File.dirname(__FILE__) + '/lib/simple_redis_cache'
+
+require 'rake/testtask'
+
+Rake::TestTask.new do |t|
+ t.pattern = "test/*_test.rb"
+end
+
23 lib/simple_redis_cache.rb
@@ -0,0 +1,23 @@
+require 'redis'
+
+module SimpleRedisCache
+
+ def redis=(redis)
+ @redis = redis
+ end
+
+ def redis
+ @redis ||= Redis.new
+ end
+
+ def cache(*args, &block)
+ redis[args.first]=(block ? block.call : args.last)
+ end
+
+ def get(key)
+ redis[key]
+ end
+
+
+
+end
3 lib/simple_redis_cache/version.rb
@@ -0,0 +1,3 @@
+module SimpleRedisCache
+ VERSION = "0.0.1"
+end
23 simple_redis_cache.gemspec
@@ -0,0 +1,23 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "simple_redis_cache/version"
+
+Gem::Specification.new do |s|
+ s.name = "simple_redis_cache"
+ s.version = SimpleRedisCache::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["TODO: Write your name"]
+ s.email = ["TODO: Write your email address"]
+ s.homepage = ""
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.rubyforge_project = "simple_redis_cache"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+ s.add_dependency('redis')
+ s.add_development_dependency('ruby-debug19')
+end
31 test/simple_redis_cache_test.rb
@@ -0,0 +1,31 @@
+require File.dirname(File.expand_path(__FILE__)) + '/test_helper'
+
+class SimpleRedisCacheTest < Test::Unit::TestCase
+
+ include SimpleRedisCache
+
+ # Called before every test method runs. Can be used
+ # to set up fixture information.
+ def setup
+ redis.flushdb
+ end
+
+ # Called after every test method runs. Can be used to tear
+ # down fixture information.
+
+ def teardown
+ # Do nothing
+ end
+
+ def test_cache_object
+ cache('hello', 'world')
+ assert_equal(get('hello'), 'world')
+ end
+
+ def test_cache_block
+ cache('hello'){ 'world' }
+ assert_equal(get('hello'), 'world')
+ end
+
+
+end
11 test/test_helper.rb
@@ -0,0 +1,11 @@
+dir = File.dirname(File.expand_path(__FILE__))
+$LOAD_PATH.unshift dir + '/../lib'
+
+require 'test/unit'
+require 'rubygems'
+require 'bundler'
+
+Bundler.require
+
+require 'simple_redis_cache'
+require 'ruby-debug'

0 comments on commit 6378456

Please sign in to comment.
Something went wrong with that request. Please try again.