hella-redis 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- data.tar.gz: d5d4a583bea7f4eb74d904bddce9474a5c218dcc
4
- metadata.gz: 6d10bd47816a27aa7924ac5cecdb22df2659423a
5
2
  SHA512:
6
- data.tar.gz: 2986489323f0237fe4f4b001b74df13962744630892d14b4135ae316cfca3b8eb2c258c372db76aded8e7fd40c626155239d3d5d97e77957b4fac6010fd7dabf
7
- metadata.gz: ada755c656466edf8b8a93837b9883e3fc5dbb597169820c7e126361a38e44ebba6670cba18e3c19dccfecec4986863b413540e09f8ad6b7c1c7b8122f9d1318
3
+ data.tar.gz: 6b2cc12d83fbb6e7b9729c89a60bb39c583bcd52543f1f1d77b3c39c05c1c58f5faac2de941ae34d4d47b22ebfff5eb7bf2847fb3d1580609283c333a4332384
4
+ metadata.gz: 570acf22296c63f86218648a9e02c9c8d11d34eeba378e86ea5014e3ea21ca6e26390d7edd3f849ab345fb17d5a8fe9696ba5411412b54d5e2da505134223ce5
5
+ SHA1:
6
+ data.tar.gz: a42078e26d25b13db394f27b31e44f41a2b4fba6
7
+ metadata.gz: 4c3dd50a8c11051d7c263d9eab72f7b48c47ded5
data/README.md CHANGED
@@ -2,24 +2,55 @@
2
2
 
3
3
  It's-a hella-redis!
4
4
 
5
- ## Usage
5
+ This gem is a wrapper that builds a connection pool of redis connections. It also provides spies and test mode behavior to ease testing redis interactions.
6
6
 
7
- ### Connection
7
+ ## Usage
8
8
 
9
9
  ```ruby
10
- # config and create a connection
11
- @config = {
10
+ # create
11
+ @redis = HellaRedis.new({
12
12
  :timeout => 1,
13
13
  :size => 5,
14
14
  :redis_ns => 'hella-redis-test',
15
15
  :driver => 'ruby',
16
16
  :url => 'redis://localhost:6379/0'
17
- }
18
- @conn = HellaRedis::Connection.new(@config)
17
+ }) # => HellaRedis:ConnectionPool instance
19
18
 
20
19
  # it's actually a pool of connections
21
- @conn.with do |conn|
22
- # get a connection and do something with it
20
+ @redis.connection do |connection|
21
+ # checks out a connection so you can do something with it
22
+ # will check it back in once the block has run
23
+ end
24
+ ```
25
+
26
+ ### Test Mode
27
+
28
+ ```ruby
29
+ ENV['HELLA_REDIS_TEST_MODE'] = 'yes' # set to anything "truthy"
30
+
31
+ @redis_spy = HellaRedis.new({
32
+ :timeout => 1,
33
+ :size => 5,
34
+ :redis_ns => 'hella-redis-test',
35
+ :driver => 'ruby',
36
+ :url => 'redis://localhost:6379/0'
37
+ }) # => HellaRedis::ConnectionPoolSpy instance
38
+
39
+ @redis_spy.connection do |connection_spy|
40
+ connection_spy # => HellaRedis::ConnectionSpy instance
41
+ connection_spy.info
42
+ end
43
+
44
+ @redis_spy.calls.size # => 1
45
+ @redis_spy.calls.first.tap do |call|
46
+ call.command # => 'info'
47
+ call.args # => nil
48
+ call.block # => nil
49
+ end
50
+
51
+ @redis_spy.connection_calls.size # => 1
52
+ @redis_spy.connection_calls.first.tap do |connection_call|
53
+ connection_call.block # => block instance
23
54
  end
24
55
  ```
25
56
 
@@ -1,5 +1,46 @@
1
1
  require 'hella-redis/version'
2
- require 'hella-redis/connection'
2
+ require 'hella-redis/connection_pool'
3
+ require 'hella-redis/connection_pool_spy'
3
4
 
4
5
  module HellaRedis
6
+
7
+ def self.new(args)
8
+ self.send(ENV['HELLA_REDIS_TEST_MODE'] ? :mock : :real, args)
9
+ end
10
+
11
+ def self.real(args)
12
+ ConnectionPool.new(Config.new(args))
13
+ end
14
+
15
+ def self.mock(args)
16
+ ConnectionPoolSpy.new(Config.new(args))
17
+ end
18
+
19
+ class Config
20
+
21
+ attr_reader :url, :driver, :redis_ns, :timeout, :size
22
+
23
+ def initialize(args = nil)
24
+ args ||= {}
25
+ @url = args[:url]
26
+ @driver = args[:driver]
27
+ @redis_ns = args[:redis_ns]
28
+ @timeout = args[:timeout]
29
+ @size = args[:size] || 1
30
+ end
31
+
32
+ def ==(other_config)
33
+ if other_config.kind_of?(Config)
34
+ self.url == other_config.url &&
35
+ self.driver == other_config.driver &&
36
+ self.redis_ns == other_config.redis_ns &&
37
+ self.timeout == other_config.timeout &&
38
+ self.size == other_config.size
39
+ else
40
+ super
41
+ end
42
+ end
43
+
44
+ end
45
+
5
46
  end
@@ -0,0 +1,31 @@
1
+ require 'connection_pool'
2
+ require 'redis'
3
+ require 'redis-namespace'
4
+
5
+ module HellaRedis
6
+
7
+ class ConnectionPool
8
+
9
+ def initialize(config)
10
+ @pool = ::ConnectionPool.new({
11
+ :timeout => config.timeout,
12
+ :size => config.size
13
+ }) do
14
+ ::Redis::Namespace.new(config.redis_ns, {
15
+ :redis => ::Redis.new({
16
+ :url => config.url,
17
+ :driver => config.driver
18
+ })
19
+ })
20
+ end
21
+ end
22
+
23
+ def connection
24
+ @pool.with do |connection|
25
+ yield connection if block_given?
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,41 @@
1
+ require 'redis'
2
+ require 'hella-redis/connection_pool'
3
+ require 'hella-redis/connection_spy'
4
+
5
+ module HellaRedis
6
+
7
+ class ConnectionPoolSpy
8
+
9
+ attr_reader :config, :connection_spy, :connection_calls
10
+
11
+ def initialize(config)
12
+ @config = config
13
+ @connection_spy = ConnectionSpy.new(config)
14
+ @connection_calls = []
15
+ end
16
+
17
+ def calls
18
+ @connection_spy.calls
19
+ end
20
+
21
+ def connection(&block)
22
+ @connection_calls << ConnectionCall.new(block)
23
+ block.call(@connection_spy)
24
+ end
25
+
26
+ def reset!
27
+ @connection_calls = []
28
+ @connection_spy.calls = []
29
+ end
30
+
31
+ def ==(other_pool_spy)
32
+ if other_pool_spy.kind_of?(ConnectionPoolSpy)
33
+ self.config == other_pool_spy.config
34
+ end
35
+ end
36
+
37
+ ConnectionCall = Struct.new(:block)
38
+
39
+ end
40
+
41
+ end
@@ -1,36 +1,12 @@
1
1
  require 'redis'
2
- require 'hella-redis/connection'
3
2
 
4
3
  module HellaRedis
5
4
 
6
5
  class ConnectionSpy
7
6
 
8
- attr_reader :config, :redis_spy, :with_calls
9
-
10
- def initialize(config, redis_spy = nil)
11
- @config = config
12
- @with_calls = []
13
- @redis_spy = redis_spy || RedisSpy.new(config)
14
- end
15
-
16
- def with(*args, &block)
17
- @with_calls << WithCall.new(args, block)
18
- block.call(@redis_spy)
19
- end
20
-
21
- def redis_calls
22
- @redis_spy.calls
23
- end
24
-
25
- end
26
-
27
- class RedisSpy
28
-
29
- attr_reader :calls
7
+ attr_accessor :calls
30
8
 
31
9
  def initialize(config)
32
- # mimic the real conection behavior, accept hash or object
33
- config = Connection::Config.new(config) if config.kind_of?(::Hash)
34
10
  @instance = ::Redis.new({
35
11
  :url => config.url,
36
12
  :driver => config.driver
@@ -39,18 +15,18 @@ module HellaRedis
39
15
  end
40
16
 
41
17
  def pipelined
42
- @calls << RedisCall.new(:pipelined, [])
18
+ @calls << ConnectionCall.new(:pipelined, [])
43
19
  yield self
44
20
  end
45
21
 
46
22
  def multi
47
- @calls << RedisCall.new(:multi, [])
23
+ @calls << ConnectionCall.new(:multi, [])
48
24
  yield self
49
25
  end
50
26
 
51
27
  def method_missing(name, *args, &block)
52
28
  if self.respond_to?(name)
53
- @calls << RedisCall.new(name, args, block)
29
+ @calls << ConnectionCall.new(name, args, block)
54
30
  else
55
31
  super
56
32
  end
@@ -60,9 +36,8 @@ module HellaRedis
60
36
  super || @instance.respond_to?(*args)
61
37
  end
62
38
 
63
- end
39
+ ConnectionCall = Struct.new(:command, :args, :block)
64
40
 
65
- WithCall = Struct.new(:args, :block)
66
- RedisCall = Struct.new(:command, :args, :block)
41
+ end
67
42
 
68
43
  end
@@ -1,3 +1,3 @@
1
1
  module HellaRedis
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,6 +1,20 @@
1
1
  require 'assert/factory'
2
+ require 'hella-redis'
2
3
 
3
4
  module Factory
4
5
  extend Assert::Factory
5
6
 
7
+ def self.config(args = nil)
8
+ HellaRedis::Config.new(self.config_args(args))
9
+ end
10
+
11
+ def self.config_args(args = nil)
12
+ { :timeout => Factory.integer,
13
+ :size => Factory.integer(5),
14
+ :redis_ns => "hella-redis-test-#{Factory.string}",
15
+ :url => 'redis://localhost:6379/0',
16
+ :driver => 'ruby'
17
+ }.merge(args || {})
18
+ end
19
+
6
20
  end
@@ -0,0 +1,76 @@
1
+ require 'assert'
2
+ require 'hella-redis/connection_pool_spy'
3
+
4
+ require 'hella-redis/connection_spy'
5
+
6
+ class HellaRedis::ConnectionPoolSpy
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "HellaRedis::ConnectionPoolSpy"
10
+ setup do
11
+ Assert.stub(HellaRedis::ConnectionSpy, :new) do |*args|
12
+ @connection_spy_created_with = args
13
+ Assert.stub_send(HellaRedis::ConnectionSpy, :new, *args)
14
+ end
15
+
16
+ @config = Factory.config
17
+ @connection_pool_spy = HellaRedis::ConnectionPoolSpy.new(@config)
18
+ end
19
+ subject{ @connection_pool_spy }
20
+
21
+ should have_readers :config, :connection_spy, :connection_calls
22
+ should have_imeths :calls, :connection, :reset!
23
+
24
+ should "know its config and redis spy" do
25
+ assert_equal @config, subject.config
26
+ assert_instance_of HellaRedis::ConnectionSpy, subject.connection_spy
27
+ exp = [@config]
28
+ assert_equal exp, @connection_spy_created_with
29
+ end
30
+
31
+ should "default its connection calls" do
32
+ assert_equal [], subject.connection_calls
33
+ end
34
+
35
+ should "know its calls" do
36
+ assert_same subject.connection_spy.calls, subject.calls
37
+ end
38
+
39
+ should "yield its connection spy using `connection`" do
40
+ yielded = nil
41
+ subject.connection{ |c| yielded = c }
42
+
43
+ assert_same subject.connection_spy, yielded
44
+ end
45
+
46
+ should "track calls to connection" do
47
+ block = proc{ |c| Factory.string }
48
+ subject.connection(&block)
49
+
50
+ call = subject.connection_calls.last
51
+ assert_equal block, call.block
52
+ end
53
+
54
+ should "remove all calls on `reset!`" do
55
+ subject.connection{ |c| c.info }
56
+
57
+ assert_not_empty subject.calls
58
+ assert_not_empty subject.connection_calls
59
+
60
+ subject.reset!
61
+
62
+ assert_empty subject.calls
63
+ assert_empty subject.connection_calls
64
+ end
65
+
66
+ should "know if it is equal to another pool spy" do
67
+ equal_pool_spy = HellaRedis::ConnectionPoolSpy.new(@config)
68
+ assert_equal subject, equal_pool_spy
69
+
70
+ not_equal_config = HellaRedis::ConnectionPoolSpy.new(Factory.config)
71
+ assert_not_equal subject, not_equal_config
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,26 @@
1
+ require 'assert'
2
+ require 'hella-redis/connection_pool'
3
+
4
+ require 'redis-namespace'
5
+
6
+ class HellaRedis::ConnectionPool
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "HellaRedis::Connection"
10
+ setup do
11
+ @connection_pool = HellaRedis::ConnectionPool.new(Factory.config)
12
+ end
13
+ subject{ @connection_pool }
14
+
15
+ should have_imeths :connection
16
+
17
+ should "build a redis namespace and yield it using `connection`" do
18
+ subject.connection do |connection|
19
+ assert_instance_of ::Redis::Namespace, connection
20
+ assert_nothing_raised{ connection.info }
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -4,79 +4,19 @@ require 'hella-redis/connection_spy'
4
4
  class HellaRedis::ConnectionSpy
5
5
 
6
6
  class UnitTests < Assert::Context
7
- setup do
8
- @config = {
9
- :url => 'redis://localhost:6379/0',
10
- :driver => 'ruby'
11
- }
12
- end
13
-
14
- end
15
-
16
- class ConnectionSpyTests < UnitTests
17
7
  desc "HellaRedis::ConnectionSpy"
18
8
  setup do
19
- @connection_spy = HellaRedis::ConnectionSpy.new(@config)
9
+ @connection_spy = HellaRedis::ConnectionSpy.new(Factory.config)
20
10
  end
21
11
  subject{ @connection_spy }
22
12
 
23
- should have_readers :config, :redis_spy, :with_calls
24
- should have_imeths :with, :redis_calls
25
-
26
- should "know its config and redis spy" do
27
- assert_equal @config, subject.config
28
- assert_instance_of HellaRedis::RedisSpy, subject.redis_spy
29
- end
30
-
31
- should "default its with calls" do
32
- assert_equal [], subject.with_calls
33
- end
34
-
35
- should "know its redis spy's calls" do
36
- assert_same subject.redis_spy.calls, subject.redis_calls
37
- end
38
-
39
- should "yield its redis spy using `with`" do
40
- yielded = nil
41
- subject.with{ |c| yielded = c }
42
- assert_same subject.redis_spy, yielded
43
- end
44
-
45
- should "track calls to with" do
46
- overrides = { :timeout => Factory.integer }
47
- block = proc{ |c| Factory.string }
48
- subject.with(overrides, &block)
49
- call = subject.with_calls.last
50
- assert_equal [overrides], call.args
51
- assert_equal block, call.block
52
- end
53
-
54
- should "allow passing a custom redis spy" do
55
- redis_spy = Factory.string
56
- spy = HellaRedis::ConnectionSpy.new(@config, redis_spy)
57
- assert_equal redis_spy, spy.redis_spy
58
- end
59
-
60
- end
61
-
62
- class RedisSpyTests < UnitTests
63
- desc "HellaRedis::RedisSpy"
64
- setup do
65
- @redis_spy = HellaRedis::RedisSpy.new(@config)
66
- end
67
- subject{ @redis_spy }
68
-
69
- should have_readers :pipelined, :multi, :calls
13
+ should have_accessors :calls
14
+ should have_imeths :pipelined, :multi
70
15
 
71
16
  should "default its calls" do
72
17
  assert_equal [], subject.calls
73
18
  end
74
19
 
75
- should "allow passing a config object" do
76
- config = OpenStruct.new(@config)
77
- assert_nothing_raised{ HellaRedis::RedisSpy.new(config) }
78
- end
79
-
80
20
  should "track redis calls made to it" do
81
21
  assert_true subject.respond_to?(:set)
82
22
 
@@ -0,0 +1,123 @@
1
+ require 'assert'
2
+ require 'hella-redis'
3
+
4
+ module HellaRedis
5
+
6
+ class UnitTests < Assert::Context
7
+ desc "HellaRedis"
8
+ setup do
9
+ @config_args = Factory.config_args
10
+ @module = HellaRedis
11
+ end
12
+ subject{ @module }
13
+
14
+ should have_imeths :new, :real, :mock
15
+
16
+ end
17
+
18
+ class NewRealMockTests < UnitTests
19
+ setup do
20
+ @config = Config.new(@config_args)
21
+
22
+ @pool = ConnectionPool.new(@config)
23
+ @pool_new_called_with = nil
24
+ Assert.stub(ConnectionPool, :new) do |*args|
25
+ @pool_new_called_with = args
26
+ @pool
27
+ end
28
+
29
+ @pool_spy = ConnectionPoolSpy.new(@config)
30
+ @pool_spy_new_called_with = nil
31
+ Assert.stub(ConnectionPoolSpy, :new) do |*args|
32
+ @pool_spy_new_called_with = args
33
+ @pool_spy
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ class NewTests < NewRealMockTests
40
+ desc "`new`"
41
+ setup do
42
+ @current_test_mode = ENV['HELLA_REDIS_TEST_MODE']
43
+ ENV['HELLA_REDIS_TEST_MODE'] = 'yes'
44
+ end
45
+ teardown do
46
+ ENV['HELLA_REDIS_TEST_MODE'] = @current_test_mode
47
+ end
48
+
49
+ should "build and return a new connection pool" do
50
+ ENV.delete('HELLA_REDIS_TEST_MODE')
51
+ redis = subject.new(@config_args)
52
+
53
+ assert_equal [@config], @pool_new_called_with
54
+ assert_equal @pool, redis
55
+ end
56
+
57
+ should "build and return a connection pool spy in test mode" do
58
+ redis = subject.new(@config_args)
59
+
60
+ assert_equal [@config], @pool_spy_new_called_with
61
+ assert_equal @pool_spy, redis
62
+ end
63
+
64
+ end
65
+
66
+ class RealTests < NewRealMockTests
67
+ desc "`real`"
68
+
69
+ should "build and return a connection pool spy" do
70
+ redis = subject.real(@config_args)
71
+
72
+ assert_equal [@config], @pool_new_called_with
73
+ assert_equal @pool, redis
74
+ end
75
+
76
+ end
77
+
78
+ class MockTests < NewRealMockTests
79
+ desc "`mock`"
80
+
81
+ should "build and return a connection pool spy" do
82
+ redis = subject.mock(@config_args)
83
+
84
+ assert_equal [@config], @pool_spy_new_called_with
85
+ assert_equal @pool_spy, redis
86
+ end
87
+
88
+ end
89
+
90
+ class ConfigTests < UnitTests
91
+ desc "Config"
92
+ setup do
93
+ @config = Config.new(@config_args)
94
+ end
95
+ subject{ @config }
96
+
97
+ should have_readers :url, :driver, :redis_ns, :timeout, :size
98
+
99
+ should "know its attributes" do
100
+ assert_equal @config_args[:url], subject.url
101
+ assert_equal @config_args[:driver], subject.driver
102
+ assert_equal @config_args[:redis_ns], subject.redis_ns
103
+ assert_equal @config_args[:timeout], subject.timeout
104
+ assert_equal @config_args[:size], subject.size
105
+ end
106
+
107
+ should "default its size" do
108
+ @config_args.delete(:size)
109
+ config = Config.new(@config_args)
110
+ assert_equal 1, config.size
111
+ end
112
+
113
+ should "know if it is equal to another config" do
114
+ equal_config = Config.new(@config_args)
115
+ assert_equal subject, equal_config
116
+
117
+ not_equal_config = Config.new
118
+ assert_not_equal subject, not_equal_config
119
+ end
120
+
121
+ end
122
+
123
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hella-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2016-06-09 00:00:00 Z
13
+ date: 2017-04-05 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: assert
@@ -69,14 +69,17 @@ files:
69
69
  - README.md
70
70
  - hella-redis.gemspec
71
71
  - lib/hella-redis.rb
72
- - lib/hella-redis/connection.rb
72
+ - lib/hella-redis/connection_pool.rb
73
+ - lib/hella-redis/connection_pool_spy.rb
73
74
  - lib/hella-redis/connection_spy.rb
74
75
  - lib/hella-redis/version.rb
75
76
  - log/.gitkeep
76
77
  - test/helper.rb
77
78
  - test/support/factory.rb
79
+ - test/unit/connection_pool_spy_tests.rb
80
+ - test/unit/connection_pool_tests.rb
78
81
  - test/unit/connection_spy_tests.rb
79
- - test/unit/connection_tests.rb
82
+ - test/unit/hella-redis_tests.rb
80
83
  - tmp/.gitkeep
81
84
  homepage: http://github.com/redding/hella-redis
82
85
  licenses:
@@ -100,12 +103,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
103
  requirements: []
101
104
 
102
105
  rubyforge_project:
103
- rubygems_version: 2.6.4
106
+ rubygems_version: 2.6.6
104
107
  signing_key:
105
108
  specification_version: 4
106
109
  summary: It's-a hella-redis!
107
110
  test_files:
108
111
  - test/helper.rb
109
112
  - test/support/factory.rb
113
+ - test/unit/connection_pool_spy_tests.rb
114
+ - test/unit/connection_pool_tests.rb
110
115
  - test/unit/connection_spy_tests.rb
111
- - test/unit/connection_tests.rb
116
+ - test/unit/hella-redis_tests.rb
@@ -1,35 +0,0 @@
1
- require 'connection_pool'
2
- require 'redis'
3
- require 'redis-namespace'
4
-
5
- module HellaRedis
6
-
7
- module Connection
8
-
9
- def self.new(config)
10
- config = Config.new(config) if config.kind_of?(::Hash)
11
- ::ConnectionPool.new(:timeout => config.timeout, :size => config.size) do
12
- ::Redis::Namespace.new(config.redis_ns, {
13
- :redis => ::Redis.new({
14
- :url => config.url,
15
- :driver => config.driver
16
- })
17
- })
18
- end
19
- end
20
-
21
- class Config
22
- attr_reader :url, :driver, :redis_ns, :timeout, :size
23
-
24
- def initialize(args)
25
- @url = args[:url]
26
- @driver = args[:driver]
27
- @redis_ns = args[:redis_ns]
28
- @timeout = args[:timeout]
29
- @size = args[:size] || 1
30
- end
31
- end
32
-
33
- end
34
-
35
- end
@@ -1,75 +0,0 @@
1
- require 'assert'
2
- require 'hella-redis/connection'
3
-
4
- require 'connection_pool'
5
- require 'ostruct'
6
-
7
- module HellaRedis::Connection
8
-
9
- class UnitTests < Assert::Context
10
- desc "HellaRedis::Connection"
11
- setup do
12
- @config_hash = {
13
- :timeout => 1,
14
- :size => 5,
15
- :redis_ns => 'hella-redis-test',
16
- :driver => 'ruby',
17
- :url => 'redis://localhost:6379/0'
18
- }
19
- @conn = HellaRedis::Connection.new(@config_hash)
20
- end
21
- subject{ @conn }
22
-
23
- should "build a connection pool" do
24
- assert_instance_of ::ConnectionPool, subject
25
- end
26
-
27
- should "connect to the redis instance that was provided" do
28
- assert_nothing_raised do
29
- subject.with{ |c| c.info }
30
- end
31
- end
32
-
33
- should "build a redis namespace and yield it using `with`" do
34
- subject.with do |conn|
35
- assert_instance_of ::Redis::Namespace, conn
36
- end
37
- end
38
-
39
- should "allow passing a config object when building a connection" do
40
- conn = nil
41
- assert_nothing_raised do
42
- config = OpenStruct.new(@config_hash)
43
- conn = HellaRedis::Connection.new(config)
44
- end
45
- assert_instance_of ::ConnectionPool, conn
46
- end
47
-
48
- end
49
-
50
- class ConfigTests < UnitTests
51
- desc "Config"
52
- setup do
53
- @config = Config.new(@config_hash)
54
- end
55
- subject{ @config }
56
-
57
- should have_readers :url, :driver, :redis_ns, :timeout, :size
58
-
59
- should "know its attributes" do
60
- assert_equal @config_hash[:url], subject.url
61
- assert_equal @config_hash[:driver], subject.driver
62
- assert_equal @config_hash[:redis_ns], subject.redis_ns
63
- assert_equal @config_hash[:timeout], subject.timeout
64
- assert_equal @config_hash[:size], subject.size
65
- end
66
-
67
- should "default its size" do
68
- @config_hash.delete(:size)
69
- config = Config.new(@config_hash)
70
- assert_equal 1, config.size
71
- end
72
-
73
- end
74
-
75
- end