From a26e6fc68c7c6da8eaaee38fc89604ae90049b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Thu, 30 May 2024 09:24:54 +0200 Subject: [PATCH 01/11] Add .idea folder (Rubymine) in .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 892d936..c72659a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ /tmp/ .*.swp *.gem -vendor/bundle \ No newline at end of file +vendor/bundle +.idea/ \ No newline at end of file From 2ef64be6d9e3cd04fcb5cf6fdd18c132f677f365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Thu, 30 May 2024 09:28:56 +0200 Subject: [PATCH 02/11] Update ruby version to 3.0.7 (+ bundle update) --- .circleci/config.yml | 4 +- .ruby-version | 2 +- Gemfile.lock | 289 +++++++++++++++++++++++-------------------- checker_jobs.gemspec | 2 +- 4 files changed, 159 insertions(+), 138 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ccde50d..b722850 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: test-ruby: docker: - - image: cimg/ruby:2.6.6 + - image: cimg/ruby:3.0.7 steps: - checkout - run: @@ -31,7 +31,7 @@ jobs: lint-ruby: docker: - - image: cimg/ruby:2.6.6 + - image: cimg/ruby:3.0.7 steps: - checkout - run: diff --git a/.ruby-version b/.ruby-version index 338a5b5..2451c27 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6.6 +3.0.7 diff --git a/Gemfile.lock b/Gemfile.lock index 9f22e1e..a00f33a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,79 +6,83 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (6.1.3.1) - actionpack (= 6.1.3.1) - actionview (= 6.1.3.1) - activejob (= 6.1.3.1) - activesupport (= 6.1.3.1) + actionmailer (6.1.7.8) + actionpack (= 6.1.7.8) + actionview (= 6.1.7.8) + activejob (= 6.1.7.8) + activesupport (= 6.1.7.8) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.1.3.1) - actionview (= 6.1.3.1) - activesupport (= 6.1.3.1) + actionpack (6.1.7.8) + actionview (= 6.1.7.8) + activesupport (= 6.1.7.8) rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (6.1.3.1) - activesupport (= 6.1.3.1) + actionview (6.1.7.8) + activesupport (= 6.1.7.8) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.3.1) - activesupport (= 6.1.3.1) + activejob (6.1.7.8) + activesupport (= 6.1.7.8) globalid (>= 0.3.6) - activesupport (6.1.3.1) + activesupport (6.1.7.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) - bugsnag (6.20.0) + base64 (0.2.0) + bugsnag (6.27.1) concurrent-ruby (~> 1.0) - builder (3.2.4) + builder (3.3.0) byebug (11.1.3) coderay (1.1.3) - concurrent-ruby (1.1.8) - connection_pool (2.2.5) + concurrent-ruby (1.3.3) + connection_pool (2.4.1) crass (1.0.6) - daemons (1.3.1) - diff-lcs (1.4.4) - docile (1.3.5) - erubi (1.10.0) + csv (3.3.0) + daemons (1.4.1) + date (3.3.4) + diff-lcs (1.5.1) + docile (1.4.0) + erubi (1.13.0) eventmachine (1.2.7) - faraday (1.4.1) - faraday-excon (~> 1.1) - faraday-net_http (~> 1.0) - faraday-net_http_persistent (~> 1.1) - multipart-post (>= 1.2, < 3) - ruby2_keywords (>= 0.0.4) - faraday-excon (1.1.0) - faraday-net_http (1.0.1) - faraday-net_http_persistent (1.1.0) - gitlab (4.17.0) - httparty (~> 0.18) - terminal-table (~> 1.5, >= 1.5.1) - globalid (0.4.2) - activesupport (>= 4.2.0) - haml (5.2.1) - temple (>= 0.8.0) + faraday (2.9.2) + faraday-net_http (>= 2.0, < 3.2) + faraday-net_http (3.1.0) + net-http + gitlab (4.20.1) + httparty (~> 0.20) + terminal-table (>= 1.5.1) + globalid (1.2.1) + activesupport (>= 6.1) + haml (6.3.0) + temple (>= 0.8.2) + thor tilt - httparty (0.18.1) - mime-types (~> 3.0) + httparty (0.22.0) + csv + mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.8.10) + i18n (1.14.5) concurrent-ruby (~> 1.0) - json (2.5.1) - loofah (2.9.1) + json (2.7.2) + language_server-protocol (3.17.0.3) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) + nokogiri (>= 1.12.0) + mail (2.8.1) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp mailcatcher (0.2.4) eventmachine haml @@ -89,127 +93,144 @@ GEM skinny (>= 0.1.2) sqlite3-ruby thin - method_source (1.0.0) - mime-types (3.3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2021.0225) - mini_mime (1.1.0) - mini_portile2 (2.5.1) - minitest (5.14.4) + method_source (1.1.0) + mini_mime (1.1.5) + mini_portile2 (2.8.7) + minitest (5.24.0) multi_xml (0.6.0) - multipart-post (2.1.1) - mustermann (1.1.1) + mustermann (3.0.0) ruby2_keywords (~> 0.0.1) - nokogiri (1.11.3) - mini_portile2 (~> 2.5.0) + net-http (0.4.1) + uri + net-imap (0.4.14) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nokogiri (1.16.6) + mini_portile2 (~> 2.8.2) racc (~> 1.4) - octokit (4.21.0) - faraday (>= 0.9) - sawyer (~> 0.8.0, >= 0.5.3) - parallel (1.20.1) - parser (3.0.1.0) + octokit (7.2.0) + faraday (>= 1, < 3) + sawyer (~> 0.9) + parallel (1.25.1) + parser (3.3.3.0) ast (~> 2.4.1) - pronto (0.11.0) - gitlab (~> 4.4, >= 4.4.0) - httparty (>= 0.13.7) - octokit (~> 4.7, >= 4.7.0) + racc + pronto (0.11.2) + gitlab (>= 4.4.0, < 5.0) + httparty (>= 0.13.7, < 1.0) + octokit (>= 4.7.0, < 8.0) rainbow (>= 2.2, < 4.0) - rexml (~> 3.2) - rugged (>= 0.23.0, < 1.1.0) + rexml (>= 3.2.5, < 4.0) + rugged (>= 0.23.0, < 2.0) thor (>= 0.20.3, < 2.0) - pronto-rubocop (0.11.1) + pronto-rubocop (0.11.5) pronto (~> 0.11.0) rubocop (>= 0.63.1, < 2.0) - pry (0.13.1) + pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - pry-byebug (3.9.0) + pry-byebug (3.10.1) byebug (~> 11.0) - pry (~> 0.13.0) - public_suffix (4.0.6) - racc (1.5.2) - rack (2.2.3) - rack-protection (2.1.0) - rack - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + pry (>= 0.13, < 0.15) + public_suffix (6.0.0) + racc (1.8.0) + rack (2.2.9) + rack-protection (3.2.0) + base64 (>= 0.1.0) + rack (~> 2.2, >= 2.2.4) + rack-test (2.1.0) + rack (>= 1.3) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) - loofah (~> 2.3) - rainbow (3.0.0) - rake (13.0.3) - redis (4.2.5) - regexp_parser (2.1.1) - rexml (3.2.5) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + rainbow (3.1.1) + rake (13.2.1) + redis (4.8.1) + regexp_parser (2.9.2) + rexml (3.3.1) + strscan + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - rubocop (1.13.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.64.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.2.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.4.1) - parser (>= 2.7.1.5) - rubocop-rspec (2.3.0) - rubocop (~> 1.0) - rubocop-ast (>= 1.1.0) - ruby-progressbar (1.11.0) - ruby2_keywords (0.0.4) - rugged (1.0.1) - sawyer (0.8.2) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-rspec (3.0.1) + rubocop (~> 1.61) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + rugged (1.7.2) + sawyer (0.9.2) addressable (>= 2.3.5) - faraday (> 0.8, < 2.0) - sidekiq (6.2.1) - connection_pool (>= 2.2.2) + faraday (>= 0.17.3, < 3) + sidekiq (6.5.12) + connection_pool (>= 2.2.5, < 3) rack (~> 2.0) - redis (>= 4.2.0) - simplecov (0.21.2) + redis (>= 4.5.0, < 5) + simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) - simplecov_json_formatter (0.1.2) - sinatra (2.1.0) - mustermann (~> 1.0) - rack (~> 2.2) - rack-protection (= 2.1.0) + simplecov_json_formatter (0.1.4) + sinatra (3.2.0) + mustermann (~> 3.0) + rack (~> 2.2, >= 2.2.4) + rack-protection (= 3.2.0) tilt (~> 2.0) skinny (0.2.2) eventmachine (~> 1.0) thin - sqlite3 (1.4.2) + sqlite3 (2.0.2) + mini_portile2 (~> 2.8.0) sqlite3-ruby (1.3.3) sqlite3 (>= 1.3.3) - temple (0.8.2) - terminal-table (1.8.0) - unicode-display_width (~> 1.1, >= 1.1.1) - thin (1.8.0) + strscan (3.1.0) + temple (0.10.3) + terminal-table (3.0.2) + unicode-display_width (>= 1.1.1, < 3) + thin (1.8.2) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) - thor (1.1.0) - tilt (2.0.10) - tzinfo (2.0.4) + thor (1.3.1) + tilt (2.3.0) + timeout (0.4.1) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (1.7.0) - zeitwerk (2.4.2) + unicode-display_width (2.5.0) + uri (0.13.0) + zeitwerk (2.6.16) PLATFORMS ruby @@ -231,4 +252,4 @@ DEPENDENCIES simplecov BUNDLED WITH - 2.1.4 + 2.5.14 diff --git a/checker_jobs.gemspec b/checker_jobs.gemspec index 53166ea..6bcb36a 100644 --- a/checker_jobs.gemspec +++ b/checker_jobs.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.required_ruby_version = ">= 2.6.0" + spec.required_ruby_version = ">= 3.0.0" spec.add_development_dependency "actionmailer", ">= 5.0", "< 7.0" spec.add_development_dependency "bugsnag" From d4cc52fa2edb8e45dada875370309087ee25a64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Thu, 30 May 2024 11:18:00 +0200 Subject: [PATCH 03/11] Fix lint --- checker_jobs.gemspec | 2 +- spec/spec_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/checker_jobs.gemspec b/checker_jobs.gemspec index 6bcb36a..c5d7f7e 100644 --- a/checker_jobs.gemspec +++ b/checker_jobs.gemspec @@ -2,7 +2,7 @@ lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "checker_jobs/version" -Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength +Gem::Specification.new do |spec| spec.name = "checker_jobs" spec.version = CheckerJobs::VERSION spec.authors = ["Drivy", "Nicolas Zermati"] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ea24b7d..a9d7938 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,7 +18,7 @@ config.release_stage = "production" end -RSpec.configure do |config| # rubocop:disable Metrics/BlockLength +RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true end From c082e83a44032e9ce8d7b26be866cacafe349fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Wed, 26 Jun 2024 17:53:28 +0200 Subject: [PATCH 04/11] Fix rubocop --- .rubocop.yml | 2 +- spec/checker_jobs/notifiers/bugsnag_spec.rb | 2 +- spec/checker_jobs/notifiers/email_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a73ac28..aac1a9c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -53,7 +53,7 @@ Style/BlockComments: Exclude: - "spec/spec_helper.rb" -Metrics/BlockLength: +Layout/LineLength: Exclude: - "spec/**/*_spec.rb" diff --git a/spec/checker_jobs/notifiers/bugsnag_spec.rb b/spec/checker_jobs/notifiers/bugsnag_spec.rb index 2524b27..f1b5f15 100644 --- a/spec/checker_jobs/notifiers/bugsnag_spec.rb +++ b/spec/checker_jobs/notifiers/bugsnag_spec.rb @@ -32,7 +32,7 @@ end # rubocop:disable RSpec/ExampleLength - it "is an Error and have an explicit message", aggregate_failures: true do + it "is an Error and have an explicit message", :aggregate_failures do expect(notify_report.context).to eq "checker_jobs" expect(notify_report.severity).to eq "warning" expect(notify_report.grouping_hash).to eq "(#{checker_klass}) Ensure name was triggered!" diff --git a/spec/checker_jobs/notifiers/email_spec.rb b/spec/checker_jobs/notifiers/email_spec.rb index ac5c48c..1a851d8 100644 --- a/spec/checker_jobs/notifiers/email_spec.rb +++ b/spec/checker_jobs/notifiers/email_spec.rb @@ -19,7 +19,7 @@ describe "with default" do subject(:perform) { instance.perform } - it "sends an email" do + it "sends an email" do # rubocop:disable RSpec/NoExpectationExample sends_an_email end end From 6267753687bf8afd4df00b693e8de6734b95cf89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Thu, 30 May 2024 14:14:12 +0200 Subject: [PATCH 05/11] Introduce new rubocop rule --- .rubocop.yml | 3 +++ lib/checker_jobs/dsl.rb | 2 +- lib/checker_jobs/notifiers/email.rb | 2 +- lib/checker_jobs/notifiers/logger.rb | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index aac1a9c..ac7b696 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -36,6 +36,9 @@ Style/TrailingCommaInHashLiteral: Style/TrailingCommaInArguments: EnforcedStyleForMultiline: comma +Naming/MemoizedInstanceVariableName: + EnforcedStyleForLeadingUnderscores: required + # # Disabled cops # diff --git a/lib/checker_jobs/dsl.rb b/lib/checker_jobs/dsl.rb index 30b34bc..d962e39 100644 --- a/lib/checker_jobs/dsl.rb +++ b/lib/checker_jobs/dsl.rb @@ -62,7 +62,7 @@ def option(key, default = nil) end def checks - @checks ||= {} + @_checks ||= {} end def add_check(klass, name, options, block) diff --git a/lib/checker_jobs/notifiers/email.rb b/lib/checker_jobs/notifiers/email.rb index ae46e92..c58a2d1 100644 --- a/lib/checker_jobs/notifiers/email.rb +++ b/lib/checker_jobs/notifiers/email.rb @@ -28,7 +28,7 @@ def valid? end def mailer_options - @mailer_options ||= @defaults. + @_mailer_options ||= @defaults. merge(email_options). merge(@check.klass.notifier_options) end diff --git a/lib/checker_jobs/notifiers/logger.rb b/lib/checker_jobs/notifiers/logger.rb index 0ad1457..f0cbad7 100644 --- a/lib/checker_jobs/notifiers/logger.rb +++ b/lib/checker_jobs/notifiers/logger.rb @@ -40,10 +40,10 @@ def valid? end def level - @level ||= @check.klass.notifier_options[:level] || notifier_options[:level] + @_level ||= @check.klass.notifier_options[:level] || notifier_options[:level] end def logdev - @logdev ||= @check.klass.notifier_options[:logdev] || notifier_options[:logdev] + @_logdev ||= @check.klass.notifier_options[:logdev] || notifier_options[:logdev] end end From 86341dac4dcf1ad1a98f09a518cabadc7ee11c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Thu, 30 May 2024 14:14:48 +0200 Subject: [PATCH 06/11] Refactor: Rename method --- spec/checker_jobs/checks/ensure_fewer_spec.rb | 4 ++-- spec/checker_jobs/checks/ensure_more_spec.rb | 4 ++-- spec/checker_jobs/checks/ensure_no_spec.rb | 6 +++--- spec/support/email_helpers.rb | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/checker_jobs/checks/ensure_fewer_spec.rb b/spec/checker_jobs/checks/ensure_fewer_spec.rb index 42c8602..a918167 100644 --- a/spec/checker_jobs/checks/ensure_fewer_spec.rb +++ b/spec/checker_jobs/checks/ensure_fewer_spec.rb @@ -17,13 +17,13 @@ context "when block's result is < options[:than]" do let(:block) { Proc.new { 2 } } - it { doesn_t_send_any_email } + it { does_not_send_any_email } end context "when block's result is == options[:than]" do let(:block) { Proc.new { 3 } } - it { doesn_t_send_any_email } + it { does_not_send_any_email } end context "when block's result is > options[:than]" do diff --git a/spec/checker_jobs/checks/ensure_more_spec.rb b/spec/checker_jobs/checks/ensure_more_spec.rb index 0e4256c..9b74600 100644 --- a/spec/checker_jobs/checks/ensure_more_spec.rb +++ b/spec/checker_jobs/checks/ensure_more_spec.rb @@ -23,13 +23,13 @@ context "when block's result is == options[:than]" do let(:block) { Proc.new { 3 } } - it { doesn_t_send_any_email } + it { does_not_send_any_email } end context "when block's result is > options[:than]" do let(:block) { Proc.new { 4 } } - it { doesn_t_send_any_email } + it { does_not_send_any_email } end end end diff --git a/spec/checker_jobs/checks/ensure_no_spec.rb b/spec/checker_jobs/checks/ensure_no_spec.rb index aa0620a..ce8be86 100644 --- a/spec/checker_jobs/checks/ensure_no_spec.rb +++ b/spec/checker_jobs/checks/ensure_no_spec.rb @@ -17,13 +17,13 @@ context "when block's result is 0" do let(:block) { Proc.new { 0 } } - it { doesn_t_send_any_email } + it { does_not_send_any_email } end context "when block's result is an empty enumerable" do let(:block) { Proc.new { [] } } - it { doesn_t_send_any_email } + it { does_not_send_any_email } end context "when block's result is > 0" do @@ -47,7 +47,7 @@ context "when block's result is false" do let(:block) { Proc.new { false } } - it { doesn_t_send_any_email } + it { does_not_send_any_email } end end end diff --git a/spec/support/email_helpers.rb b/spec/support/email_helpers.rb index 5c84130..2588b4d 100644 --- a/spec/support/email_helpers.rb +++ b/spec/support/email_helpers.rb @@ -5,7 +5,7 @@ def sends_an_email from(0).to(1) end - def doesn_t_send_any_email + def does_not_send_any_email expect { subject }. not_to change { ActionMailer::Base.deliveries.count }. from(0) From c7ffc209eb93aa90f4c838e8a0d6e89f75e23ad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Fri, 31 May 2024 11:45:06 +0200 Subject: [PATCH 07/11] Add rubocop rule --- .rubocop.yml | 3 +++ spec/checker_jobs/notifiers/bugsnag_spec.rb | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ac7b696..99d08cf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -39,6 +39,9 @@ Style/TrailingCommaInArguments: Naming/MemoizedInstanceVariableName: EnforcedStyleForLeadingUnderscores: required +RSpec/ExampleLength: + Max: 30 + # # Disabled cops # diff --git a/spec/checker_jobs/notifiers/bugsnag_spec.rb b/spec/checker_jobs/notifiers/bugsnag_spec.rb index f1b5f15..9a6918d 100644 --- a/spec/checker_jobs/notifiers/bugsnag_spec.rb +++ b/spec/checker_jobs/notifiers/bugsnag_spec.rb @@ -31,7 +31,6 @@ report end - # rubocop:disable RSpec/ExampleLength it "is an Error and have an explicit message", :aggregate_failures do expect(notify_report.context).to eq "checker_jobs" expect(notify_report.severity).to eq "warning" @@ -50,6 +49,5 @@ }, }) end - # rubocop:enable RSpec/ExampleLength end end From c3c62014743588a997e6b6d1bf97f2b47e7b8741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Fri, 31 May 2024 12:02:52 +0200 Subject: [PATCH 08/11] Fix calling unknown variable --- lib/checker_jobs/errors.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checker_jobs/errors.rb b/lib/checker_jobs/errors.rb index 072ae07..15e0234 100644 --- a/lib/checker_jobs/errors.rb +++ b/lib/checker_jobs/errors.rb @@ -34,7 +34,7 @@ def initialize(checker_name) end def message - "CheckerJobs: the name '#{checker_name}' is already used for another checker." + "CheckerJobs: the name '#{@checker_name}' is already used for another checker." end end end From 9a9bb38684c48f31a354e9e60c39edc12815c198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Fri, 31 May 2024 12:03:45 +0200 Subject: [PATCH 09/11] Use Bugsnag notifier instead of Emails in the specs --- spec/checker_jobs/checks/base_spec.rb | 8 ++++---- spec/checker_jobs/checks/ensure_fewer_spec.rb | 14 ++++++------- spec/checker_jobs/checks/ensure_more_spec.rb | 14 ++++++------- spec/checker_jobs/checks/ensure_no_spec.rb | 20 +++++++++---------- spec/checker_jobs/notifiers/bugsnag_spec.rb | 3 +++ spec/checker_jobs/notifiers/email_spec.rb | 2 -- spec/spec_helper.rb | 3 +++ 7 files changed, 31 insertions(+), 33 deletions(-) diff --git a/spec/checker_jobs/checks/base_spec.rb b/spec/checker_jobs/checks/base_spec.rb index 644524c..cb7e8b1 100644 --- a/spec/checker_jobs/checks/base_spec.rb +++ b/spec/checker_jobs/checks/base_spec.rb @@ -4,7 +4,7 @@ let(:checker_klass) do Class.new do include CheckerJobs::Base - notify :email, to: "oss@drivy.com" + notify :bugsnag end end @@ -12,11 +12,11 @@ subject(:perform) { instance.perform } let(:block) do - Proc.new { self.class.notifier_options[:to].length } + Proc.new { 13 } end - it "executes the block in the context of a new klass's instance" do - expect(perform).to eq 13 # "oss@drivy.com".size + it "executes the block in the context of a new klass' instance" do + expect(perform).to eq 13 end context "when there is an around_check" do diff --git a/spec/checker_jobs/checks/ensure_fewer_spec.rb b/spec/checker_jobs/checks/ensure_fewer_spec.rb index a918167..70045b2 100644 --- a/spec/checker_jobs/checks/ensure_fewer_spec.rb +++ b/spec/checker_jobs/checks/ensure_fewer_spec.rb @@ -1,13 +1,11 @@ -require "support/email_helpers" - -RSpec.describe CheckerJobs::Checks::EnsureFewer, :email, :configuration do - include EmailHelpers +RSpec.describe CheckerJobs::Checks::EnsureFewer, :bugsnag, :configuration do + include BugsnagHelpers let(:instance) { described_class.new(checker_klass, "ensure_name", { than: 3 }, block) } let(:checker_klass) do Class.new do include CheckerJobs::Base - notify :email, to: "oss@drivy.com" + notify :bugsnag end end @@ -17,19 +15,19 @@ context "when block's result is < options[:than]" do let(:block) { Proc.new { 2 } } - it { does_not_send_any_email } + include_examples "does_not_send_a_bugsnag_notification" end context "when block's result is == options[:than]" do let(:block) { Proc.new { 3 } } - it { does_not_send_any_email } + include_examples "does_not_send_a_bugsnag_notification" end context "when block's result is > options[:than]" do let(:block) { Proc.new { 4 } } - it { sends_an_email } + include_examples "sends_a_bugsnag_notification" end end end diff --git a/spec/checker_jobs/checks/ensure_more_spec.rb b/spec/checker_jobs/checks/ensure_more_spec.rb index 9b74600..84a7574 100644 --- a/spec/checker_jobs/checks/ensure_more_spec.rb +++ b/spec/checker_jobs/checks/ensure_more_spec.rb @@ -1,13 +1,11 @@ -require "support/email_helpers" - -RSpec.describe CheckerJobs::Checks::EnsureMore, :email, :configuration do - include EmailHelpers +RSpec.describe CheckerJobs::Checks::EnsureMore, :bugsnag, :configuration do + include BugsnagHelpers let(:instance) { described_class.new(checker_klass, "ensure_name", { than: 3 }, block) } let(:checker_klass) do Class.new do include CheckerJobs::Base - notify :email, to: "oss@drivy.com" + notify :bugsnag end end @@ -17,19 +15,19 @@ context "when block's result is < options[:than]" do let(:block) { Proc.new { 2 } } - it { sends_an_email } + include_examples "sends_a_bugsnag_notification" end context "when block's result is == options[:than]" do let(:block) { Proc.new { 3 } } - it { does_not_send_any_email } + include_examples "does_not_send_a_bugsnag_notification" end context "when block's result is > options[:than]" do let(:block) { Proc.new { 4 } } - it { does_not_send_any_email } + include_examples "does_not_send_a_bugsnag_notification" end end end diff --git a/spec/checker_jobs/checks/ensure_no_spec.rb b/spec/checker_jobs/checks/ensure_no_spec.rb index ce8be86..cf8b8b2 100644 --- a/spec/checker_jobs/checks/ensure_no_spec.rb +++ b/spec/checker_jobs/checks/ensure_no_spec.rb @@ -1,13 +1,11 @@ -require "support/email_helpers" - -RSpec.describe CheckerJobs::Checks::EnsureNo, :email, :configuration do - include EmailHelpers +RSpec.describe CheckerJobs::Checks::EnsureNo, :bugsnag, :configuration do + include BugsnagHelpers let(:instance) { described_class.new(checker_klass, "ensure_name", {}, block) } let(:checker_klass) do Class.new do include CheckerJobs::Base - notify :email, to: "oss@drivy.com" + notify :bugsnag end end @@ -17,37 +15,37 @@ context "when block's result is 0" do let(:block) { Proc.new { 0 } } - it { does_not_send_any_email } + include_examples "does_not_send_a_bugsnag_notification" end context "when block's result is an empty enumerable" do let(:block) { Proc.new { [] } } - it { does_not_send_any_email } + include_examples "does_not_send_a_bugsnag_notification" end context "when block's result is > 0" do let(:block) { Proc.new { 2 } } - it { sends_an_email } + include_examples "sends_a_bugsnag_notification" end context "when block's result is a non-empty enumerable" do let(:block) { Proc.new { [1, 2] } } - it { sends_an_email } + include_examples "sends_a_bugsnag_notification" end context "when block's result is true" do let(:block) { Proc.new { true } } - it { sends_an_email } + include_examples "sends_a_bugsnag_notification" end context "when block's result is false" do let(:block) { Proc.new { false } } - it { does_not_send_any_email } + include_examples "does_not_send_a_bugsnag_notification" end end end diff --git a/spec/checker_jobs/notifiers/bugsnag_spec.rb b/spec/checker_jobs/notifiers/bugsnag_spec.rb index 9a6918d..1612343 100644 --- a/spec/checker_jobs/notifiers/bugsnag_spec.rb +++ b/spec/checker_jobs/notifiers/bugsnag_spec.rb @@ -1,4 +1,5 @@ RSpec.describe CheckerJobs::Notifiers::Bugsnag, :configuration do + include BugsnagHelpers subject(:perform) { instance.perform } let(:instance) do @@ -14,6 +15,8 @@ end end + include_examples "sends_a_bugsnag_notification" + it "notifies bugsnag" do allow(::Bugsnag).to receive(:deliver_notification) perform diff --git a/spec/checker_jobs/notifiers/email_spec.rb b/spec/checker_jobs/notifiers/email_spec.rb index 1a851d8..9c068ee 100644 --- a/spec/checker_jobs/notifiers/email_spec.rb +++ b/spec/checker_jobs/notifiers/email_spec.rb @@ -1,5 +1,3 @@ -require "support/email_helpers" - RSpec.describe CheckerJobs::Notifiers::Email, :configuration, :email do include EmailHelpers diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a9d7938..9ddf9f9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,6 +8,9 @@ require "sidekiq" require "sidekiq/testing" +require "support/email_helpers" +require "support/bugsnag_helpers" + ActionMailer::Base.delivery_method = :test Sidekiq::Testing.inline! From 658f2accd82e33bffdb565d9fc84bfc9db03e40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Fri, 31 May 2024 15:21:56 +0200 Subject: [PATCH 10/11] Add rubocop rule --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 99d08cf..fe9d8ce 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -42,6 +42,9 @@ Naming/MemoizedInstanceVariableName: RSpec/ExampleLength: Max: 30 +RSpec/NestedGroups: + Max: 6 + # # Disabled cops # From 64814ec2f9363ddab34a65b38b4292fe43a50c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Chabanne?= Date: Fri, 31 May 2024 15:22:48 +0200 Subject: [PATCH 11/11] Allow a checker to be retried in case it fails --- .rubocop.yml | 3 +- lib/checker_jobs/checks/base.rb | 18 +++++-- lib/checker_jobs/checks/ensure_fewer.rb | 4 +- lib/checker_jobs/checks/ensure_more.rb | 4 +- lib/checker_jobs/checks/ensure_no.rb | 8 ++-- lib/checker_jobs/notifiers/email.rb | 6 +-- spec/checker_jobs/checks/base_spec.rb | 2 +- spec/checker_jobs/checks/ensure_fewer_spec.rb | 26 +++++++++- spec/checker_jobs/checks/ensure_more_spec.rb | 26 +++++++++- spec/checker_jobs/checks/ensure_no_spec.rb | 47 ++++++++++++++++++- spec/checker_jobs/notifiers/bugsnag_spec.rb | 2 +- spec/support/bugsnag_helpers.rb | 17 +++++++ 12 files changed, 143 insertions(+), 20 deletions(-) create mode 100644 spec/support/bugsnag_helpers.rb diff --git a/.rubocop.yml b/.rubocop.yml index fe9d8ce..1bbac5e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,7 +10,8 @@ AllCops: # Layout/DotPosition: - EnforcedStyle: trailing + Enabled: false + StyleGuide: https://relaxed.ruby.style/#layoutdotposition Layout/FirstHashElementIndentation: EnforcedStyle: consistent diff --git a/lib/checker_jobs/checks/base.rb b/lib/checker_jobs/checks/base.rb index 91609d0..9aafb9e 100644 --- a/lib/checker_jobs/checks/base.rb +++ b/lib/checker_jobs/checks/base.rb @@ -1,10 +1,10 @@ CheckerJobs::Checks::Base = Struct.new(:klass, :name, :options, :block) do - def perform + def perform(iteration = 0) result = CheckerJobs.configuration.around_check.call do klass.new.instance_exec(&block) end - result.tap { |res| handle_result(res) } + result.tap { |res| handle_result(res, iteration) } end private @@ -14,7 +14,19 @@ def notify(count:, entries: nil) notifier_class.new(self, count, entries).notify end - def handle_result(_result) + def handle_result(_result, _retry_count) raise NotImplementedError end + + def handle_retry(count, iteration, entries = nil) + retry?(iteration) ? perform(iteration + 1) : notify(count: count, entries: entries) + end + + def retry?(iteration) + iteration < max_retry + end + + def max_retry + @_max_retry ||= options.fetch(:retry, 0).clamp(0, 3) + end end diff --git a/lib/checker_jobs/checks/ensure_fewer.rb b/lib/checker_jobs/checks/ensure_fewer.rb index 4b9250c..e0b4659 100644 --- a/lib/checker_jobs/checks/ensure_fewer.rb +++ b/lib/checker_jobs/checks/ensure_fewer.rb @@ -1,10 +1,10 @@ class CheckerJobs::Checks::EnsureFewer < CheckerJobs::Checks::Base private - def handle_result(result) + def handle_result(result, iteration) case result when Numeric - notify(count: result) if result > options.fetch(:than) + handle_retry(result, iteration) if result > options.fetch(:than) else raise ArgumentError, "Unsupported result: '#{result.class.name}' for 'ensure_less'" end diff --git a/lib/checker_jobs/checks/ensure_more.rb b/lib/checker_jobs/checks/ensure_more.rb index a27c225..853bf59 100644 --- a/lib/checker_jobs/checks/ensure_more.rb +++ b/lib/checker_jobs/checks/ensure_more.rb @@ -1,10 +1,10 @@ class CheckerJobs::Checks::EnsureMore < CheckerJobs::Checks::Base private - def handle_result(result) + def handle_result(result, iteration) case result when Numeric - notify(count: result) if result < options.fetch(:than) + handle_retry(result, iteration) if result < options.fetch(:than) else raise ArgumentError, "Unsupported result: '#{result.class.name}' for 'ensure_more'" end diff --git a/lib/checker_jobs/checks/ensure_no.rb b/lib/checker_jobs/checks/ensure_no.rb index 9cce70c..ebf2ae7 100644 --- a/lib/checker_jobs/checks/ensure_no.rb +++ b/lib/checker_jobs/checks/ensure_no.rb @@ -1,14 +1,14 @@ class CheckerJobs::Checks::EnsureNo < CheckerJobs::Checks::Base private - def handle_result(result) + def handle_result(result, iteration) case result when Numeric - notify(count: result) unless result.zero? + handle_retry(result, iteration) unless result.zero? when Enumerable - notify(count: result.size, entries: result) unless result.empty? + handle_retry(result.size, iteration, result) unless result.empty? when TrueClass, FalseClass - notify(count: 1) if result + handle_retry(1, iteration) if result else raise ArgumentError, "Unsupported result: '#{result.class.name}' for 'ensure_no'" end diff --git a/lib/checker_jobs/notifiers/email.rb b/lib/checker_jobs/notifiers/email.rb index c58a2d1..eeb1320 100644 --- a/lib/checker_jobs/notifiers/email.rb +++ b/lib/checker_jobs/notifiers/email.rb @@ -28,9 +28,9 @@ def valid? end def mailer_options - @_mailer_options ||= @defaults. - merge(email_options). - merge(@check.klass.notifier_options) + @_mailer_options ||= @defaults + .merge(email_options) + .merge(@check.klass.notifier_options) end def email_options diff --git a/spec/checker_jobs/checks/base_spec.rb b/spec/checker_jobs/checks/base_spec.rb index cb7e8b1..f4ac267 100644 --- a/spec/checker_jobs/checks/base_spec.rb +++ b/spec/checker_jobs/checks/base_spec.rb @@ -39,7 +39,7 @@ it "keeps handling the result outside the around_check delegation" do allow(instance).to receive(:handle_result).and_call_original perform - expect(instance).to have_received(:handle_result).with(0) + expect(instance).to have_received(:handle_result).with(0, 0) end end end diff --git a/spec/checker_jobs/checks/ensure_fewer_spec.rb b/spec/checker_jobs/checks/ensure_fewer_spec.rb index 70045b2..1d98e03 100644 --- a/spec/checker_jobs/checks/ensure_fewer_spec.rb +++ b/spec/checker_jobs/checks/ensure_fewer_spec.rb @@ -1,7 +1,7 @@ RSpec.describe CheckerJobs::Checks::EnsureFewer, :bugsnag, :configuration do include BugsnagHelpers - let(:instance) { described_class.new(checker_klass, "ensure_name", { than: 3 }, block) } + let(:instance) { described_class.new(checker_klass, "ensure_name", options, block) } let(:checker_klass) do Class.new do include CheckerJobs::Base @@ -9,6 +9,8 @@ end end + let(:options) { { than: 3 } } + describe "#perform" do subject(:perform) { instance.perform } @@ -29,5 +31,27 @@ include_examples "sends_a_bugsnag_notification" end + + context "when retry option is used" do + let(:options) { { than: 3, retry: 1 } } + + context "when block's result is lower than the threshold" do + let(:block) { Proc.new { 2 } } + + include_examples "does_not_send_a_bugsnag_notification" + end + + context "when block's result is greater than the threshold" do + let(:block) { Proc.new { 4 } } + + it "sends 2 sidekiq jobs" do + allow(instance).to receive(:perform).and_call_original + perform + expect(instance).to have_received(:perform).twice + end + + include_examples "sends_a_bugsnag_notification" + end + end end end diff --git a/spec/checker_jobs/checks/ensure_more_spec.rb b/spec/checker_jobs/checks/ensure_more_spec.rb index 84a7574..271ba76 100644 --- a/spec/checker_jobs/checks/ensure_more_spec.rb +++ b/spec/checker_jobs/checks/ensure_more_spec.rb @@ -1,7 +1,7 @@ RSpec.describe CheckerJobs::Checks::EnsureMore, :bugsnag, :configuration do include BugsnagHelpers - let(:instance) { described_class.new(checker_klass, "ensure_name", { than: 3 }, block) } + let(:instance) { described_class.new(checker_klass, "ensure_name", options, block) } let(:checker_klass) do Class.new do include CheckerJobs::Base @@ -9,6 +9,8 @@ end end + let(:options) { { than: 3 } } + describe "#perform" do subject(:perform) { instance.perform } @@ -29,5 +31,27 @@ include_examples "does_not_send_a_bugsnag_notification" end + + context "when retry option is used" do + let(:options) { { than: 3, retry: 1 } } + + context "when block's result is greater than the threshold" do + let(:block) { Proc.new { 4 } } + + include_examples "does_not_send_a_bugsnag_notification" + end + + context "when block's result is lower than the threshold" do + let(:block) { Proc.new { 2 } } + + it "sends 2 sidekiq jobs" do + allow(instance).to receive(:perform).and_call_original + perform + expect(instance).to have_received(:perform).twice + end + + include_examples "sends_a_bugsnag_notification" + end + end end end diff --git a/spec/checker_jobs/checks/ensure_no_spec.rb b/spec/checker_jobs/checks/ensure_no_spec.rb index cf8b8b2..3cf04a8 100644 --- a/spec/checker_jobs/checks/ensure_no_spec.rb +++ b/spec/checker_jobs/checks/ensure_no_spec.rb @@ -1,13 +1,16 @@ +require "support/checkers" + RSpec.describe CheckerJobs::Checks::EnsureNo, :bugsnag, :configuration do include BugsnagHelpers - let(:instance) { described_class.new(checker_klass, "ensure_name", {}, block) } + let(:instance) { described_class.new(checker_klass, "ensure_name", options, block) } let(:checker_klass) do Class.new do include CheckerJobs::Base notify :bugsnag end end + let(:options) { {} } describe "#perform" do subject(:perform) { instance.perform } @@ -47,5 +50,47 @@ include_examples "does_not_send_a_bugsnag_notification" end + + context "when retry option is used" do + context "when set to 1 time" do + let(:options) { { retry: 1 } } + + context "when block's result is 0" do + let(:block) { Proc.new { 0 } } + + include_examples "does_not_send_a_bugsnag_notification" + end + + context "when block's result is > 0" do + include_context "when SidekiqChecker is available" + let(:block) { Proc.new { 2 } } + + it "sends 2 sidekiq jobs" do + allow(instance).to receive(:perform).and_call_original + perform + expect(instance).to have_received(:perform).twice + end + + include_examples "sends_a_bugsnag_notification" + end + end + + context "when set to more than the maximum allowed" do + let(:options) { { retry: 8 } } + + context "when block's result is > 0" do + include_context "when SidekiqChecker is available" + let(:block) { Proc.new { 2 } } + + it "sends 1 more sidekiq jobs than the maximum number of retries" do + allow(instance).to receive(:perform).and_call_original + perform + expect(instance).to have_received(:perform).exactly(4).times + end + + include_examples "sends_a_bugsnag_notification" + end + end + end end end diff --git a/spec/checker_jobs/notifiers/bugsnag_spec.rb b/spec/checker_jobs/notifiers/bugsnag_spec.rb index 1612343..0ed9184 100644 --- a/spec/checker_jobs/notifiers/bugsnag_spec.rb +++ b/spec/checker_jobs/notifiers/bugsnag_spec.rb @@ -23,7 +23,7 @@ expect(::Bugsnag).to have_received(:deliver_notification).once end - describe "notify's resulting payload" do + describe "notifies resulting payload" do subject(:notify_report) do report = nil diff --git a/spec/support/bugsnag_helpers.rb b/spec/support/bugsnag_helpers.rb new file mode 100644 index 0000000..b709224 --- /dev/null +++ b/spec/support/bugsnag_helpers.rb @@ -0,0 +1,17 @@ +module BugsnagHelpers + shared_examples "sends_a_bugsnag_notification" do + it do + allow(::Bugsnag).to receive(:deliver_notification) + subject + expect(::Bugsnag).to have_received(:deliver_notification).once + end + end + + shared_examples "does_not_send_a_bugsnag_notification" do + it do + allow(::Bugsnag).to receive(:deliver_notification) + subject + expect(::Bugsnag).not_to have_received(:deliver_notification) + end + end +end