Sha256: 8a4ac6241512d8cce9a39fa084e55c72d99df8f5bf129f32eea438fbd768a7df

Contents?: true

Size: 703 Bytes

Versions: 5

Compression:

Stored size: 703 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Discourse
      class NoMockingJobs < Base
        MSG =
          "Use the test helpers provided by Sidekiq instead of mocking `Jobs.expects(:enqueue)`."

        def_node_matcher :mocking_jobs_enqueue?, <<~MATCHER
        (send (const nil? :Jobs) :expects (:sym :enqueue))
        MATCHER

        def_node_matcher :mocking_jobs_enqueue_in?, <<~MATCHER
        (send (const nil? :Jobs) :expects (:sym :enqueue_in))
        MATCHER

        def on_send(node)
          if mocking_jobs_enqueue?(node) || mocking_jobs_enqueue_in?(node)
            add_offense(node, message: MSG)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-discourse-3.8.6 lib/rubocop/cop/discourse/no_mocking_jobs.rb
rubocop-discourse-3.8.5 lib/rubocop/cop/discourse/no_mocking_jobs.rb
rubocop-discourse-3.8.4 lib/rubocop/cop/discourse/no_mocking_jobs.rb
rubocop-discourse-3.8.3 lib/rubocop/cop/discourse/no_mocking_jobs.rb
rubocop-discourse-3.8.2 lib/rubocop/cop/discourse/no_mocking_jobs.rb