hella-redis 0.2.0 → 0.5.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2c11849c706992fadaf24788eab0d8e5998350e08b429646c772097fc32cd048
4
+ data.tar.gz: c291e238be0cff2321ea88058c3c3eb22496702595b6f6900e9a80570901865e
5
+ SHA512:
6
+ metadata.gz: 7f8ea4a862606da3b802ff7a841320dfe05ca6cea1304aa05b089b022d7711f4bc2779c9032b4cc231a731e9b6e9b4c3ab096c7dab35cdd6c3b731f0c65bcbb8
7
+ data.tar.gz: fe824c06209a19cea1e0b72ac261bf788e9b6d044803acd3003e5216be0ea1429fd2c1e37fd5a34227831d32f0d822668729483710477333ae053e3a38aaf022
data/.l.yml ADDED
@@ -0,0 +1,9 @@
1
+ # https://github.com/redding/l.rb
2
+
3
+ linters:
4
+ - name: "Rubocop"
5
+ cmd: "bundle exec rubocop"
6
+ autocorrect_cmd: "bundle exec rubocop -A"
7
+ extensions:
8
+ - ".rb"
9
+ cli_abbrev: "u"
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ inherit_gem:
2
+ much-style-guide:
3
+ - "lib/much-style-guide/rubocop.yml"
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.3
data/.t.yml ADDED
@@ -0,0 +1,6 @@
1
+ # https://github.com/redding/t.rb
2
+
3
+ default_cmd: "bundle exec assert"
4
+ test_dir: "test"
5
+ test_file_suffixes:
6
+ - "_tests.rb"
data/Gemfile CHANGED
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
5
+ ruby "~> 2.5"
6
+
3
7
  gemspec
4
8
 
5
- gem 'rake'
6
- gem 'pry', "~> 0.9.0"
9
+ gem "pry"
File without changes
data/README.md CHANGED
@@ -2,32 +2,72 @@
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 = {
12
- :timeout => 1,
13
- :size => 5,
14
- :redis_ns => 'hella-redis-test',
15
- :driver => 'ruby',
16
- :url => 'redis://localhost:6379/0'
17
- }
18
- @conn = HellaRedis::Connection.new(@config)
10
+ # create
11
+ @redis =
12
+ HellaRedis.new(
13
+ timeout: 1,
14
+ size: 5,
15
+ redis_ns: "hella-redis-test",
16
+ driver: "ruby",
17
+ url: "redis://localhost:6379/0"
18
+ ) # => HellaRedis:ConnectionPool instance
19
19
 
20
20
  # it's actually a pool of connections
21
- @conn.with do |conn|
22
- # get a connection and do something with it
21
+ @redis.connection do |connection|
22
+ # checks out a connection so you can do something with it
23
+ # will check it back in once the block has run
24
+ end
25
+ ```
26
+
27
+ ### Test Mode
28
+
29
+ ```ruby
30
+ ENV["HELLA_REDIS_TEST_MODE"] = "yes" # set to anything "truthy"
31
+
32
+ @redis_spy =
33
+ HellaRedis.new({
34
+ timeout: 1,
35
+ size: 5,
36
+ redis_ns: "hella-redis-test",
37
+ driver: "ruby",
38
+ url: "redis://localhost:6379/0"
39
+ }) # => HellaRedis::ConnectionPoolSpy instance
40
+
41
+ @redis_spy.connection do |connection|
42
+ connection # => HellaRedis::ConnectionSpy instance
43
+ connection.info
44
+ end
45
+
46
+ @redis_spy.calls.size # => 1
47
+ @redis_spy.calls.first.tap do |call|
48
+ call.command # => :info
49
+ call.args # => nil
50
+ call.block # => nil
51
+ end
52
+
53
+ @redis_spy.connection_calls.size # => 1
54
+ @redis_spy.connection_calls.first.tap do |connection_call|
55
+ connection_call.block # => block instance
56
+ end
57
+
58
+ Assert.stub(@redis_spy.connection_spy, :get).with("some-key"){ "some-value" }
59
+ value = @redis_spy.connection do |connection|
60
+ connection.get("some_key")
23
61
  end
