Sha256: bd4387324333de03f0554cbaceee5d28eb160f2b087a56387121b8537570c9a5
Contents?: true
Size: 1.32 KB
Versions: 11
Compression:
Stored size: 1.32 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 < Cop 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
11 entries across 11 versions & 1 rubygems