Sha256: b3035193a02f8640f29b3c834dfadf98e4bb16f7bfd07befd06134d8eb88bba3

Contents?: true

Size: 1.98 KB

Versions: 3

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe RedisWebManager do
  describe 'Test default configuration' do
    it 'returns a Redis class' do
      expect(RedisWebManager.redises).to be_a_kind_of(Hash)
    end

    it 'returns a nil class' do
      expect(RedisWebManager.authenticate).to eql(nil)
    end

    it 'returns a ActiveSupport::Duration class' do
      expect(RedisWebManager.lifespan).to be_a_kind_of(ActiveSupport::Duration)
    end
  end

  describe 'Test configuration' do
    it 'returns a raise error (redises)' do
      expect do
        RedisWebManager.configure do |c|
          c.redises = 1
        end
      end.to raise_error(ArgumentError, 'Invalid redises hash, use like that { test: Redis.new }')
    end

    it 'returns a raise error (value of redises)' do
      expect do
        RedisWebManager.configure do |c|
          c.redises = {
            default: 1
          }
        end
      end.to raise_error(ArgumentError, 'Invalid Redis instance for default, use like that Redis.new')
    end

    it 'returns a raise error (lifespan)' do
      expect do
        RedisWebManager.configure do |c|
          c.redises = {
            default: Redis.new
          }
          c.lifespan = 1
        end
      end.to raise_error(ArgumentError, 'Invalid lifespan, use like that 15.days, 15.minutes etc')
    end

    it 'returns a raise error (lifespan)' do
      expect do
        RedisWebManager.configure do |c|
          c.redises = {
            default: Redis.new
          }
          c.lifespan = -1.days
        end
      end.to raise_error(ArgumentError, 'Invalid lifespan, value must be greater than 0')
    end

    it 'returns instances' do
      RedisWebManager.configure do |c|
        c.redises = {
          foo: Redis.new,
          bar: Redis.new
        }
        c.lifespan = 12.days
      end

      expect(RedisWebManager.redises.keys).to eql(%i[foo bar])
      expect(RedisWebManager.redises.values.map(&:class)).to eql([Redis, Redis])
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redis_web_manager-0.4.0 spec/redis_web_manager_spec.rb
redis_web_manager-0.3.9 spec/redis_web_manager_spec.rb
redis_web_manager-0.3.8 spec/redis_web_manager_spec.rb