From 12c85aa9df98edf5488bc61086f4e7f3d6a747fa Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Sun, 1 Sep 2024 02:52:45 +0200 Subject: [PATCH] Improve Rubocop config, fix offenses --- .rubocop.yml | 18 +++++++++++++++++- spec/config_rspec.rb | 2 ++ spec/royce/role_spec.rb | 15 ++++++++++----- spec/royce/scope_spec.rb | 8 +++++--- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 65f63aa..ab36b4a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,7 +12,7 @@ AllCops: - bin/* - lib/generators/**/*.rb - gemfiles/* - - spec/**/* + - spec/dummy/**/* Gemspec/RequireMFA: Enabled: false @@ -27,6 +27,9 @@ Style/Documentation: Style/HashSyntax: EnforcedShorthandSyntax: never +Style/BlockDelimiters: + AllowedPatterns: ['expect'] + ########## # LAYOUT # ########## @@ -50,3 +53,16 @@ Layout/EmptyLinesAroundBlockBody: Layout/EmptyLinesAroundModuleBody: Enabled: false + +######### +# RSPEC # +######### + +RSpec/MultipleExpectations: + Max: 6 + +RSpec/ExampleLength: + Max: 8 + +RSpec/NotToNot: + EnforcedStyle: to_not diff --git a/spec/config_rspec.rb b/spec/config_rspec.rb index 2ff8172..0abea7a 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| # Use DB agnostic schema by default diff --git a/spec/royce/role_spec.rb b/spec/royce/role_spec.rb index c87e5d5..c1daf78 100644 --- a/spec/royce/role_spec.rb +++ b/spec/royce/role_spec.rb @@ -1,20 +1,23 @@ +# frozen_string_literal: true + require 'spec_helper' -RSpec.describe 'Basic tests' do +RSpec.describe 'Basic tests' do # rubocop:disable RSpec/DescribeClass before { User.delete_all } + let(:user) { User.create } it 'can create role' do role = Royce::Role.create(name: 'some_role') - expect(role).to_not be nil + expect(role).to_not be_nil expect(role.name).to eq 'some_role' expect(role.to_s).to eq 'some_role' end it 'Can create user' do user = User.create - expect(user).to_not be nil + expect(user).to_not be_nil end it 'Creates roles automatically' do @@ -108,7 +111,9 @@ it 'has named scopes for each role' do User.available_roles.each do |role| - User.send role.name.pluralize.to_sym + expect { + User.send(role.name.pluralize.to_sym) + }.to_not raise_error end end @@ -119,7 +124,7 @@ expect(user.role_list).to eq ['user'] user.add_role :admin - expect(user.role_list).to eq ['user', 'admin'] + expect(user.role_list).to eq %w[user admin] end it 'doesnt get double roles' do diff --git a/spec/royce/scope_spec.rb b/spec/royce/scope_spec.rb index 1ae9daa..32b32d5 100644 --- a/spec/royce/scope_spec.rb +++ b/spec/royce/scope_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -RSpec.describe 'Testing class-level scopes' do +RSpec.describe 'Testing class-level scopes' do # rubocop:disable RSpec/DescribeClass before do Employee.delete_all @@ -31,10 +33,10 @@ describe 'Role to owning class relationships' do the_role = Royce::Role.find_or_create_by(name: 'partier') - count = 20 + count = 20 it 'exist for single word models' do - count.times{ Employee.create.add_role 'partier' } + count.times { Employee.create.add_role 'partier' } expect(the_role.employees.count).to eq count end