memcache_mock 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/.rvmrc.example ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@memcache_mock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # Memcache Mock
2
+
3
+ Simple library to mock a **key/value** storage system.
4
+
5
+ The _API_ is based in the **Dalli Memcache Ruby Client**.
6
+
7
+ ## Use
8
+ gem install memcache_mock
9
+ cache = MemcacheMock.new
10
+ cache.set( "key", "value" )
11
+ cache.get( "key" ) # => "value"
12
+
13
+ ## Status
14
+
15
+ The actual status is **Beta** and the _API_ only support the methods we have needed so far.
16
+
17
+ If you have any suggestion we'll appreciate _pull requests_.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # require 'bundler/gem_tasks'
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'bundler'
6
+
7
+ include Rake::DSL
8
+
9
+ Bundler::GemHelper.install_tasks
10
+
11
+ task :default => :test
12
+
13
+ Rake::TestTask.new do |t|
14
+ t.libs << '.'
15
+ t.test_files = FileList['test/*_test.rb']
16
+ t.verbose = true
17
+ end
18
+
@@ -0,0 +1,41 @@
1
+ require "memcache_mock/version"
2
+
3
+ class MemcacheMock
4
+ def initialize( )
5
+ @values = {}
6
+ end
7
+
8
+ def incr( key, value, ttl, default_value )
9
+ if @values[key]
10
+ append( key, value )
11
+ else
12
+ @values[key] = default_value
13
+ end
14
+ end
15
+
16
+ def get( key )
17
+ @values[key] ? @values[key].to_s : nil
18
+ end
19
+
20
+ def get_multi( keys )
21
+ @values.select { |k, v| keys.include?( k ) }
22
+ end
23
+
24
+ def set( key, value, ttl = nil, options = {} )
25
+ @values[key] = value
26
+ end
27
+
28
+ def update( key, default, ttl = nil, options = nil )
29
+ @values[key] = yield( @values[key] || default )
30
+ end
31
+
32
+ def append( key, value )
33
+ if @values[key]
34
+ @values[key] += value
35
+ end
36
+ end
37
+
38
+ def flush
39
+ @values.clear
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ class MemcacheMock
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "memcache_mock/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "memcache_mock"
7
+ s.version = MemcacheMock::VERSION
8
+ s.authors = ["Fernando Guillen"]
9
+ s.email = ["fguillen.mail@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = "Simple key/value mocked storage system"
12
+ s.description = "Simple key/value mocked storage system"
13
+
14
+ s.rubyforge_project = "memcache_mock"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "bundler", "1.0.21"
22
+ s.add_development_dependency "rake", "0.9.2.2"
23
+ s.add_development_dependency "mocha", "0.10.0"
24
+ end
@@ -0,0 +1,63 @@
1
+ require_relative "test_helper"
2
+
3
+ class MemcacheMockTest < Test::Unit::TestCase
4
+ def setup
5
+ @cache = MemcacheMock.new
6
+ end
7
+
8
+ def test_initialize
9
+ assert( @cache.is_a? MemcacheMock )
10
+ assert_equal( {}, @cache.instance_variable_get( :@values ) )
11
+ end
12
+
13
+ def test_incr_when_key_not_exists
14
+ @cache.incr( "key", "value", nil, "default_value" )
15
+ assert_equal( "default_value", @cache.get( "key" ))
16
+ end
17
+
18
+ def test_incr
19
+ @cache.set( "key", "original_value" )
20
+ @cache.expects( :append ).with( "key", "value" )
21
+
22
+ @cache.incr( "key", "value", nil, nil )
23
+ end
24
+
25
+ def test_get_when_key_not_exists
26
+ assert_equal( nil, @cache.get( "key" ) )
27
+ end
28
+
29
+ def test_get
30
+ @cache.set( "key", "value" )
31
+ assert_equal( "value", @cache.get( "key" ) )
32
+ end
33
+
34
+ def test_get_multi
35
+ @cache.set( "key1", "value1" )
36
+ @cache.set( "key2", "value2" )
37
+ @cache.set( "key3", "value3" )
38
+
39
+ result = @cache.get_multi( ["key1", "key2", "key3", "key4" ] )
40
+
41
+ assert_equal( "value1", result["key1"] )
42
+ assert_equal( "value3", result["key3"] )
43
+ assert_equal( nil, result["key4"] )
44
+ end
45
+
46
+ def test_set
47
+ @cache.set( "key", "value" )
48
+ assert_equal( "value", @cache.get( "key" ) )
49
+ end
50
+
51
+ def test_append
52
+ @cache.set( "key", "value1" )
53
+ @cache.append( "key", "|value2" )
54
+
55
+ assert_equal( "value1|value2", @cache.get( "key" ) )
56
+ end
57
+
58
+ def test_flush
59
+ @cache.set( "key", "value1" )
60
+ @cache.flush
61
+ assert_equal( nil, @cache.get( "key" ) )
62
+ end
63
+ end
@@ -0,0 +1,4 @@
1
+ require "test/unit"
2
+ require "mocha"
3
+
4
+ require_relative "../lib/memcache_mock.rb"
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memcache_mock
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Fernando Guillen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-01-20 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.21
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.9.2.2
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: mocha
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - "="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.10.0
46
+ type: :development
47
+ version_requirements: *id003
48
+ description: Simple key/value mocked storage system
49
+ email:
50
+ - fguillen.mail@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - .rvmrc.example
60
+ - Gemfile
61
+ - README.md
62
+ - Rakefile
63
+ - lib/memcache_mock.rb
64
+ - lib/memcache_mock/version.rb
65
+ - memcache_mock.gemspec
66
+ - test/memcache_mock_test.rb
67
+ - test/test_helper.rb
68
+ homepage: ""
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project: memcache_mock
91
+ rubygems_version: 1.8.15
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Simple key/value mocked storage system
95
+ test_files:
96
+ - test/memcache_mock_test.rb
97
+ - test/test_helper.rb