mock_redis 0.13.2 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/.travis.yml +3 -0
  4. data/CHANGELOG.md +10 -0
  5. data/Gemfile +0 -5
  6. data/README.md +2 -2
  7. data/lib/mock_redis.rb +1 -0
  8. data/lib/mock_redis/database.rb +11 -2
  9. data/lib/mock_redis/future.rb +22 -0
  10. data/lib/mock_redis/pipelined_wrapper.rb +0 -21
  11. data/lib/mock_redis/set_methods.rb +1 -0
  12. data/lib/mock_redis/string_methods.rb +13 -5
  13. data/lib/mock_redis/transaction_wrapper.rb +22 -8
  14. data/lib/mock_redis/version.rb +1 -1
  15. data/lib/mock_redis/zset_methods.rb +12 -9
  16. data/mock_redis.gemspec +2 -1
  17. data/spec/commands/connected_spec.rb +1 -1
  18. data/spec/commands/exists_spec.rb +2 -2
  19. data/spec/commands/expire_spec.rb +18 -2
  20. data/spec/commands/expireat_spec.rb +2 -2
  21. data/spec/commands/hexists_spec.rb +4 -4
  22. data/spec/commands/hsetnx_spec.rb +2 -2
  23. data/spec/commands/move_spec.rb +8 -8
  24. data/spec/commands/msetnx_spec.rb +2 -2
  25. data/spec/commands/persist_spec.rb +4 -4
  26. data/spec/commands/pexpire_spec.rb +2 -2
  27. data/spec/commands/pexpireat_spec.rb +2 -2
  28. data/spec/commands/renamenx_spec.rb +2 -2
  29. data/spec/commands/sadd_spec.rb +2 -2
  30. data/spec/commands/scan_spec.rb +51 -0
  31. data/spec/commands/set_spec.rb +6 -6
  32. data/spec/commands/setbit_spec.rb +7 -0
  33. data/spec/commands/setnx_spec.rb +2 -2
  34. data/spec/commands/sismember_spec.rb +5 -5
  35. data/spec/commands/smove_spec.rb +6 -6
  36. data/spec/commands/srem_spec.rb +3 -3
  37. data/spec/commands/sunion_spec.rb +4 -0
  38. data/spec/commands/zadd_spec.rb +2 -2
  39. data/spec/commands/zrange_spec.rb +1 -1
  40. data/spec/commands/zrangebyscore_spec.rb +1 -1
  41. data/spec/commands/zrem_spec.rb +3 -3
  42. data/spec/commands/zremrangebyscore_spec.rb +1 -0
  43. data/spec/commands/zrevrange_spec.rb +1 -1
  44. data/spec/commands/zrevrangebyscore_spec.rb +1 -1
  45. data/spec/commands/zscore_spec.rb +2 -2
  46. data/spec/spec_helper.rb +11 -2
  47. data/spec/support/redis_multiplexer.rb +6 -6
  48. data/spec/support/shared_examples/only_operates_on_hashes.rb +2 -2
  49. data/spec/support/shared_examples/only_operates_on_lists.rb +2 -2
  50. data/spec/support/shared_examples/only_operates_on_sets.rb +2 -2
  51. data/spec/support/shared_examples/only_operates_on_strings.rb +2 -2
  52. data/spec/support/shared_examples/only_operates_on_zsets.rb +4 -4
  53. data/spec/transactions_spec.rb +23 -0
  54. metadata +36 -18
@@ -9,11 +9,11 @@ describe "#zrem(key, member)" do
9
9
  end
10
10
 
11
11
  it "returns true if member is present in the set" do
12
- @redises.zrem(@key, 'one').should be_true
12
+ @redises.zrem(@key, 'one').should == true
13
13
  end
14
14
 
15
15
  it "returns false if member is not present in the set" do
16
- @redises.zrem(@key, 'nobody home').should be_false
16
+ @redises.zrem(@key, 'nobody home').should == false
17
17
  end
18
18
 
