Sha256: b8197c1a290098e69fc812c329dffa3b7937fc6af05cac221f351c4f2ead4f1b
Contents?: true
Size: 1.33 KB
Versions: 13
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Discourse # Use `type: :multisite` only on a top-level `describe`. # Mixing multisite and standard specs can lead to errors, # e.g. when using `fab!` helper. # # @example # # bad # describe "something" do # describe "x", type: :multisite do # end # # it "does X", type: :multisite do # end # end # # # good # describe "something", type: :multisite do # describe "x" do # end # # it "does X" do # end # end class OnlyTopLevelMultisiteSpecs < Base MSG = "Use `type: :multisite` only on a top-level `describe`" def on_block(node) return if top_level?(node) return if !multisite_describe?(node.children.first) add_offense(node, message: MSG) end private def_node_matcher :multisite_describe?, <<~MATCHER (send {nil? (const nil? :RSpec)} {:describe :context :it} _ (hash (pair (sym :type) (sym :multisite)) ...) ) MATCHER def top_level?(node) node.parent&.begin_type? ? node.parent.root? : node.root? end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems