Class: RuboCop::Cop::Minitest::NoAssertions

Inherits:
Base
  • Object
show all
Includes:
RuboCop::Cop::MinitestExplorationHelpers
Defined in:
lib/rubocop/cop/minitest/no_assertions.rb

Overview

Checks if test cases contain any assertion calls.

Matchers such as must_equal and wont_match are also treated as assertion methods.

Examples:

# bad
class FooTest < Minitest::Test
  def test_the_truth
  end
end

# good
class FooTest < Minitest::Test
  def test_the_truth
    assert true
  end
end

# bad
class FooTest < ActiveSupport::TestCase
  describe 'foo' do
    it 'test equal' do
    end
  end
end

# good
class FooTest < ActiveSupport::TestCase
  describe 'foo' do
    it 'test equal' do
      musts.must_equal expected_musts
    end
  end
end

Constant Summary collapse

MSG =
'Test case has no assertions.'

Constants included from RuboCop::Cop::MinitestExplorationHelpers

RuboCop::Cop::MinitestExplorationHelpers::ASSERTION_PREFIXES, RuboCop::Cop::MinitestExplorationHelpers::BLOCK_MATCHERS, RuboCop::Cop::MinitestExplorationHelpers::LIFECYCLE_HOOK_METHODS, RuboCop::Cop::MinitestExplorationHelpers::LIFECYCLE_HOOK_METHODS_IN_ORDER, RuboCop::Cop::MinitestExplorationHelpers::MATCHER_METHODS, RuboCop::Cop::MinitestExplorationHelpers::VALUE_MATCHERS

Instance Method Summary collapse

Instance Method Details

#on_class(class_node) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rubocop/cop/minitest/no_assertions.rb', line 46

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

  test_cases(class_node).each do |node|
    assertions_count = assertions_count(node)

    next if assertions_count.positive?

    add_offense(node.block_type? ? node.source_range : node.loc.name)
  end
end