Sha256: 0bdde15a41bbceab16f322e7c87618308618a2b48c2e5e1c73c1aef2ad5b8e1c
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module RSpec # Checks for setup scattered across multiple hooks in an example group. # # Unify `before`, `after`, and `around` hooks when possible. # # @example # # bad # describe Foo do # before { setup1 } # before { setup2 } # end # # # good # describe Foo do # before do # setup1 # setup2 # end # end # class ScatteredSetup < Cop MSG = 'Do not define multiple hooks in the same example group.' def on_block(node) return unless example_group?(node) analyzable_hooks(node).each do |repeated_hook| add_offense(repeated_hook, location: :expression) end end def analyzable_hooks(node) RuboCop::RSpec::ExampleGroup.new(node) .hooks .select { |hook| hook.knowable_scope? && hook.valid_scope? } .group_by { |hook| [hook.name, hook.scope] } .values .reject(&:one?) .flatten .map(&:to_node) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubocop-rspec-1.33.0 | lib/rubocop/cop/rspec/scattered_setup.rb |