Sha256: 7ed816b279b7d7c2f9bfbe842345aeabb4de9b74e512552f46315e374b162985

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Minitest
      # This cop checks for usage of assertions in lifecycle hooks.
      #
      # @example
      #   # bad
      #   class FooTest < Minitest::Test
      #     def setup
      #       assert_equal(foo, bar)
      #     end
      #   end
      #
      #   # good
      #   class FooTest < Minitest::Test
      #     def test_something
      #       assert_equal(foo, bar)
      #     end
      #   end
      #
      class AssertionInLifecycleHook < Cop
        include MinitestExplorationHelpers

        MSG = 'Do not use `%<assertion>s` in `%<hook>s` hook.'

        def on_class(class_node)
          return unless test_class?(class_node)

          lifecycle_hooks(class_node).each do |hook_node|
            hook_node.each_descendant(:send) do |node|
              if assertion?(node)
                message = format(MSG, assertion: node.method_name, hook: hook_node.method_name)
                add_offense(node, message: message)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubocop-minitest-0.11.1 lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb
rubocop-minitest-0.11.0 lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb
rubocop-minitest-0.10.3 lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb
rubocop-minitest-0.10.2 lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb
rubocop-minitest-0.10.1 lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb
rubocop-minitest-0.10.0 lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb