Skip to content

Commit

Permalink
Update Rubocop config, fix offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
n-rodriguez committed Sep 6, 2024
1 parent 69e0154 commit 421b866
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 55 deletions.
15 changes: 14 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AllCops:
Exclude:
- bin/*
- gemfiles/*
- spec/**/*
- spec/dummy/**/*

Gemspec/RequireMFA:
Enabled: false
Expand Down Expand Up @@ -47,3 +47,16 @@ Layout/EmptyLinesAroundBlockBody:

Layout/EmptyLinesAroundModuleBody:
Enabled: false

#########
# RSPEC #
#########

RSpec/ExampleLength:
Max: 23

RSpec/MultipleExpectations:
Max: 6

RSpecRails/InferredSpecType:
Enabled: false
2 changes: 2 additions & 0 deletions spec/config_rspec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Configure RSpec
RSpec.configure do |config|
# config.order = :random
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
end

it 'returns a nil value (authenticate)' do
expect(controller.send(:authenticate)).to eql(nil)
expect(controller.send(:authenticate)).to be_nil
end

it 'returns a Info class (info)' do
expect(controller.send(:info)).to be_a_kind_of(RedisWebManager::Info)
expect(controller.send(:info)).to be_a(RedisWebManager::Info)
end

it 'returns a Connection class (connection)' do
expect(controller.send(:connection)).to be_a_kind_of(RedisWebManager::Connection)
expect(controller.send(:connection)).to be_a(RedisWebManager::Connection)
end

it 'returns a Action class (action)' do
expect(controller.send(:action)).to be_a_kind_of(RedisWebManager::Action)
expect(controller.send(:action)).to be_a(RedisWebManager::Action)
end
end
end
12 changes: 6 additions & 6 deletions spec/controllers/redis_web_manager/keys_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
eql = {
value: 'test'
}
expect(controller.send(:get_value, 'test')).to eql(eql)
expect(controller.send(:get_value, 'test')).to eq(eql)
end

it 'returns a hash value (get_value - hgetall)' do
Expand All @@ -80,7 +80,7 @@
}
}
redis.hset('hgetall', 'name', 'hgetall')
expect(controller.send(:get_value, 'hgetall')).to eql(eql)
expect(controller.send(:get_value, 'hgetall')).to eq(eql)
end

it 'returns a hash value (get_value - lrange)' do
Expand All @@ -101,15 +101,15 @@
}
]
}
expect(controller.send(:get_value, 'lrange')).to eql(eql)
expect(controller.send(:get_value, 'lrange')).to eq(eql)
end

it 'returns a hash value (get_value - set)' do
redis.sadd('smembers', 'smembers')
eql = {
values: [{ type: 'string', value: 'smembers' }]
}
expect(controller.send(:get_value, 'smembers')).to eql(eql)
expect(controller.send(:get_value, 'smembers')).to eq(eql)
end

it 'returns a hash value (get_value - zset)' do
Expand All @@ -135,7 +135,7 @@
}
]
}
expect(controller.send(:get_value, 'zrange')).to eql(eql)
expect(controller.send(:get_value, 'zrange')).to eq(eql)
end

it 'returns a hash value (get_value - not found)' do
Expand All @@ -145,7 +145,7 @@
eql = {
value: 'Not found'
}
expect(controller.send(:get_value, 'testtesttesttesttest')).to eql(eql)
expect(controller.send(:get_value, 'testtesttesttesttest')).to eq(eql)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
expect(helper.status(true)).to match(/ON/)
end

it 'returns status tag (true)' do
it 'returns status tag (false)' do
expect(helper.status(false)).to match(/OFF/)
end

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe RedisWebManager::Action do
let(:action) do
RedisWebManager::Action.new(RedisWebManager.redises.keys[0])
described_class.new(RedisWebManager.redises.keys[0])
end

let(:redis) do
Expand All @@ -13,21 +13,21 @@

describe 'action' do
it 'returns a OK (flushall)' do
expect(action.flushall).to eql('OK')
expect(action.flushall).to eq('OK')
end

it 'returns a OK (flushdb)' do
expect(action.flushdb).to eql('OK')
expect(action.flushdb).to eq('OK')
end

it 'returns a 1 (del)' do
redis.set('test', 'test')
expect(action.del('test')).to eql(1)
expect(action.del('test')).to eq(1)
end

it 'returns a OK (rename)' do
redis.set('test', 'test')
expect(action.rename('test', 'test2')).to eql('OK')
expect(action.rename('test', 'test2')).to eq('OK')
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@

RSpec.describe RedisWebManager::Connection do
let(:connection) do
RedisWebManager::Connection.new(RedisWebManager.redises.keys[0])
described_class.new(RedisWebManager.redises.keys[0])
end

describe 'connection' do
it 'returns a host' do
expect(connection.host).to eql('localhost')
expect(connection.host).to eq('localhost')
end

it 'returns a port' do
expect(connection.port).to eql(6379)
expect(connection.port).to eq(6379)
end

it 'returns a db' do
expect(connection.db).to eql(0)
expect(connection.db).to eq(0)
end

it 'returns an id' do
expect(connection.id).to eql('redis://localhost:6379')
expect(connection.id).to eq('redis://localhost:6379')
end

