kuende-fakeredis 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +19 -0
  4. data/Gemfile +13 -0
  5. data/Guardfile +8 -0
  6. data/LICENSE +21 -0
  7. data/README.md +102 -0
  8. data/Rakefile +27 -0
  9. data/fakeredis.gemspec +24 -0
  10. data/gemfiles/redisrb-master.gemfile +14 -0
  11. data/lib/fake_redis.rb +1 -0
  12. data/lib/fakeredis.rb +6 -0
  13. data/lib/fakeredis/bitop_command.rb +56 -0
  14. data/lib/fakeredis/command_executor.rb +25 -0
  15. data/lib/fakeredis/expiring_hash.rb +70 -0
  16. data/lib/fakeredis/minitest.rb +24 -0
  17. data/lib/fakeredis/rspec.rb +24 -0
  18. data/lib/fakeredis/sort_method.rb +117 -0
  19. data/lib/fakeredis/sorted_set_argument_handler.rb +74 -0
  20. data/lib/fakeredis/sorted_set_store.rb +80 -0
  21. data/lib/fakeredis/transaction_commands.rb +83 -0
  22. data/lib/fakeredis/version.rb +3 -0
  23. data/lib/fakeredis/zset.rb +39 -0
  24. data/lib/redis/connection/memory.rb +1375 -0
  25. data/spec/bitop_command_spec.rb +209 -0
  26. data/spec/compatibility_spec.rb +9 -0
  27. data/spec/connection_spec.rb +85 -0
  28. data/spec/hashes_spec.rb +261 -0
  29. data/spec/keys_spec.rb +488 -0
  30. data/spec/lists_spec.rb +229 -0
  31. data/spec/memory_spec.rb +28 -0
  32. data/spec/server_spec.rb +100 -0
  33. data/spec/sets_spec.rb +280 -0
  34. data/spec/sort_method_spec.rb +74 -0
  35. data/spec/sorted_sets_spec.rb +578 -0
  36. data/spec/spec_helper.rb +29 -0
  37. data/spec/spec_helper_live_redis.rb +14 -0
  38. data/spec/strings_spec.rb +289 -0
  39. data/spec/subscription_spec.rb +107 -0
  40. data/spec/support/shared_examples/bitwise_operation.rb +59 -0
  41. data/spec/support/shared_examples/sortable.rb +69 -0
  42. data/spec/transactions_spec.rb +92 -0
  43. data/spec/upcase_method_name_spec.rb +18 -0
  44. metadata +148 -0
@@ -0,0 +1,69 @@
1
+ shared_examples_for "a sortable" do
2
+ it 'returns empty array on nil' do
3
+ expect(@client.sort(nil)).to eq([])
4
+ end
5
+
6
+ context 'ordering' do
7
+ it 'orders ascending by default' do
8
+ expect(@client.sort(@key)).to eq(['1', '2'])
9
+ end
10
+
11
+ it 'orders by ascending when specified' do
12
+ expect(@client.sort(@key, :order => "ASC")).to eq(['1', '2'])
13
+ end
14
+
15
+ it 'orders by descending when specified' do
16
+ expect(@client.sort(@key, :order => "DESC")).to eq(['2', '1'])
17
+ end
18
+
19
+ it "orders by ascending when alpha is specified" do
20
+ expect(@client.sort(@key, :order => "ALPHA")).to eq(["1", "2"])
21
+ end
22
+ end
23
+
24
+ context 'projections' do
25
+ it 'projects element when :get is "#"' do
26
+ expect(@client.sort(@key, :get => '#')).to eq(['1', '2'])
27
+ end
28
+
29
+ it 'projects through a key pattern' do
30
+ expect(@client.sort(@key, :get => 'fake-redis-test:values_*')).to eq(['a', 'b'])
31
+ end
32
+
33
+ it 'projects through a key pattern and reflects element' do
34
+ expect(@client.sort(@key, :get => ['#', 'fake-redis-test:values_*'])).to eq([['1', 'a'], ['2', 'b']])
35
+ end
36
+
37
+ it 'projects through a hash key pattern' do
38
+ expect(@client.sort(@key, :get => 'fake-redis-test:hash_*->key')).to eq(['x', 'y'])
39
+ end
40
+ end
41
+
42
+ context 'weights' do
43
+ it 'weights by projecting through a key pattern' do
44
+ expect(@client.sort(@key, :by => "fake-redis-test:weight_*")).to eq(['2', '1'])
45
+ end
46
+
47
+ it 'weights by projecting through a key pattern and a specific order' do
48
+ expect(@client.sort(@key, :order => "DESC", :by => "fake-redis-test:weight_*")).to eq(['1', '2'])
49
+ end
50
+ end
51
+
52
+ context 'limit' do
53
+ it 'only returns requested window in the enumerable' do
54
+ expect(@client.sort(@key, :limit => [0, 1])).to eq(['1'])
55
+ end
56
+ end
57
+
58
+ context 'store' do
59
+ it 'stores into another key' do
60
+ expect(@client.sort(@key, :store => "fake-redis-test:some_bucket")).to eq(2)
61
+ expect(@client.lrange("fake-redis-test:some_bucket", 0, -1)).to eq(['1', '2'])
62
+ end
63
+
64
+ it "stores into another key with other options specified" do
65
+ expect(@client.sort(@key, :store => "fake-redis-test:some_bucket", :by => "fake-redis-test:weight_*")).to eq(2)
66
+ expect(@client.lrange("fake-redis-test:some_bucket", 0, -1)).to eq(['2', '1'])
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ module FakeRedis
4
+ describe "TransactionsMethods" do
5
+ before(:all) do
6
+ @client = Redis.new
7
+ end
8
+
9
+ before(:each) do
10
+ @client.discard rescue nil
11
+ end
12
+
13
+ context '#multi' do
14
+ it "should respond with 'OK'" do
15
+ expect(@client.multi).to eq('OK')
16
+ end
17
+
18
+ it "should forbid nesting" do
19
+ @client.multi
20
+ expect{@client.multi}.to raise_error(Redis::CommandError)
21
+ end
22
+
23
+ it "should mark the start of a transaction block" do
24
+ transaction = @client.multi do |multi|
25
+ multi.set("key1", "1")
26
+ multi.set("key2", "2")
27
+ multi.expire("key1", 123)
28
+ multi.mget("key1", "key2")
29
+ end
30
+
31
+ expect(transaction).to eq(["OK", "OK", true, ["1", "2"]])
32
+ end
33
+ end
34
+
35
+ context '#discard' do
36
+ it "should responde with 'OK' after #multi" do
37
+ @client.multi
38
+ expect(@client.discard).to eq('OK')
39
+ end
40
+
41
+ it "can't be run outside of #multi/#exec" do
42
+ expect{@client.discard}.to raise_error(Redis::CommandError)
43
+ end
44
+ end
45
+
46
+ context '#exec' do
47
+ it "can't be run outside of #multi" do
48
+ expect{@client.exec}.to raise_error(Redis::CommandError)
49
+ end
50
+ end
51
+
52
+ context 'saving up commands for later' do
53
+ before(:each) do
54
+ @client.multi
55
+ @string = 'fake-redis-test:string'
56
+ @list = 'fake-redis-test:list'
57
+ end
58
+
59
+ it "makes commands respond with 'QUEUED'" do
60
+ expect(@client.set(@string, 'string')).to eq('QUEUED')
61
+ expect(@client.lpush(@list, 'list')).to eq('QUEUED')
62
+ end
63
+
64
+ it "gives you the commands' responses when you call #exec" do
65
+ @client.set(@string, 'string')
66
+ @client.lpush(@list, 'list')
67
+ @client.lpush(@list, 'list')
68
+
69
+ expect(@client.exec).to eq(['OK', 1, 2])
70
+ end
71
+
72
+ it "does not raise exceptions, but rather puts them in #exec's response" do
73
+ @client.set(@string, 'string')
74
+ @client.lpush(@string, 'oops!')
75
+ @client.lpush(@list, 'list')
76
+
77
+ responses = @client.exec
78
+ expect(responses[0]).to eq('OK')
79
+ expect(responses[1]).to be_a(RuntimeError)
80
+ expect(responses[2]).to eq(1)
81
+ end
82
+ end
83
+
84
+ context 'executing hash commands in a block' do
85
+ it "returns true if the nested hash command succeeds" do
86
+ responses = @client.multi { |multi| multi.hset('hash', 'key', 'value') }
87
+
88
+ expect(responses[0]).to eq(true)
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ module FakeRedis
4
+ describe "UPCASE method name will call downcase method" do
5
+
6
+ before do
7
+ @client = Redis.new
8
+ end
9
+
10
+ it "#ZCOUNT" do
11
+ expect(@client.ZCOUNT("key", 2, 3)).to eq(@client.zcount("key", 2, 3))
12
+ end
13
+
14
+ it "#ZSCORE" do
15
+ expect(@client.ZSCORE("key", 2)).to eq(@client.zscore("key", 2))
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kuende-fakeredis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Guillermo Iguaran
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Fake (In-memory) driver for redis-rb. Useful for testing environment
56
+ and machines without Redis.
57
+ email:
58
+ - guilleiguaran@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Guardfile
67
+ - LICENSE
68
+ - README.md
69
+ - Rakefile
70
+ - fakeredis.gemspec
71
+ - gemfiles/redisrb-master.gemfile
72
+ - lib/fake_redis.rb
73
+ - lib/fakeredis.rb
74
+ - lib/fakeredis/bitop_command.rb
75
+ - lib/fakeredis/command_executor.rb
76
+ - lib/fakeredis/expiring_hash.rb
77
+ - lib/fakeredis/minitest.rb
78
+ - lib/fakeredis/rspec.rb
79
+ - lib/fakeredis/sort_method.rb
80
+ - lib/fakeredis/sorted_set_argument_handler.rb
81
+ - lib/fakeredis/sorted_set_store.rb
82
+ - lib/fakeredis/transaction_commands.rb
83
+ - lib/fakeredis/version.rb
84
+ - lib/fakeredis/zset.rb
85
+ - lib/redis/connection/memory.rb
86
+ - spec/bitop_command_spec.rb
87
+ - spec/compatibility_spec.rb
88
+ - spec/connection_spec.rb
89
+ - spec/hashes_spec.rb
90
+ - spec/keys_spec.rb
91
+ - spec/lists_spec.rb
92
+ - spec/memory_spec.rb
93
+ - spec/server_spec.rb
94
+ - spec/sets_spec.rb
95
+ - spec/sort_method_spec.rb
96
+ - spec/sorted_sets_spec.rb
97
+ - spec/spec_helper.rb
98
+ - spec/spec_helper_live_redis.rb
99
+ - spec/strings_spec.rb
100
+ - spec/subscription_spec.rb
101
+ - spec/support/shared_examples/bitwise_operation.rb
102
+ - spec/support/shared_examples/sortable.rb
103
+ - spec/transactions_spec.rb
104
+ - spec/upcase_method_name_spec.rb
105
+ homepage: https://guilleiguaran.github.com/fakeredis
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.5
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Fake (In-memory) driver for redis-rb.
129
+ test_files:
130
+ - spec/bitop_command_spec.rb
131
+ - spec/compatibility_spec.rb
132
+ - spec/connection_spec.rb
133
+ - spec/hashes_spec.rb
134
+ - spec/keys_spec.rb
135
+ - spec/lists_spec.rb
136
+ - spec/memory_spec.rb
137
+ - spec/server_spec.rb
138
+ - spec/sets_spec.rb
139
+ - spec/sort_method_spec.rb
140
+ - spec/sorted_sets_spec.rb
141
+ - spec/spec_helper.rb
142
+ - spec/spec_helper_live_redis.rb
143
+ - spec/strings_spec.rb
144
+ - spec/subscription_spec.rb
145
+ - spec/support/shared_examples/bitwise_operation.rb
146
+ - spec/support/shared_examples/sortable.rb
147
+ - spec/transactions_spec.rb
148
+ - spec/upcase_method_name_spec.rb