From 421b866c9afa9f8684c788772fbb168823d3562e Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Fri, 6 Sep 2024 16:10:21 +0200 Subject: [PATCH] Update Rubocop config, fix offenses --- .rubocop.yml | 15 +++++++- spec/config_rspec.rb | 2 ++ .../application_controller_spec.rb | 8 ++--- .../redis_web_manager/keys_controller_spec.rb | 12 +++---- .../application_helper_spec.rb | 2 +- .../clients_helper_spec.rb | 0 .../dashboard_helper_spec.rb | 0 .../keys_helper_spec.rb | 0 ..._manager_action_spec.rb => action_spec.rb} | 10 +++--- ..._connection_spec.rb => connection_spec.rb} | 12 +++---- ..._web_manager_data_spec.rb => data_spec.rb} | 6 ++-- ..._web_manager_info_spec.rb => info_spec.rb} | 34 +++++++++---------- .../redis_web_manager_spec.rb | 24 ++++++------- 13 files changed, 70 insertions(+), 55 deletions(-) rename spec/helpers/{ => redis_web_manager}/application_helper_spec.rb (93%) rename spec/helpers/{ => redis_web_manager}/clients_helper_spec.rb (100%) rename spec/helpers/{ => redis_web_manager}/dashboard_helper_spec.rb (100%) rename spec/helpers/{ => redis_web_manager}/keys_helper_spec.rb (100%) rename spec/redis_web_manager/{redis_web_manager_action_spec.rb => action_spec.rb} (62%) rename spec/redis_web_manager/{redis_web_manager_connection_spec.rb => connection_spec.rb} (51%) rename spec/redis_web_manager/{redis_web_manager_data_spec.rb => data_spec.rb} (67%) rename spec/redis_web_manager/{redis_web_manager_info_spec.rb => info_spec.rb} (63%) diff --git a/.rubocop.yml b/.rubocop.yml index 225c512..3f7c64b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,7 +11,7 @@ AllCops: Exclude: - bin/* - gemfiles/* - - spec/**/* + - spec/dummy/**/* Gemspec/RequireMFA: Enabled: false @@ -47,3 +47,16 @@ Layout/EmptyLinesAroundBlockBody: Layout/EmptyLinesAroundModuleBody: Enabled: false + +######### +# RSPEC # +######### + +RSpec/ExampleLength: + Max: 23 + +RSpec/MultipleExpectations: + Max: 6 + +RSpecRails/InferredSpecType: + Enabled: false diff --git a/spec/config_rspec.rb b/spec/config_rspec.rb index 3b6c7f8..a8d54d6 100644 --- a/spec/config_rspec.rb +++ b/spec/config_rspec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Configure RSpec RSpec.configure do |config| # config.order = :random diff --git a/spec/controllers/redis_web_manager/application_controller_spec.rb b/spec/controllers/redis_web_manager/application_controller_spec.rb index 5a96fa3..d5e0b8b 100644 --- a/spec/controllers/redis_web_manager/application_controller_spec.rb +++ b/spec/controllers/redis_web_manager/application_controller_spec.rb @@ -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 diff --git a/spec/controllers/redis_web_manager/keys_controller_spec.rb b/spec/controllers/redis_web_manager/keys_controller_spec.rb index f14ec66..f2a00f3 100644 --- a/spec/controllers/redis_web_manager/keys_controller_spec.rb +++ b/spec/controllers/redis_web_manager/keys_controller_spec.rb @@ -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 @@ -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 @@ -101,7 +101,7 @@ } ] } - 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 @@ -109,7 +109,7 @@ 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 @@ -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 @@ -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 diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/redis_web_manager/application_helper_spec.rb similarity index 93% rename from spec/helpers/application_helper_spec.rb rename to spec/helpers/redis_web_manager/application_helper_spec.rb index bf3fcfe..2f4ab0a 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/redis_web_manager/application_helper_spec.rb @@ -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 diff --git a/spec/helpers/clients_helper_spec.rb b/spec/helpers/redis_web_manager/clients_helper_spec.rb similarity index 100% rename from spec/helpers/clients_helper_spec.rb rename to spec/helpers/redis_web_manager/clients_helper_spec.rb diff --git a/spec/helpers/dashboard_helper_spec.rb b/spec/helpers/redis_web_manager/dashboard_helper_spec.rb similarity index 100% rename from spec/helpers/dashboard_helper_spec.rb rename to spec/helpers/redis_web_manager/dashboard_helper_spec.rb diff --git a/spec/helpers/keys_helper_spec.rb b/spec/helpers/redis_web_manager/keys_helper_spec.rb similarity index 100% rename from spec/helpers/keys_helper_spec.rb rename to spec/helpers/redis_web_manager/keys_helper_spec.rb diff --git a/spec/redis_web_manager/redis_web_manager_action_spec.rb b/spec/redis_web_manager/action_spec.rb similarity index 62% rename from spec/redis_web_manager/redis_web_manager_action_spec.rb rename to spec/redis_web_manager/action_spec.rb index 39a0941..c7b03a4 100644 --- a/spec/redis_web_manager/redis_web_manager_action_spec.rb +++ b/spec/redis_web_manager/action_spec.rb @@ -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 @@ -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 diff --git a/spec/redis_web_manager/redis_web_manager_connection_spec.rb b/spec/redis_web_manager/connection_spec.rb similarity index 51% rename from spec/redis_web_manager/redis_web_manager_connection_spec.rb rename to spec/redis_web_manager/connection_spec.rb index 6ee72a4..5c6505c 100644 --- a/spec/redis_web_manager/redis_web_manager_connection_spec.rb +++ b/spec/redis_web_manager/connection_spec.rb @@ -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 diff --git a/spec/redis_web_manager/redis_web_manager_data_spec.rb b/spec/redis_web_manager/data_spec.rb similarity index 67% rename from spec/redis_web_manager/redis_web_manager_data_spec.rb rename to spec/redis_web_manager/data_spec.rb index 673741d..01f7e4a 100644 --- a/spec/redis_web_manager/redis_web_manager_data_spec.rb +++ b/spec/redis_web_manager/data_spec.rb @@ -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 @@ -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 diff --git a/spec/redis_web_manager/redis_web_manager_info_spec.rb b/spec/redis_web_manager/info_spec.rb similarity index 63% rename from spec/redis_web_manager/redis_web_manager_info_spec.rb rename to spec/redis_web_manager/info_spec.rb index 30808f3..96a5d46 100644 --- a/spec/redis_web_manager/redis_web_manager_info_spec.rb +++ b/spec/redis_web_manager/info_spec.rb @@ -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 @@ -13,31 +13,31 @@ 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 @@ -45,48 +45,48 @@ 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 diff --git a/spec/redis_web_manager/redis_web_manager_spec.rb b/spec/redis_web_manager/redis_web_manager_spec.rb index cfadecc..794c431 100644 --- a/spec/redis_web_manager/redis_web_manager_spec.rb +++ b/spec/redis_web_manager/redis_web_manager_spec.rb @@ -5,22 +5,22 @@ 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 }') @@ -28,7 +28,7 @@ it 'returns a raise error (value of redises)' do expect do - RedisWebManager.configure do |c| + described_class.configure do |c| c.redises = { default: 1 } @@ -36,9 +36,9 @@ 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 } @@ -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 } @@ -59,7 +59,7 @@ end it 'returns instances' do - RedisWebManager.configure do |c| + described_class.configure do |c| c.redises = { foo: Redis.new, bar: Redis.new @@ -67,8 +67,8 @@ 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