it 'returns a location' do
expect(connection.location).to eql('localhost:6379')
expect(connection.location).to eq('localhost:6379')
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe RedisWebManager::Data do
let(:data) do
RedisWebManager::Data.new(RedisWebManager.redises.keys[0])
described_class.new(RedisWebManager.redises.keys[0])
end

describe 'data' do
Expand All @@ -13,11 +13,11 @@
end

it 'returns a Array of keys' do
expect(data.keys).to be_a_kind_of(Array)
expect(data.keys).to be_a(Array)
end

it 'returns a Array of keys deleted' do
expect(data.flush).to be_a_kind_of(Array)
expect(data.flush).to be_a(Array)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe RedisWebManager::Info do
let(:info) do
RedisWebManager::Info.new(RedisWebManager.redises.keys[0])
described_class.new(RedisWebManager.redises.keys[0])
end

let(:redis) do
Expand All @@ -13,80 +13,80 @@

describe 'info' do
it 'returns a true (status)' do
expect(info.status).to eql(true)
expect(info.status).to be(true)
end

it 'returns a Hash class (stats)' do
expect(info.stats).to be_a_kind_of(Hash)
expect(info.stats).to be_a(Hash)
end


it 'returns a string value (type)' do
redis.set('test', 'test', ex: 20.seconds)
expect(info.type('test')).to eql('string')
expect(info.type('test')).to eq('string')
end

it 'returns a Arary of keys (search)' do
redis.set('testtesttest', 'testtesttest')
expect(info.search('testtesttest')).to eql(['testtesttest'])
expect(info.search('testtesttest')).to eq(['testtesttest'])
end

it 'returns an empty array if query string is empty' do
expect(info.search(nil)).to eql([])
expect(info.search('')).to eql([])
expect(info.search(nil)).to eq([])
expect(info.search('')).to eq([])
end

it 'returns a ttl value (expire)' do
expect(info.expiry('test')).to eql(20)
expect(info.expiry('test')).to eq(20)
end

it 'returns a memory usage value (memory_usage)' do
expect(info.memory_usage('test')).to be_between(52, 62)
end

it 'returns a test value (get)' do
expect(info.get('test')).to eql('test')
expect(info.get('test')).to eq('test')
end

it 'returns a Integer value (llen)' do
redis.lpush('llen', '1')
redis.lpush('llen', '2')
expect(info.llen('llen')).to eql(2)
expect(info.llen('llen')).to eq(2)
end

it 'returns a Array value (lrange)' do
redis.lpush('lrange', '1')
redis.lpush('lrange', '2')
expect(info.lrange('lrange', 0, -1)).to eql(%w[2 1])
expect(info.lrange('lrange', 0, -1)).to eq(%w[2 1])
end

it 'returns a Array value (smembers)' do
redis.sadd('smembers', 'smembers')
expect(info.smembers('smembers')).to eql(%w[smembers])
expect(info.smembers('smembers')).to eq(%w[smembers])
end

it 'returns a Array value (zrange)' do
redis.zadd('zrange', 10, '1')
redis.zadd('zrange', 20, '2')
redis.zadd('zrange', 30, '3')
expect(info.zrange('zrange', 0, -1)).to eql(%w[1 2 3])
expect(info.zrange('zrange', 0, -1)).to eq(%w[1 2 3])
end

it 'returns a Hash value (hgetall)' do
redis.hset('hgetall', 'name', 'hgetall')
expect(info.hgetall('hgetall')).to eql('name' => 'hgetall')
expect(info.hgetall('hgetall')).to eq('name' => 'hgetall')
end

it 'returns a Integer class (dbsize)' do
expect(info.dbsize).to be_a_kind_of(Integer)
expect(info.dbsize).to be_a(Integer)
end

it 'returns a Hash class (configuration)' do
expect(info.configuration).to be_a_kind_of(Hash)
expect(info.configuration).to be_a(Hash)
end

it 'returns a Array class (clients)' do
expect(info.clients).to be_a_kind_of(Array)
expect(info.clients).to be_a(Array)
end
end
end
24 changes: 12 additions & 12 deletions spec/redis_web_manager/redis_web_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@
RSpec.describe RedisWebManager do
describe 'Test default configuration' do
it 'returns a Redis class' do
expect(RedisWebManager.redises).to be_a_kind_of(Hash)
expect(described_class.redises).to be_a(Hash)
end

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

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

describe 'Test configuration' do
it 'returns a raise error (redises)' do
expect do
RedisWebManager.configure do |c|
described_class.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|
described_class.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
it 'returns a raise error (invalid lifespan 1)' do
expect do
RedisWebManager.configure do |c|
described_class.configure do |c|
c.redises = {
default: Redis.new
}
Expand All @@ -47,9 +47,9 @@
end.to raise_error(ArgumentError, 'Invalid lifespan, use like that 15.days, 15.minutes etc')
end

it 'returns a raise error (lifespan)' do
it 'returns a raise error (invalid lifespan 2)' do
expect do
RedisWebManager.configure do |c|
described_class.configure do |c|
c.redises = {
default: Redis.new
}
Expand All @@ -59,16 +59,16 @@
end

it 'returns instances' do
RedisWebManager.configure do |c|
described_class.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])
expect(described_class.redises.keys).to eql(%i[foo bar])
expect(described_class.redises.values.map(&:class)).to eql([Redis, Redis])
end
end
end

0 comments on commit 421b866

Please sign in to comment.