19
19
  it "removes member from the set" do
@@ -24,7 +24,7 @@ describe "#zrem(key, member)" do
24
24
  it "removes integer member from the set" do
25
25
  member = 11
26
26
  @redises.zadd(@key, 3, member)
27
- @redises.zrem(@key, member).should be_true
27
+ @redises.zrem(@key, member).should == true
28
28
  @redises.zrange(@key, 0, -1).should == ['one', 'two']
29
29
  end
30
30
 
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'date'
2
3
 
3
4
  describe "#zremrangebyscore(key, min, max)" do
4
5
  before do
@@ -15,7 +15,7 @@ describe "#zrevrange(key, start, stop [, :with_scores => true])" do
15
15
  end
16
16
 
17
17
  it 'should return an empty array' do
18
- @redises.exists(@key).should be_false
18
+ @redises.exists(@key).should == false
19
19
  @redises.zrevrange(@key, 0, 4).should == []
20
20
  end
21
21
  end
@@ -15,7 +15,7 @@ describe "#zrevrangebyscore(key, start, stop [:with_scores => true] [:limit => [
15
15
  end
16
16
 
17
17
  it 'should return an empty array' do
18
- @redises.exists(@key).should be_false
18
+ @redises.exists(@key).should == false
19
19
  @redises.zrevrangebyscore(@key, 0, 4).should == []
20
20
  end
21
21
  end
@@ -4,13 +4,13 @@ describe "#zscore(key, member)" do
4
4
  before { @key = 'mock-redis-test:zscore' }
5
5
 
6
6
  it "returns the score as a string" do
7
- @redises.zadd(@key, 0.25, 'foo').should be_true
7
+ @redises.zadd(@key, 0.25, 'foo').should == true
8
8
  @redises.zscore(@key, 'foo').should == 0.25
9
9
  end
10
10
 
11
11
  it "handles integer members correctly" do
12
12
  member = 11
13
- @redises.zadd(@key, 0.25, member).should be_true
13
+ @redises.zadd(@key, 0.25, member).should == true
14
14
  @redises.zscore(@key, member).should == 0.25
15
15
  end
16
16
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rspec'
2
+ require 'rspec/its'
2
3
  require 'redis'
3
4
  $LOAD_PATH.unshift(File.expand_path(File.join(__FILE__, "..", "..", "lib")))
4
5
  require 'mock_redis'
@@ -7,12 +8,12 @@ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..')))
7
8
  Dir["spec/support/**/*.rb"].each {|x| require x}
8
9
 
9
10
  module TypeCheckingHelper
10
- def method_from_description
11
+ def method_from_description(example)
11
12
  # extracting this from the RSpec description string may or may not
12
13
  # be a good idea. On the one hand, it enforces the convention of
13
14
  # putting the method name in the right place; on the other hand,
14
15
  # it's pretty magic-looking.