62
+ assert_that("some-value").equals(value)
63
+ @redis_spy.calls.size # => 1 (unchanged b/c we stubbed the :get method)
24
64
  ```
25
65
 
26
66
  ## Installation
27
67
 
28
68
  Add this line to your application's Gemfile:
29
69
 
30
- gem 'hella-redis'
70
+ gem "hella-redis"
31
71
 
32
72
  And then execute:
33
73
 
data/hella-redis.gemspec CHANGED
@@ -1,5 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path("../lib", __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require "hella-redis/version"
5
7
 
@@ -8,19 +10,22 @@ Gem::Specification.new do |gem|
8
10
  gem.version = HellaRedis::VERSION
9
11
  gem.authors = ["Kelly Redding", "Collin Redding"]
10
12
  gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
11
- gem.description = %q{It's-a hella-redis!}
12
- gem.summary = %q{It's-a hella-redis!}
13
+ gem.summary = "It's-a hella-redis!"
14
+ gem.description = "It's-a hella-redis!"
13
15
  gem.homepage = "http://github.com/redding/hella-redis"
16
+ gem.license = "MIT"
14
17
 
15
- gem.files = `git ls-files`.split($/)
18
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
19
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
20
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
21
  gem.require_paths = ["lib"]
19
22
 
20
- gem.add_development_dependency("assert")
23
+ gem.required_ruby_version = "~> 2.5"
21
24
 
22
- gem.add_dependency("redis", ["~> 3.2"])
23
- gem.add_dependency("redis-namespace", ["~> 1.5"])
24
- gem.add_dependency("connection_pool", ["= 0.9.2"]) # temp, for 1.8.7 support
25
+ gem.add_development_dependency("assert", ["~> 2.19.6"])
26
+ gem.add_development_dependency("much-style-guide", ["~> 0.6.3"])
25
27
 
28
+ gem.add_dependency("redis", ["~> 4.2.5"])
29
+ gem.add_dependency("redis-namespace", ["~> 1.8.1"])
30
+ gem.add_dependency("connection_pool", ["~> 2.2.5"])
26
31
  end
data/lib/hella-redis.rb CHANGED
@@ -1,5 +1,44 @@
1
- require 'hella-redis/version'
2
- require 'hella-redis/connection'
1
+ # frozen_string_literal: true
2
+
3
+ require "hella-redis/version"
4
+ require "hella-redis/connection_pool"
5
+ require "hella-redis/connection_pool_spy"
3
6
 
4
7
  module HellaRedis
8
+ def self.new(args)
9
+ send(ENV["HELLA_REDIS_TEST_MODE"] ? :mock : :real, args)
10
+ end
11
+
12
+ def self.real(args)
13
+ ConnectionPool.new(Config.new(args))
14
+ end
15
+
16
+ def self.mock(args)
17
+ ConnectionPoolSpy.new(Config.new(args))
18
+ end
19
+
20
+ class Config
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)
33
+ if other.is_a?(Config)
34
+ url == other.url &&
35
+ driver == other.driver &&
36
+ redis_ns == other.redis_ns &&
37
+ timeout == other.timeout &&
38
+ size == other.size
39
+ else
40
+ super
41
+ end
42
+ end
43
+ end
5
44
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "connection_pool"
4
+ require "redis"
5
+ require "redis-namespace"
6
+
7
+ module HellaRedis
8
+ class ConnectionPool
9
+ def initialize(config)
10
+ @pool =
11
+ ::ConnectionPool.new(
12
+ timeout: config.timeout,
13
+ size: config.size,
14
+ ) do
15
+ ::Redis::Namespace.new(
16
+ config.redis_ns,
17
+ redis: ::Redis.new(url: config.url, driver: config.driver),
18
+ )
19
+ end
20
+ end
21
+
22
+ def connection
23
+ @pool.with do |connection|
24
+ yield connection if block_given?
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "redis"
4
+ require "hella-redis/connection_pool"
5
+ require "hella-redis/connection_spy"
6
+
7
+ module HellaRedis
8
+ class ConnectionPoolSpy
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)
32
+ config == other.config if other.is_a?(ConnectionPoolSpy)
33
+ end
34
+
35
+ ConnectionCall = Struct.new(:block)
36
+ end
37
+ end
@@ -1,58 +1,42 @@
1
- require 'redis'
2
- require 'hella-redis/connection'
1
+ # frozen_string_literal: true
3
2
 
4
- module HellaRedis
3
+ require "redis"
5
4
 
5
+ module HellaRedis
6
6
  class ConnectionSpy
7
+ attr_accessor :calls
7
8
 
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)
9
+ def initialize(config)
10
+ @instance =
11
+ ::Redis.new(
12
+ url: config.url,
13
+ driver: config.driver,
14
+ )
15
+ @calls = []
14
16
  end
15
17
 
16
- def with(*args, &block)
17
- @with_calls << WithCall.new(args, block)
18
- block.call(@redis_spy)
18
+ def pipelined
19
+ @calls << ConnectionCall.new(:pipelined, [])
20
+ yield self
19
21
  end
20
22
 
21
- def redis_calls
22
- @redis_spy.calls
23
- end
24
-
25
- end
26
-
27
- class RedisSpy
28
-
29
- attr_reader :calls
30
-
31
- 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
- @instance = ::Redis.new({
35
- :url => config.url,
36
- :driver => config.driver
37
- })
38
- @calls = []
23
+ def multi
24
+ @calls << ConnectionCall.new(:multi, [])
25
+ yield self
39
26
  end
40
27
 
41
28
  def method_missing(name, *args, &block)
42
- if self.respond_to?(name)
43
- @calls << RedisCall.new(name, args, block)
29
+ if respond_to?(name)
30
+ @calls << ConnectionCall.new(name, args, block)
44
31
  else
45
32
  super
46
33
  end
47
34
  end
48
35
 
49
- def respond_to?(*args)
36
+ def respond_to_missing?(*args)
50
37
  super || @instance.respond_to?(*args)
51
38
  end
52
39
 
40
+ ConnectionCall = Struct.new(:command, :args, :block)
53
41
  end
54
-
55
- WithCall = Struct.new(:args, :block)
56
- RedisCall = Struct.new(:command, :args, :block)
57
-
58
42
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HellaRedis
2
- VERSION = "0.2.0"
4
+ VERSION = "0.5.0"
3
5
  end
File without changes
data/test/helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # this file is automatically required when you run `assert`
2
4
  # put any test helpers here
3
5
 
@@ -5,6 +7,6 @@
5
7
  $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
6
8
 
7
9
  # require pry for debugging (`binding.pry`)
8
- require 'pry'
10
+ require "pry"
9
11
 
10
- require 'test/support/factory'
12
+ require "test/support/factory"
@@ -1,6 +1,21 @@
1
- require 'assert/factory'
1
+ # frozen_string_literal: true
2
+
3
+ require "assert/factory"
4
+ require "hella-redis"
2
5
 
3
6
  module Factory
4
7
  extend Assert::Factory
5
8
 
9
+ def self.config(args = nil)
10
+ HellaRedis::Config.new(config_args(args))
11
+ end
12
+
13
+ def self.config_args(args = nil)
14
+ { timeout: Factory.integer,
15
+ size: Factory.integer(5),
16
+ redis_ns: "hella-redis-test-#{Factory.string}",
17
+ url: "redis://localhost:6379/0",
18
+ driver: "ruby",
19
+ }.merge(args || {})
20
+ end
6
21
  end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "assert"
4
+ require "hella-redis/connection_pool_spy"
5
+
6
+ require "hella-redis/connection_spy"
7
+
8
+ class HellaRedis::ConnectionPoolSpy
9
+ class UnitTests < Assert::Context
10
+ desc "HellaRedis::ConnectionPoolSpy"
11
+ setup do
12
+ Assert.stub_tap_on_call(HellaRedis::ConnectionSpy, :new) do |_, call|
13
+ @connection_spy_new_call = call
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_that(subject.config).is(@config)
26
+ assert_that(subject.connection_spy)
27
+ .is_an_instance_of(HellaRedis::ConnectionSpy)
28
+ assert_that(@connection_spy_new_call.args).equals([@config])
29
+ end
30
+
31
+ should "default its connection calls" do
32
+ assert_that(subject.connection_calls).equals([])
33
+ end
34
+
35
+ should "know its calls" do
36
+ assert_that(subject.calls).is(subject.connection_spy.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_that(yielded).is(subject.connection_spy)
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_that(call.block).is(block)
52
+ end
53
+
54
+ should "remove all calls on `reset!`" do
55
+ subject.connection(&:info)
56
+
57
+ assert_that(subject.calls.empty?).is_false
58
+ assert_that(subject.connection_calls.empty?).is_false
59
+
60
+ subject.reset!
61
+
62
+ assert_that(subject.calls.empty?).is_true
63
+ assert_that(subject.connection_calls.empty?).is_true
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_that(equal_pool_spy).equals(subject)
69
+
70
+ not_equal_config = HellaRedis::ConnectionPoolSpy.new(Factory.config)
71
+ assert_that(not_equal_config).does_not_equal(subject)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "assert"
4
+ require "hella-redis/connection_pool"
5
+
6
+ require "redis-namespace"
7
+
8
+ class HellaRedis::ConnectionPool
9
+ class UnitTests < Assert::Context
10
+ desc "HellaRedis::Connection"
11
+ setup do
12
+ @connection_pool = HellaRedis::ConnectionPool.new(Factory.config)
13
+ end
14
+ subject{ @connection_pool }
15
+
16
+ should have_imeths :connection
17
+
18
+ should "build a redis namespace and yield it using `connection`" do
19
+ subject.connection do |connection|
20
+ assert_that(connection).is_an_instance_of(::Redis::Namespace)
21
+ assert_that{ connection.get(Factory.string) }.does_not_raise
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,100 +1,49 @@
1
- require 'assert'
2
- require 'hella-redis/connection_spy'
1
+ # frozen_string_literal: true
3
2
 
4
- class HellaRedis::ConnectionSpy
3
+ require "assert"
4
+ require "hella-redis/connection_spy"
5
5
 
6
+ class HellaRedis::ConnectionSpy
6
7
  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
8
  desc "HellaRedis::ConnectionSpy"
18
9
  setup do
19
- @connection_spy = HellaRedis::ConnectionSpy.new(@config)
10
+ @connection_spy = HellaRedis::ConnectionSpy.new(Factory.config)
20
11
  end
21
12
  subject{ @connection_spy }
22
13
 
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 :calls
14
+ should have_accessors :calls
15
+ should have_imeths :pipelined, :multi
70
16
 
71
17
  should "default its calls" do
72
- assert_equal [], subject.calls
73
- end
74
-
75
- should "allow passing a config object" do
76
- config = OpenStruct.new(@config)
77
- assert_nothing_raised{ HellaRedis::RedisSpy.new(config) }
18
+ assert_that(subject.calls).equals([])
78
19
  end
79
20
 
80
21
  should "track redis calls made to it" do
81
- assert_true subject.respond_to?(:set)
22
+ assert_that(subject.respond_to?(:set)).is_true
82
23
 
83
24
  key, value = [Factory.string, Factory.string]
84
25
  subject.set(key, value)
85
26
 
86
27
  call = subject.calls.first
87
- assert_equal :set, call.command
88
- assert_equal [key, value], call.args
28
+ assert_that(call.command).equals(:set)
29
+ assert_that(call.args).equals([key, value])
30
+ end
31
+
32
+ should "track the call and yield itself using `pipelined`" do
33
+ subject.pipelined{ |c| c.set(Factory.string, Factory.string) }
34
+ assert_that(subject.calls.map(&:command)).equals([:pipelined, :set])
35
+ end
36
+
37
+ should "track the call and yield itself using `multi`" do
38
+ subject.multi{ |c| c.set(Factory.string, Factory.string) }
39
+ assert_that(subject.calls.map(&:command)).equals([:multi, :set])
89
40
  end
90
41
 
91
42
  should "raise no method errors for non-redis methods" do
92
- assert_false subject.respond_to?(:super_awesome_set)
93
- assert_raises(NoMethodError) do
43
+ assert_that(subject.respond_to?(:super_awesome_set)).is_false
44
+ assert_that{
94
45
  subject.super_awesome_set(Factory.string, Factory.string)
95
- end
46
+ }.raises(NoMethodError)
96
47
  end
97
-
98
48
  end
99
-
100
49
  end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "assert"
4
+ require "hella-redis"
5
+
6
+ module HellaRedis
7
+ class UnitTests < Assert::Context
8
+ desc "HellaRedis"
9
+ setup do
10
+ @config_args = Factory.config_args
11
+ @module = HellaRedis
12
+ end
13
+ subject{ @module }
14
+
15
+ should have_imeths :new, :real, :mock
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_on_call(ConnectionPool, :new) do |call|
25
+ @pool_new_call = call
26
+ @pool
27
+ end
28
+
29
+ @pool_spy = ConnectionPoolSpy.new(@config)
30
+ @pool_spy_new_called_with = nil
31
+ Assert.stub_on_call(ConnectionPoolSpy, :new) do |call|
32
+ @pool_spy_new_call = call
33
+ @pool_spy
34
+ end
35
+ end
36
+ end
37
+
38
+ class NewTests < NewRealMockTests
39
+ desc "`new`"
40
+ setup do
41
+ @current_test_mode = ENV["HELLA_REDIS_TEST_MODE"]
42
+ ENV["HELLA_REDIS_TEST_MODE"] = "yes"
43
+ end
44
+ teardown do
45
+ ENV["HELLA_REDIS_TEST_MODE"] = @current_test_mode
46
+ end
47
+
48
+ should "build and return a new connection pool" do
49
+ ENV.delete("HELLA_REDIS_TEST_MODE")
50
+ redis = subject.new(@config_args)
51
+
52
+ assert_that(@pool_new_call.args).equals([@config])
53
+ assert_that(redis).equals(@pool)
54
+ end
55
+
56
+ should "build and return a connection pool spy in test mode" do
57
+ redis = subject.new(@config_args)
58
+
59
+ assert_that(@pool_spy_new_call.args).equals([@config])
60
+ assert_that(redis).equals(@pool_spy)
61
+ end
62
+ end
63
+
64
+ class RealTests < NewRealMockTests
65
+ desc "`real`"
66
+
67
+ should "build and return a connection pool spy" do
68
+ redis = subject.real(@config_args)
69
+
70
+ assert_that(@pool_new_call.args).equals([@config])
71
+ assert_that(redis).equals(@pool)
72
+ end
73
+ end
74
+
75
+ class MockTests < NewRealMockTests
76
+ desc "`mock`"
77
+
78
+ should "build and return a connection pool spy" do
79
+ redis = subject.mock(@config_args)
80
+
81
+ assert_that(@pool_spy_new_call.args).equals([@config])
82
+ assert_that(redis).equals(@pool_spy)
83
+ end
84
+ end
85
+
86
+ class ConfigTests < UnitTests
87
+ desc "Config"
88
+ setup do
89
+ @config = Config.new(@config_args)
90
+ end
91
+ subject{ @config }
92
+
93
+ should have_readers :url, :driver, :redis_ns, :timeout, :size
94
+
95
+ should "know its attributes" do
96
+ assert_that(subject.url).equals(@config_args[:url])
97
+ assert_that(subject.driver).equals(@config_args[:driver])
98
+ assert_that(subject.redis_ns).equals(@config_args[:redis_ns])
99
+ assert_that(subject.timeout).equals(@config_args[:timeout])
100
+ assert_that(subject.size).equals(@config_args[:size])
101
+ end
102
+
103
+ should "default its size" do
104
+ @config_args.delete(:size)
105
+ config = Config.new(@config_args)
106
+ assert_that(config.size).equals(1)
107
+ end
108
+
109
+ should "know if it is equal to another config" do
110
+ equal_config = Config.new(@config_args)
111
+ assert_that(subject).equals(equal_config)
112
+
113
+ not_equal_config = Config.new
114
+ assert_that(subject).does_not_equal(not_equal_config)
115
+ end
116
+ end
117
+ end
metadata CHANGED
@@ -1,145 +1,143 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hella-redis
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Kelly Redding
14
8
  - Collin Redding
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2014-12-30 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
31
- version_requirements: *id001
32
- type: :development
12
+ date: 2021-05-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
33
15
  name: assert
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.19.6
21
+ type: :development
34
22
  prerelease: false
35
- - !ruby/object:Gem::Dependency
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- none: false
38
- requirements:
39
- - - ~>
40
- - !ruby/object:Gem::Version
41
- hash: 3
42
- segments:
43
- - 3
44
- - 2
45
- version: "3.2"
46
- version_requirements: *id002
47
- type: :runtime
48
- name: redis
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.19.6
28
+ - !ruby/object:Gem::Dependency
29
+ name: much-style-guide
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.6.3
35
+ type: :development
49
36
  prerelease: false
50
- - !ruby/object:Gem::Dependency
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ~>
55
- - !ruby/object:Gem::Version
56
- hash: 5
57
- segments:
58
- - 1
59
- - 5
60
- version: "1.5"
61
- version_requirements: *id003
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.6.3
42
+ - !ruby/object:Gem::Dependency
43
+ name: redis
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 4.2.5
62
49
  type: :runtime
63
- name: redis-namespace
64
50
  prerelease: false
65
- - !ruby/object:Gem::Dependency
66
- requirement: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - "="
70
- - !ruby/object:Gem::Version
71
- hash: 63
72
- segments:
73
- - 0
74
- - 9
75
- - 2
76
- version: 0.9.2
77
- version_requirements: *id004
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 4.2.5
56
+ - !ruby/object:Gem::Dependency
57
+ name: redis-namespace
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.8.1
78
63
  type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.1
70
+ - !ruby/object:Gem::Dependency
79
71
  name: connection_pool
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 2.2.5
77
+ type: :runtime
80
78
  prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 2.2.5
81
84
  description: It's-a hella-redis!
82
- email:
85
+ email:
83
86
  - kelly@kellyredding.com
84
87
  - collin.redding@me.com
85
88
  executables: []
86
-
87
89
  extensions: []
88
-
89
90
  extra_rdoc_files: []
90
-
91
- files:
92
- - .gitignore
91
+ files:
92
+ - ".gitignore"
93
+ - ".l.yml"
94
+ - ".rubocop.yml"
95
+ - ".ruby-version"
96
+ - ".t.yml"
93
97
  - Gemfile
94
- - LICENSE.txt
98
+ - LICENSE
95
99
  - README.md
96
- - Rakefile
97
100
  - hella-redis.gemspec
98
101
  - lib/hella-redis.rb
99
- - lib/hella-redis/connection.rb
102
+ - lib/hella-redis/connection_pool.rb
103
+ - lib/hella-redis/connection_pool_spy.rb
100
104
  - lib/hella-redis/connection_spy.rb
101
105
  - lib/hella-redis/version.rb
102
- - log/.gitkeep
106
+ - log/.keep
103
107
  - test/helper.rb
104
108
  - test/support/factory.rb
109
+ - test/unit/connection_pool_spy_tests.rb
110
+ - test/unit/connection_pool_tests.rb
105
111
  - test/unit/connection_spy_tests.rb
106
- - test/unit/connection_tests.rb
107
- - tmp/.gitkeep
112
+ - test/unit/hella-redis_tests.rb
113
+ - tmp/.keep
108
114
  homepage: http://github.com/redding/hella-redis
109
- licenses: []
110
-
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
111
118
  post_install_message:
112
119
  rdoc_options: []
113
-
114
- require_paths:
120
+ require_paths:
115
121
  - lib
116
- required_ruby_version: !ruby/object:Gem::Requirement
117
- none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- hash: 3
122
- segments:
123
- - 0
124
- version: "0"
125
- required_rubygems_version: !ruby/object:Gem::Requirement
126
- none: false
127
- requirements:
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '2.5'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
128
129
  - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
- version: "0"
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
134
132
  requirements: []
135
-
136
- rubyforge_project:
137
- rubygems_version: 1.8.29
133
+ rubygems_version: 3.1.6
138
134
  signing_key:
139
- specification_version: 3
135
+ specification_version: 4
140
136
  summary: It's-a hella-redis!
141
- test_files:
137
+ test_files:
142
138
  - test/helper.rb
143
139
  - test/support/factory.rb
140
+ - test/unit/connection_pool_spy_tests.rb
141
+ - test/unit/connection_pool_tests.rb
144
142
  - test/unit/connection_spy_tests.rb
145
- - test/unit/connection_tests.rb
143
+ - test/unit/hella-redis_tests.rb
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
@@ -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[: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[: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