Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-11 12:09:58 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-11 12:09:58 +0300
commita350f877c4246fee981690388239d1e19e17202a (patch)
treefc75efe26a34c732ab85b1dc6cf09fcab558e3f8 /rubocop
parent7adadf7e5b83c46f7e83051146624719e9b6bf0d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/rspec/have_enqueued_sidekiq_job.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/rubocop/cop/rspec/have_enqueued_sidekiq_job.rb b/rubocop/cop/rspec/have_enqueued_sidekiq_job.rb
new file mode 100644
index 00000000000..4b0beb10723
--- /dev/null
+++ b/rubocop/cop/rspec/have_enqueued_sidekiq_job.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ module RSpec
+ # This cop checks for `expect(worker).to receive(:perform_async)` usage in specs
+ #
+ # @example
+ # # bad
+ # it "enqueues a worker" do
+ # expect(MyWorker).to receive(:perform_async)
+ # end
+ #
+ # # good
+ # it "enqueues a worker" do
+ # expect(MyWorker).to have_enqueued_sidekiq_job
+ # end
+ #
+ # # bad
+ # it "enqueues a worker" do
+ # expect(MyWorker).to receive(:perform_async).with(1, 2)
+ # end
+ #
+ # # good
+ # it "enqueues a worker" do
+ # expect(MyWorker).to have_enqueued_sidekiq_job(1, 2)
+ # end
+ #
+ class HaveEnqueuedSidekiqJob < RuboCop::Cop::Cop
+ MESSAGE = 'Do not use `receive(:perform_async)` to check a job has been enqueued, use `have_enqueued_sidekiq_job` instead.'
+
+ def_node_search :expect_to_receive_perform_async?, <<~PATTERN
+ (send
+ (send nil? :expect ...)
+ {:to :not_to :to_not}
+ {
+ (send nil? :receive (sym :perform_async))
+
+ (send
+ (send nil? :receive (sym :perform_async)) ...
+ )
+
+ (send
+ (send
+ (send nil? :receive (sym :perform_async)) ...
+ ) ...
+ )
+ }
+ )
+ PATTERN
+
+ def on_send(node)
+ return unless expect_to_receive_perform_async?(node)
+
+ add_offense(node, location: :expression, message: MESSAGE)
+ end
+ end
+ end
+ end
+end