15
- self.example.full_description.match(/#(\w+)/).captures.first
16
+ example.full_description.match(/#(\w+)/).captures.first
16
17
  end
17
18
 
18
19
  def args_for_method(method)
@@ -26,6 +27,14 @@ module TypeCheckingHelper
26
27
  end
27
28
 
28
29
  RSpec.configure do |config|
30
+ config.expect_with :rspec do |c|
31
+ c.syntax = [:expect, :should]
32
+ end
33
+
34
+ config.mock_with :rspec do |c|
35
+ c.syntax = [:expect, :should]
36
+ end
37
+
29
38
  config.include(TypeCheckingHelper)
30
39
 
31
40
  config.before(:all) do
@@ -15,18 +15,18 @@ class RedisMultiplexer < BlankSlate
15
15
  # on the Redis implementation that the block came from.
16
16
  # e.g. if a pipelined command is started on a MockRedis object, DON'T send commands inside the pipelined block
17
17
  # to the real Redis object, as that one WON'T be inside a pipelined command, and we'll see weird behaviour
18
- if blk
19
- @in_mock_block = true
20
- @in_redis_block = false
21
- end
22
- mock_retval, mock_error = catch_errors { @in_redis_block ? :no_op : @mock_redis.send(method, *args, &blk) }
23
-
24
18
  if blk
25
19
  @in_mock_block = false
26
20
  @in_redis_block = true
27
21
  end
28
22
  real_retval, real_error = catch_errors { @in_mock_block ? :no_op : @real_redis.send(method, *args, &blk) }
29
23
 
24
+ if blk
25
+ @in_mock_block = true
26
+ @in_redis_block = false
27
+ end
28
+ mock_retval, mock_error = catch_errors { @in_redis_block ? :no_op : @mock_redis.send(method, *args, &blk) }
29
+
30
30
  if blk
31
31
  @in_mock_block = false
32
32
  @in_redis_block = false
@@ -1,8 +1,8 @@
1
1
  shared_examples_for "a hash-only command" do
2
- it "raises an error for non-hash values" do
2
+ it "raises an error for non-hash values" do |example|
3
3
  key = 'mock-redis-test:hash-only'
4
4
 
5
- method = method_from_description
5
+ method = method_from_description(example)
6
6
  args = args_for_method(method).unshift(key)
7
7
 
8
8
  @redises.set(key, 1)
@@ -1,8 +1,8 @@
1
1
  shared_examples_for "a list-only command" do
2
- it "raises an error for non-list values" do
2
+ it "raises an error for non-list values" do |example|
3
3
  key = 'mock-redis-test:list-only'
4
4
 
5
- method = method_from_description
5
+ method = method_from_description(example)
6
6
  args = args_for_method(method).unshift(key)
7
7
 
8
8
  @redises.set(key, 1)
@@ -1,8 +1,8 @@
1
1
  shared_examples_for "a set-only command" do
2
- it "raises an error for non-set values" do
2
+ it "raises an error for non-set values" do |example|
3
3
  key = 'mock-redis-test:set-only'
4
4
 
5
- method = method_from_description
5
+ method = method_from_description(example)
6
6
  args = args_for_method(method).unshift(key)
7
7
 
8
8
  @redises.set(key, 1)
@@ -1,8 +1,8 @@
1
1
  shared_examples_for "a string-only command" do
2
- it "raises an error for non-string values" do
2
+ it "raises an error for non-string values" do |example|
3
3
  key = "mock-redis-test:string-only-command"
4
4
 
5
- method = method_from_description
5
+ method = method_from_description(example)
6
6
  args = args_for_method(method).unshift(key)
7
7
 
8
8
  @redises.lpush(key, 1)
@@ -1,8 +1,8 @@
1
1
  shared_examples_for "a zset-only command" do
2
- it "raises an error for non-zset values" do
2
+ it "raises an error for non-zset values" do |example|
3
3
  key = 'mock-redis-test:zset-only'
4
4
 
5
- method = method_from_description
5
+ method = method_from_description(example)
6
6
  args = args_for_method(method).unshift(key)
7
7
 
8
8
  @redises.set(key, 1)
@@ -23,10 +23,10 @@ shared_examples_for "arg 2 is a score" do
23
23
  end
24
24
 
25
25
  shared_examples_for "arg N is a score" do
26
- before do
26
+ before do |example|
27
27
  key = 'mock-redis-test:zset-only'
28
28
 
29
- @method = method_from_description
29
+ @method = method_from_description(example)
30
30
  @args = args_for_method(@method).unshift(key)
31
31
  end
32
32
 
@@ -109,4 +109,27 @@ describe 'transactions (multi/exec/discard)' do
109
109
  responses[2].should == 1
110
110
  end
111
111
  end
112
+
113
+ context "saving commands with multi block" do
114
+ before(:each) do
115
+ @string = 'mock-redis-test:string'
116
+ @list = 'mock-redis-test:list'
117
+ end
118
+
119
+ it "commands return response after exec is called" do
120
+ set_response = nil
121
+ lpush_response = nil
122
+ second_lpush_response = nil
123
+
124
+ @redises.multi do |mult|
125
+ set_response = mult.set(@string, 'string')
126
+ lpush_response = mult.lpush(@list, 'list')
127
+ second_lpush_response = mult.lpush(@list, 'list')
128
+ end
129
+
130
+ set_response.value.should == 'OK'
131
+ lpush_response.value.should == 1
132
+ second_lpush_response.value.should == 2
133
+ end
134
+ end
112
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Causes Engineering
@@ -9,50 +9,64 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-09 00:00:00.000000000 Z
12
+ date: 2014-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '10.0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '10.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: redis
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
34
  version: 3.0.0
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ~>
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: 3.0.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 2.14.0
48
+ version: 3.1.0
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 2.14.0
55
+ version: 3.1.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-its
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.0'
56
70
  description: Instantiate one with `redis = MockRedis.new` and treat it like you would
57
71
  a normal Redis object. It supports all the usual Redis operations.
58
72
  email:
@@ -61,11 +75,11 @@ executables: []
61
75
  extensions: []
62
76
  extra_rdoc_files: []
63
77
  files:
64
- - .gitignore
65
- - .mailmap
66
- - .overcommit.yml
67
- - .rspec
68
- - .travis.yml
78
+ - ".gitignore"
79
+ - ".mailmap"
80
+ - ".overcommit.yml"
81
+ - ".rspec"
82
+ - ".travis.yml"
69
83
  - CHANGELOG.md
70
84
  - Gemfile
71
85
  - LICENSE
@@ -76,6 +90,7 @@ files:
76
90
  - lib/mock_redis/database.rb
77
91
  - lib/mock_redis/exceptions.rb
78
92
  - lib/mock_redis/expire_wrapper.rb
93
+ - lib/mock_redis/future.rb
79
94
  - lib/mock_redis/hash_methods.rb
80
95
  - lib/mock_redis/indifferent_hash.rb
81
96
  - lib/mock_redis/info_method.rb
@@ -174,6 +189,7 @@ files:
174
189
  - spec/commands/rpushx_spec.rb
175
190
  - spec/commands/sadd_spec.rb
176
191
  - spec/commands/save_spec.rb
192
+ - spec/commands/scan_spec.rb
177
193
  - spec/commands/scard_spec.rb
178
194
  - spec/commands/sdiff_spec.rb
179
195
  - spec/commands/sdiffstore_spec.rb
@@ -237,17 +253,17 @@ require_paths:
237
253
  - lib
238
254
  required_ruby_version: !ruby/object:Gem::Requirement
239
255
  requirements:
240
- - - '>='
256
+ - - ">="
241
257
  - !ruby/object:Gem::Version
242
258
  version: '0'
243
259
  required_rubygems_version: !ruby/object:Gem::Requirement
244
260
  requirements:
245
- - - '>='
261
+ - - ">="
246
262
  - !ruby/object:Gem::Version
247
263
  version: '0'
248
264
  requirements: []
249
265
  rubyforge_project:
250
- rubygems_version: 2.0.14
266
+ rubygems_version: 2.2.2
251
267
  signing_key:
252
268
  specification_version: 4
253
269
  summary: Redis mock that just lives in memory; useful for testing.
@@ -334,6 +350,7 @@ test_files:
334
350
  - spec/commands/rpushx_spec.rb
335
351
  - spec/commands/sadd_spec.rb
336
352
  - spec/commands/save_spec.rb
353
+ - spec/commands/scan_spec.rb
337
354
  - spec/commands/scard_spec.rb
338
355
  - spec/commands/sdiff_spec.rb
339
356
  - spec/commands/sdiffstore_spec.rb
@@ -387,3 +404,4 @@ test_files:
387
404
  - spec/support/shared_examples/only_operates_on_zsets.rb
388
405
  - spec/support/shared_examples/sorts_enumerables.rb
389
406
  - spec/transactions_spec.rb
407
+ has_rdoc: