Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract #assertions_count #235

Merged
merged 1 commit into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/rubocop/cop/minitest/multiple_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ def on_class(class_node)

private

def assertions_count(node)
node.each_descendant(:send).count do |send_node|
assertion_method?(send_node)
end
end

def max_assertions
Integer(cop_config.fetch('Max', 3))
end
Expand Down
7 changes: 0 additions & 7 deletions lib/rubocop/cop/minitest/no_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ def on_class(class_node)
add_offense(node.block_type? ? node.loc.expression : node.loc.name)
end
end

private

def assertions_count(node)
base = assertion_method?(node) ? 1 : 0
base + node.each_child_node.sum { |c| assertions_count(c) }
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/rubocop/cop/mixin/minitest_exploration_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ def assertions(def_node)
send_nodes.select { |send_node| assertion_method?(send_node) }
end

def assertions_count(node)
node.each_descendant(:send).count do |send_node|
assertion_method?(send_node)
end
end

def assertion_method?(node)
return false if !node.send_type? && !node.block_type?

Expand Down